How to Measure Negative Voltage with an ADC.

How to Measure Negative Voltage with an ADC.
Схемотехника

As you know, many modern microcontrollers have a built-in multi-channel ADC; as a rule, there is physically only one ADC, and the multiple channels are provided by multiplexing. The voltage range the ADC can work with is determined by the reference voltage levels (+VREF and -VREF), which must not go beyond the microcontroller's supply range. The range of voltages powering...

How to Choose a MOSFET.

How to Choose a MOSFET.
Схемотехника

In this article we'll look at which parameters to pay attention to when choosing a MOSFET operating in switching mode. A transistor operating in this mode can switch a relay, a light bulb, a motor and other loads that draw a large current. 1. First, you need to know the voltage of the circuit the transistor will work in; this voltage will be applied to the Drain and Source pins...

Using Resistors in Electronics.

Using Resistors in Electronics.
Схемотехника

A resistor can be characterized by three parameters: resistance, tolerance, power. To understand what resistance is, let's imagine a pipe with water flowing through it. Since nothing hinders the movement of water in the pipe, the pressure at the outlet of the pipe will equal the pressure at the inlet. Now let's mentally cut the pipe into two parts and place a mesh between them, like the one in the sieve...

Main Types of Capacitors.

Main Types of Capacitors.
Схемотехника

Today there are many types of capacitors, and each has its own advantages and disadvantages. Some can work at high voltages, others have large capacitance, others low leakage, others low inductance; these factors determine the field of application of each capacitor type. This article covers the main, but far from all, types...

Using Capacitors in Electronics.

Using Capacitors in Electronics.
Схемотехника

Electronics uses three main properties of a capacitor: the ability to store charge; the ability to pass alternating current and block direct current; and the fact that the rate at which a capacitor charges can be calculated. Depending on the circuit, one of these properties may be more pronounced than the others. Probably the best-known property of a capacitor is energy storage. And indeed, in...

How to Tune a Radio Bug with an Oscilloscope.

How to Tune a Radio Bug with an Oscilloscope.
Электроника

The internet describes many ways to find and tune a radio bug (a tiny FM transmitter). Yes, yes, first you have to find the bug, or rather not the bug itself but the frequency it operates on, and only then tune it. It's also important to decide right away what you'll receive this bug on; if this is your first homemade device of this kind, it's best if its frequency is within the 87.5 to 108MHz range, then...

Controlling a Stepper Motor with a Microcontroller.

Controlling a Stepper Motor with a Microcontroller.
Схемотехника

It all started when one of my devices needed to rotate a motor shaft a certain number of turns; high precision wasn't required, plus or minus a quarter turn, so I decided to do it with a DC motor. An Atmega16 microcontroller was chosen as the control element, but since the output voltage of the Atmega16 pins...

STM32 Interrupts.

STM32 Interrupts.
STM32

On STM32, interrupts are managed by the NVIC (Nested Vectored Interrupt Controller). Let's look at its capabilities: handling up to 81 interrupts, depending on the MCU model; a programmable priority level from 0 to 15 for each interrupt, with level 0 being the highest priority; dynamic priority changes; dividing interrupts into groups, and within groups into...

STM32 Code Execution Time.

STM32 Code Execution Time.
STM32

It all started when I needed to at least roughly estimate the execution time of a piece of code. It turned out that microcontrollers with a Cortex-M3 core have a special module for this called the Data Watchpoint and Trace Unit, DWT for short. To configure DWT to measure code execution time, we need to set 2 bits. The TRCENA bit in the DEMCR register, setting...

STM32 PWM.

STM32 PWM.
STM32

PWM on STM32 is generated using timers; the documentation says a lot about them, but PWM turned out to be quite easy to configure. We'll generate PWM using channel 4 of timer 1. First, we need to find which pin is responsible for channel 4 of timer 1; to do this, open the Technical DataSheet for your MCU (mine is the STM32F103VET6) and find which pin has...

STM32: Storing ADC Data with DMA.

STM32: Storing ADC Data with DMA.
STM32

DMA (Direct Memory Access) lets you transfer data without involving the core. That is, if you use DMA, then when an ADC conversion completes, we don't need to fetch the conversion result and store it in memory; DMA will do it for us. To do this, when configuring DMA it's enough to specify the address to take data from and where to store it, plus a few more simple settings...

How to Run a Crystal on Its Third Overtone.

How to Run a Crystal on Its Third Overtone.
Схемотехника

The other day I came across an interesting way to run a crystal on its third overtone. It works like this: in a crystal oscillator built as a Colpitts (capacitive three-point) circuit, a trap filter tuned to the crystal's fundamental frequency is connected in the emitter; it blocks the oscillator from starting on the fundamental, and the crystal, and with it the oscillator, start on the third overtone...

Flashing AVR via a Bootloader.

Flashing AVR via a Bootloader.

Since I didn't get a USB programmer right away, and flashing via the COM port was slow and inconvenient, I had to find a way out of the situation, and it was to use a bootloader. One of my previous articles described how to flash an STM32 using its bootloader, but on STM32 the bootloader is programmed into the chip at the factory during manufacturing, whereas here we'll have to flash it ourselves. Here's how it looks in...

How a Zener Diode Works.

How a Zener Diode Works.
Схемотехника

A Zener diode is named after Clarence Zener, the discoverer of tunnel breakdown, and is shown on schematics as follows. But unlike a rectifier diode, current can flow through it in both directions. To better understand how it works, you can think of it as two diodes connected in anti-parallel, but with different voltage drops. For any Zener diode, the drop...

Digital Programmable Oscillator: Connecting the LTC6903 to STM32.

Digital Programmable Oscillator: Connecting the LTC6903 to STM32.
STM32

In one of my designs I needed to vary a clock frequency over a wide range, and as the title suggests, I chose the LTC6903. The LTC6903 and LTC6904 are digital programmable oscillators with a frequency range from 1KHz to 68MHz; the only difference is that the LTC6903 is controlled via SPI and the LTC6904 via I2C. They are quite easy to connect and only require bypass capacitors on the supply...

A Microcontroller-Based Scale: Connecting the HX711 to an Atmega16.

A Microcontroller-Based Scale: Connecting the HX711 to an Atmega16.
Схемотехника

This scale has been sitting unused for a long time. One day it simply stopped turning on, and my attempt to repair it failed, so I decided to restore it and at the same time figure out how it works. For this I ordered an HX711 board from AliExpress. This chip contains a programmable gain amplifier and a sigma-delta ADC; it was specifically designed for...

Drawing a Custom Character on a 1602A LCD Display.

Drawing a Custom Character on a 1602A LCD Display.
Дисплеи

In previous articles we looked at how to initialize an LCD display and output characters to it using the character generator table (CGROM). Previous articles also mentioned a type of memory called CGRAM, in which you can store your own characters. I should say that its size is limited and it can hold up to 8 characters. One character that can come in handy and that isn't in the standard...