Arduino is the most popular microcontroller today, with which every engineer is familiar, and most of them have even worked closely.
The beauty of it is that there is no need to write software for your projects from scratch, because initially the MK is loaded with presets that you can use as needed.
In most cases, it is enough to simply download a ready-made library, which can be found freely available on our website.
But those who have not yet encountered this device may be perplexed by many of the nuances of its use. Let's lift the lid on the secrecy and look at microcontrollers for beginners.
History of appearance
Work on the invention of the microprocessor has been carried out since the early 1970s. The first company to develop it was Intel. Already in 1971, the first microcontroller 4004 was released, which consisted of 2300 semiconductor transistors and was no larger than the palm of a hand. This became possible after a processor crystal was specially designed for the chip.
Despite its small size, the performance of the microprocessor was not inferior to the Eniac computer, which has dimensions of 85 m3. The peculiarity of this device was that it could only process 4 bits of information.
In the next six months, several more companies announced the creation of similar products.
By the end of 1973, Intel released an 8-charge microprocessor. It was so well designed that it is still considered a classic today.
A few months later, Motorola released its 8-bit microprocessor 6800. It became a strong competitor to the Intel chip, because it had a more significant interrupt system and one power supply voltage. In 8080 there were three of them.
The internal architecture of the 6800 was also different. It did not have general-purpose registers in which both address information and numerical indicators could be stored. Instead, the processor now has another full-fledged battery for data processing and 16-bit registers for storing addresses. Memory work was faster and simpler on the 6800, but the 8080 spent less time exchanging internal information between registers.
Both of these products had both positive aspects and shortcomings. They became the founders of two large families of microprocessors - Intel and Motorola, which still compete with each other.
In 1978, Intel released a 16-bit microprocessor that IBM used to develop personal computers. Motorola did not lag behind its competitor and also released a 16-bit microprocessor, which was used by Atari and Apple.
There are now more than 200 types of microcontrollers. The number of companies producing them has exceeded two dozen. The following are widely used by developers:
- 8-bit Pic microcontrollers from Microchip Technology and AVR from Atmel;
- 16-bit MSP 430 from TI;
- 32-bit ARM from the company of the same name.
Microcontrollers from Renesas Electronics, Freescale, and Samsung are popular in Russia.
Microcontrollers
This section is devoted to such a modern topic as microcontrollers . Currently, almost no modern device can do without microcontrollers. If you have any questions on the topic of microcontrollers , their programming, etc., then you can visit the forums: MK for beginners, AVR forum, PIC forum, Arduino and Raspberry Pi, STM32/ARM forum, programmers , peripherals, FPGAs, where competent specialists and forum participants will try to answer your questions.
Microcontrollers for Beginners:
- AVR microcontrollers for beginners. Part 1 - introduction to the AVR family
- AVR microcontrollers for beginners. Part 2 - programmers and firmware. Working with PonyProg
- AVR microcontrollers for beginners. Part 3 - working with CodeVision AVR
- Book on programming AVR microcontrollers
- Video course (8 lessons, plus tasks) on AVR with the author’s support topic on the forum
- Microcontroller training video for beginners
- AVR in C - easy?
- AVR in C - easy? Part 2
- AVR in C - easy? Part 3
- AVR in C - easy? Part 4
- Fuses of AVR microcontrollers - how and with what they are used
- Learning to create devices on microcontrollers: “traffic light”
- Learning to create devices on microcontrollers: “battery charge indicator”
- An ideal C program for MK, let's try to write
- The ideal C program for MK - continued
- Writing C programs in Code Vision AVR for controllers without RAM
- Timer/Counter for AVR for beginners
- PWM on Attiny13 microcontroller
- PWM controller on MK Attiny2313 (fan control)
- PWM controller on ATmega8515 microcontroller
- Brightness control (PWM) for LED driver or bicycle headlight
- PWM or PWM (Pulse Width Modulation) on AVR for beginners. Part 1
- PWM or PWM on AVR for beginners. Part 2 - software PWM
- Software PWM on STM8L
- Works MCP3421 ADC 18 bit with ATmega32 microcontroller
- Development board on AT89S52 or studying MK from scratch
- Counter with memory on Attiny2313
- Control of 595 shift registers using AVR via SPI
- Turning devices on and off with one button
- Turn devices on and off with one button
- Connecting LEDs to AVR
- mikroPascal for AVR. Lesson 1. Introduction
- mikroPascal for AVR. Lesson 2. ADC, UART and display
- mikroPascal for AVR. Lesson 3. UART again and also a little about interrupts
- mikroPascal for AVR. Lesson 4. Interrupts, interruptions and more interruptions. Timers
- mikroPascal for AVR. Lesson 5. Using OneWire. Built-in library
- mikroPascal for AVR. Lesson 6. Working with OneWire again. Expanded library
- mikroPascal for AVR. Lesson 7. Hardware PWM
- mikroPascal for AVR. Lesson 8. Software PWM
- Lesson on PWM (PWM) for mikroPascal for AVR
- Lesson on mikropascal for AVR.I2C
- AvrStudio 4. Library for AVR. Module for I2C or TWI
- Algorithm Builder. Lesson 1 - Introduction
- Algorithm Builder. Lesson 2 - About creating your first program
- Using USI interface to connect I2C peripherals to Attiny2313
- Working with I2C and SPI using the PCA2129T real-time clock as an example
- Several useful utilities for microcontrollers
- Library for managing multiple 1Wire devices in a point-to-point topology
- Expanding the number of ports of the PIC18 microcontroller via the SPI interface
- AvrStudio 4. CMSIS for AVR. Structure for GPIO
- PSoC. Chapter 0. Introduction. First example
- PSoC. Chapter 1. ADC
- PSoC. Chapter 2. UART
- PSoC. Chapter 3. DAC and UART RX line
- PSoC. Chapter 4 Timers and Global Interrupts
- Let's start working with FPGA or FPGA - it's easy. Part 1
- Let's start working with FPGA or FPGA - it's easy. Part 2
- Xilinx module template on VHDL and TestBench for testing
- FPGA internals
- FPGA. Just about the complex - Philosophy of writing configurations for FPGAs
- FPGA. Just about the complex stuff - Creating a project in Quartus II. Comparison of VHDL and Verilog
- QuickLogic QuickFeather Development Kits
- Let's start working with MSP430 microcontrollers from Texas Instruments
- Project of a virtual COM port for the STM32H107 development board
- SYS/BIOS: real-time operating system for MSP430 microcontrollers
Lessons on STM32, ARM:
- IAR and STM32 CORTEX M0. Part 0x00 (empty chatter and excuses)
- IAR and STM32 CORTEX M0. Part 0x01. Preparing the IAR platform
- IAR and STM32 CORTEX M0. Part 0x02, Let's start soldering!
- IAR and STM32 CORTEX M0. Part 0x03, Programming without a programmer
- IAR and STM32 CORTEX M0. Part 0x04 Automation of IAR firmware
- IAR and STM32 CORTEX M0. Part 0x05, GPIO - goes in and out...
- IAR and STM32 CORTEX M0. Part 0x06, Timers, PWM, interrupts
- ARM made easy (part 1)
- ARM made easy (part 2)
- ARM made easy (part 3)
- STM8. Lesson 1. ST Visual Develop environment settings
- STM8. Lesson 2. Controller clocking
- STM8. Lesson 3. Description of GPIO and SPL library
- STM8. Lesson 4. Setting up a timer 4. Timer interrupts
- STM8. Lesson 5. Quick setup of STVD environment for STM8S and STM8L
- STM8. Lesson 6. Project structure for STM8L and STM8S
- STM8. Lesson 7. Selecting and configuring a memory model
- STM8. Lesson 8. Assembly language inserts in Cosmic. Shifts in C
- STM8. Cosmic compiler error "FlexLM No such feature exists"
- STM32 start with CMSIS
- STM32 easy and fast start with CooCox CoIDE
- ARM. STM32 quick start
- STM32. Lesson 1. Selecting a development board
- STM32. Lesson 2. I/O Ports
- STM32. Lesson 3. UART
- STM32. Lesson 4. Basic timers
- STM32. Lesson 5. Connecting the WH1602 LCD display
- STM32F4. Lesson 1 - LED Control
- STM32F4. Lesson 2 - Pressing a Button
- STM32F4. Lesson 3 - Digital Outputs
- STM32F4. Lesson 4 - Digital Inputs
- STM32F4. Lesson 5 - working with ADC
- STM32F4. Lesson 6 - working with the ST7783 display
- STM32F4. Lesson 7 - Graphics library for the ST7783 display
- STM32F4. Lesson 8 - ST7783 Display Font Library
- STM32F4. Lesson 9 - Touchscreen ADS7843
- STM32F4. Lesson 10 - Software Timer and Counter
- STM32F4. Lesson 11 - Random Number Generator
- STM32F4. Lesson 12 - UART
- STM32F4. Lesson 13 - Working with an SD card
- STM32F4. Lesson 14 - ADC using DMA
- STM32F4. Lesson 15 - Low Level SPI
- STM32F4. Lesson 16 - Working with the MAX5250 DAC via SPI
- STM32F4. Lesson 17 - Controlling the LIS302DL via SPI
- STM32F4. Lesson 18 - Low Level I2C
- STM32F4. Lesson 19 — Working with EEprom M24C02 via I2C
- STM32F4. Lesson 20 - Displaying an image from an SD card
- STM32F4. Lesson 21 - ADC in Group Mode
- STM32F4. Lesson 22 - System Check
- STM32F4. Lesson 23 - Working with DAC
- STM32F4. Lesson 24 - Working with DAC via DMA
- STM32F4. Lesson 25 - Working with PWM
- STM32F4. Lesson 26 - Transferring ADC data to PC
- STM32F4. Lesson 27 - Connecting the OV9655 Camera
- STM32F4. Lesson 28 - Working with external interrupts
- STM32F4. Lesson 29 - Working with a PS2 keyboard
- STM32F4. Lesson 30 - Working with a PS2 mouse
- STM32F4. Lesson 31 — Using USB-OTG as a virtual COM port
- STM32F4. Lesson 32 — Using USB-OTG in MSC_HOST mode
- STM32F4. Lesson 33 - Working with the SSD1289 display
- STM32F4. Lesson 34 — Connecting a 16x2 character LCD display (HD44780)
- USB FLASH. Introduction and Part 1 - Working with the AT45DB161D
- USB FLASH. Part 2 - USB Peripherals in STM32F0
- USB FLASH. Part 3 - Final. SCSI protocol
- FAT32 to STM32
- Text command control (USART on STM32)
- Handling a custom button press using external interrupts
- Option to use packed time format in STM32
- Connecting a matrix keyboard to STM32F4Discovery
- Matrix keyboard library for STM32F4 Discovery
- Connecting HD44780 display to STM32 in CubeIDE (HAL)
- HD44780 library 4 lines x 20 characters for STM32
- Lighting up on TLC5940
- IAR EWARM. STM32F030F4P6. The microcontroller is not listed...
- STM32F030. Non-blocking I2C implementation
- Universal board based on STM32F405
- Nucleo-F411RE USB-ADC
- Working with LabVIEW using the STM32 as an example
AVR Lessons (BASCOM-AVR):
- Lesson 1. What is an AVR microcontroller?
- Lesson 2. AVR microcontroller programmer
- Lesson 3. Development board for AVR microcontroller Attiy13
- Lesson 4. Output ports in the Attiy13 microcontroller
- Lesson 5. Programming AVR microcontrollers
- Lesson 6. First design on the AVR microcontroller
- Lesson 7. Working with the LCD indicator on the HD44780 controller and its analogues
- Lesson 8. Entering information into MK. Connecting the button to the BASCOM-AVR MK
- Lesson 9. Working with ADC using the example of ATtiny13 in BASCOM-AVR
- Lesson 10. Working with the UART interface
- Lesson 11. Working with the DS1307 real-time clock chip
- Lesson 12. Working with a computer PS/2 keyboard in BASCOM-AVR
- Lesson 13. Hardware PWM on a microcontroller
- Lesson 14. Software UART in BASCOM-AVR
- Lesson 15. Working with the DS18B20 temperature sensor in BASCOM-AVR
- Lesson 16. Working with an encoder in BASCOM-AVR
- Lesson 17. Using the bootloader in BASCOM-AVR
- Lesson 18. Working with the display of Nokia 3310
- Lesson 19. Working with ultrasonic distance sensor HC-SR04 in BASCOM-AVR
- Lesson 20. Connecting a seven-segment indicator using three wires (74HC595)
- Lesson 21. BASCOM-AVR and Arduino
Circuits and devices on microcontrollers:
- Mini digital soldering station
- DIY digital soldering station DSS-1
- Digital soldering station 4 in 1 (DSS-2.1)
- Station for mounting and dismantling BGA and other SMD radio components
- Charger-analyzer of NiMh/NiCd batteries
- Intelligent NiMh/NiCd battery charger
- AA battery tester
- 12V battery charge status indicator
- Two microcontroller power regulators
- Autolight - control of external car lighting devices
- Onboard tachometer on PIC16C84
- Cycling computer based on PIC16F628A and 4-digit LED indicator
- DIY cycling computer
- Timelapse of growing microgreens on Onion Omega 2+
- Wi-Fi modules ESP8266 and AVR microcontroller
- MK communication using RF modules
- Radio communication between two microcontrollers using RF modules
- Radio relay on module NRF24L01
- Communication interface between GSM module SIM300 and AVR ATmega32 microcontroller
- Sending and receiving SMS using GSM module SIM300
- How to connect a microcontroller and a computer via RS-232
- Radio control of three loads on “RF modules” using microcontrollers
- Radio control device for 12 commands
- Radio control device (radio key) for 3 commands
- Remote control device for 12 high-power commands
- Electronic scales based on HX711
- Ultrasonic water level control using 8051 microcontroller
- Ultrasonic range finder
- Mini radar, speed meter
- Bluetooth communication between STM32 and Android
- DIY GPS receiver on the EB-500 and AVR module
- Portable GPS Data Logger
- Accelerometer ADXL345
- Accelerometer and gyroscope MPU6050
- Alcohol vapor concentration tester for AVR
- Simple electronic compass
- The simplest Laundromat
- Intelligent Laundromat
- One bill acceptor and four attractions
- Simple DIY vending machine
- Practical implementation of a multi-channel phase controller on Attiny2313
- Pairing the 830 Series Digital Multimeter with a Computer
- Electronic combination lock on ATmega8
- Combination lock on PIC16F628A
- Key location indication (Part 1)
- Key location indication (Part 2)
- Code lock
- Intercom and hub
- RFID transponder reader TIRIS from Texas Instruments
- Electronic key reader iButton (DS1990) on MK ATtiny2313
- Electronic lock with iButton keys
- Security device with iButton keys and shock sensor
- Motion sensor on a PIC microcontroller using a PIR sensor
- Security device with telephone line notification
- Security device "Laser tripwire"
- Multi-command remote control device for pyrotechnic shows
- Autonomous reset module
- 4-channel load controller with UART control
- Controller of 8 loads on ATtiny13 with UART control
- USB I/O device on PIC18F4550 with 16 digital I/O and 8 analog inputs
- Data logger (analog data recorder)
- I/O device
- USB Device
- COM terminal
- Connecting and starting the motor from FDD (JCM5044)
- A simple tester for unipolar stepper motors on ATtiny2313 and ULN2004
- Microstep driver from an old printer on an ATmega32 microcontroller
- Control of two stepper motors via UART
- Engine speed sensor for controller
- Development board for devices based on Atmega8/48/88/168/328 MCUs
- Development board for ATtiny13/15 microcontrollers
- Universal basis for a controller with a graphical interface on ATmega8 with an OLED display
- Simple development board based on ATTINY2313
- Development board AT90USB162
- PIC16F877A - Development board
- Development kit based on PIC18F4520 microcontroller
- Universal development board for AVR
- Control of 15 pins with one PIC microcontroller input
- Display and keyboard driver TM1638
- Connecting PS/2 keyboard to PIC
- Connecting PS/2, AT keyboard to Attiny2313 microcontroller
- Interface board for connecting a PS2 keyboard with an LCD display on a PICAXE MK
- Keyboard Morse code sensor (PS/2 and PIC16F628A)
- ABCom - ATmega1284P computer
- Electronic accessories for the game STALKER
- Wait for it! - 80s game
- Electronic game “LED Thimbles”
- Economical dice on PIC12F629
- Electronic dice on ATtiny 2313
- Game console on STM32 and LCD Nokia 5110
- Game video console on AVR AVGA
- Button controller for the game Brein Ring v2.0
- USB joke
- USB joke 2
- Defuse the Bomb Game
- Steering wheel, joystick and gamepad with feedback (Force Feedback)
- Microcontroller virus and antivirus
- USB Password Keeper
- Why are some microcontrollers more reliable than others?
- ATmega8 TQFP to DIP adapter
- Auxiliary modules for development boards
- Overclocking ATmega328 (30 MHz)
Lighting, LED, LCD and LCD:
- Multimedia device
- Simple touch screen interface on PIC
- Touch module on AVR
- Simple touch sensor on AVR
- We work with LCD. Part 1
- We work with LCD. Part 2
- Winstar LCD WH1602B
- Review of IPS display 80x160 pixels with ST7735 controller
- Review of 128x160 pixel display with ST7735 controller
- Connecting and using LCD Nokia 3310 (5110) to an AVR microcontroller
- Connecting a display from an HP LaserJet P2055 printer to a microcontroller
- Connecting a display from a Mercury 130K cash register to a microcontroller
- Connecting the display from the Elwes-Micro cash register to the microcontroller
- Negative voltage generator for display 1602 and similar
- A short test of the OLED display Winstar WEH001602ALPP5N
- We connect LCD from Siemens C75 and ME75 to STM32
- Working with LPH8731-3C display from Siemens phones
- Features of working with the LPH9157-2 display
- Library for LPH9135 display
- Library for character display based on HD44780
- TFT display 3.2 open source
- Connecting Nokia1616 display to BASCOM-AVR
- Connecting a 128x64 KS0108 graphic LCD display to AT89C52
- HD44780 LCD to UART adapter
- Information display device on a 16×2 LCD display with HD44780 controller
- Electronic tag with LCD on a microcontroller
- Connecting the ST7565 LCD display to the MSP430 microcontroller
- Connecting a monochrome display on ST7565 to STM32
- SSD1331 RGB OLED display
- Fiber optic LED lamp on ESP
- Software implementation of the TM1640 control interface on ATmega
- An advisor in your pocket
- No LCD driver - just a calculator!
- Do-it-yourself electronic reader on the ATmega32 microcontroller
- Connecting a seven-segment indicator via UART to ATtiny13
- Dynamic indication on 7-segment LED indicators with programmable brightness control
- Once again about dynamic indication on LED indicators
- Connecting a 4-digit LED indicator to a total of 4 microcontroller ports
- Controlling RGB spotlights
- A simple flasher on an RGB LED using the ATtiny2313 (ATtiny13) microcontroller
- Controlling WS2813 Addressable LEDs with ATtiny
- RGB LED control
- RGB lighting for the kettle
- Creeping line on PIC16F877 on 20 matrices 8x8 or 160x8 pixels
- Ticker 8×80 LED on PIC16F628
- Ticker 8×80 with typing on the keyboard (PIC16F628)
- Creeping line on PIC controller
- Ticker on ATmega168
- LED strip controller on ATtiny13a
- LED garland on a microcontroller
- Simple LED garland on MK Attiny13
- POV - LED bicycle wheel lighting on MSP430
- Ticker with mechanical scanning
- DMX512 Controller for 40 channels
- PixelPOI
- LED matrix – MOJET
- Fade Out effect for LED using PWM (PIC)
- 3-channel PWM regulator on Attiny2313
- Multichannel phase regulator on ATtiny2313
- PWM controller on AVR
- Backlight brightness control on BH1750 sensor
- DIY traffic light
- A device for simulating traffic light operation on a PIC16F84A microcontroller
- Traffic light on PIC12F629 with the “wrong” program
- Traffic light on ATtiny13
- Simulation of a traffic light
- LED control on MK Attiny13
- Burning candle effect on ATTiny
- ADC on TINY13 and 16 LEDs
- New Year's night lamp made of RGB LEDs on the LaunchPad MSP-EXP430 board, controlled by an IR remote control
- Night light on a microcontroller
- IR remote control on MSP430 Launchpad
- Refinement of the Chinese headlamp
- LED lamp with PWM and timer
- Chandelier controller with 6 lamps
- Dual Channel Light Cord Adapter
- Flexilight Dual Color Light Cord Controller
- Pimp up your monitor. Build an interactive backlight
Audio:
- Whistling analyzer on Cortex-M4 or switching on the load by whistle
- Transmitting audio over a radio channel using the Speex codec
- Visualization of audio signal on Nokia 3310 LCD
- Audio spectrum analyzer on Atmega32
- Simple SD audio player
- MMC/SD WAV stereo player on ATmega32 with TV remote control
- SD WAV player with UART control
- Video playback on Nokia color LCD using Atmega32 8-bit AVR microcontroller
- Second life Creative Sound Blaster
- DIY MP3 player
- Playing notes on the PIC
- Playing audio on PIC
- Piano on PIC18F4550 microcontroller
- Echo effect on the Atmega32 microcontroller
- MMC/SD voice recorder on PIC16F877A
- Musical bell with secret button
- Musical call on MK Attiny13
- Musical call with the ability to change melodies without using a programmer
- Musical bell that can do it all (Z80)
- Door bell
Clocks and timers:
- Talker mp3. Tube clock
- Clock on gas-discharge indicators
- Clock on gas-discharge indicators V2.0
- Nixie Clock "King Size"
- Electronic alarm clock with gas-discharge indicators and MK
- IV-11 - watch with effects
- Clock on gas-discharge indicators with ATmega8
- Steampunk clock with gas discharge indicators
- Clock on VLI indicator IV-18
- Clock on the IV-18 indicator
- Radio, oh radio! And also IN-18
- IV-9. Clock, effects, pain and something else
- Making LED clock CxemWatch-v1 on ATmega328p
- Wristwatches on GRI (based on the Bars project)
- Multifunctional thermostat clock with remote control
- Musical clock with thermometers on PIC16F873A
- Chess clock - souvenir
- Multifunctional LED wristwatch
- Talking clock
- Clock/calendar on MK ATTiny2313 and RTC DS1305
- Clock ATtiny 2313, DS1302, TM1637 in assembler
- Clock on DS3231 and AVR microcontroller
- Clock on PCA21125 and AVR microcontroller
- Clock – daily timer with time correction
- 4 MHz quartz clock
- Clock on PIC16F877A
- Clock on PIC16F628A and FYQ3641A
- Compact watch with LED indicators
- Clock on a PIC microcontroller
- Watches with automatic brightness adjustment, touch buttons, etc.
- Clock on Attiny2313
- LED clock on Attiny2313 and DS1307
- Clock on ATtiny2313, DS1307 and LCD indicator 8*2
- Multi-function clock on AVR
- Alarm clock radio
- Alarm clock with thermometer
- Clock - calendar
- Talking clock - thermometer with calendar
- Digital clock on RTC DS12C887 and 8051
- RTC on STM8L-Discovery
- Library for working with the I2C bus and the PCF8583 real-time clock
- Clock on PCF8523 and AVR microcontroller
- Detonator Clock
- Binary clock on ATmega8
- Simple binary clock
- USB hit counter on AVR ATtiny25 microcontroller
- Automatic call system for AVR
- Time relay
- Timer 0…9999 seconds for exposing photoresist on ATtiny13
- Household timer on a PIC microcontroller
- Simple timer on PIC16F84A
- Timer on PIC
- Countdown timer on MK Attiny2313
- Countdown timer on MK ATmega8 + LCD 8x2 or 16x1
- 0-9999 seconds countdown timer on PIC12F683
- Multifunctional cyclic timer
- We install a multifunctional cyclic timer in the case
Temperature measurement, thermostats and thermostats on microcontrollers:
- Weather station on STM32
- Indoor weather station
- WiFi ESP8266 - a new step in the design of home devices with a wireless interface
- BME280 sensor data exchange with PC
- Wireless temperature and humidity meter with USB interface
- Humidity and temperature meter
- Temperature and relative humidity sensor with adaptive brightness control
- Simple temperature meter
- LCD thermometer
- USB thermometer
- Bluetooth thermometer
- Bluetooth thermometer on AVR (Arduino)
- Thermometer on PIC
- Thermometer on SE97B sensor and AVR microcontroller
- Digital thermometer on LM75AD sensor
- Connecting the DS18B20 ambient temperature sensor to the microcontroller
- Thermometer on DS18B20
- Thermostat with digital temperature sensor
- Dual digital thermometer on ATmega8 and DS18B20
- Simple thermometer for home with two sensors DS18B20
- Thermometer on MK Attiny13 and sensor DS18B20
- Unusual thermometer on ATtiny13 and DS18B20
- Decorative thermometer on a microcontroller
- Thermometer for AT89C2051 and DS18B20
- Universal two-channel thermometer for AVR
- Multipoint thermometer
- Thermometer on STM8L-Discovery
- XControl
- LAN Control - remote control system via local network, Internet and remote control
- Electronic thermostat and temperature alarm on PIC16C84
- Thermostat on PIC16F877A and LCD NOKIA 3310
- Simple thermostat
- Thermostat with preset 4 control temperatures for room thermometer
- Thermostat on PIC
- Programmable thermostat
- Barometer on AVR
- Clock, thermometer, thermostat, alarm clock, remote control system
- Clock + thermometer on PIC16F628A and LED indicators
Measurements, generators:
- 30V voltmeter on MSP430
- Multichannel remote voltmeter
- Small-sized frequency meter - digital scale up to 200 MHz with LCD display
- Frequency counter up to 16 MHz on a microcontroller
- Homemade oscilloscope on an AVR microcontroller
- Oscilloscope probe for ATmega8
- Digital LCD Oscilloscope
- USB oscilloscope
- Signal generator on MK ATtiny2313
- Functional DDS generator
- DDS generator
- Color determinant
- Digital dosimeter Gamma_1
Programmers, MK recovery, firmware:
- Clone AVR JTAG ICE
- Chinese JTAG ICE for AVR and driver installation
- PICkit 2 clone
- PURPIC, portable clone of PICkit2
- Simple USB PIC programmer
- The simplest programmer for PIC
- Simple PIC controller programmer using PicPgm
- Programmer for PIC controllers
- Saving Calibration Constant for 12F629 and 12F675 PIC Controllers
- How to make a simple programmer for PICs and AVRs
- Programmer for microcontrollers AT89C51/52/55
- Simple programmer
- USBasp - USB programmer for Atmel AVR microcontrollers
- Improvement of the USBasp programmer
- VUSBTiny programmer
- USB programmer for parallel Flash and EEPROM memory chips
- USB programmer for parallel Flash and EEPROM memory chips. Continuation
- Universal USB programmer for AVR MK, I2C EEPROM and SPI Flash 25ХХ
- Universal USB programmer
- ZIF SOIC adapter for programmer
- Universal adapter-programmer
- Universal adapter for Atmel STK500
- Compact programmer USBTiny-MkII SLIM (clone AVRISP-MKII)
- Programmer ATtiny84 USBtiny AVR ISP
- AVR programmer ULTI-SP
- USB programmer for AVR and AT89S microcontrollers, compatible with AVR910
- Gromov programmer for ATmega8A-PU
- AVR programmer on PIC
- Universal programmer
- Fixing AVR fuzz
- Atmel microcontroller revitalization device
- SinaProg + ATmega328P fixing fuse firmware
- Programmer for KR573RF5
- Optocoupler module for in-circuit debugging and SPI programmers
- In-circuit programming and debugging of Microchip microcontrollers
- Programming AVR microcontrollers in Ubuntu
- Programming AVR microcontrollers in Ubuntu-2 (GUI)
- STM32F4DISCOVERY: Working with ARM Cortex M4
What is a microcontroller
A microcontroller is essentially a microcircuit that consists of:
- Central processor. It includes a control unit, registers, ROM (read only memory).
- Peripherals, which include I/O ports, interrupt controllers, timers, various pulse generators, analog converters and similar elements.
A microcontroller is often called a microprocessor. But it is not so. The latter performs only certain mathematical and logical operations. And the microcontroller also includes a microprocessor with other elements, being only part of the microcontroller.
What is a register?
A register is a device located inside the core of a microcontroller (or processor) for storing n-bit binary data and performing transformations on it. The speed of their work is very high. The register is an ordered set of triggers, or switches (English trigger), capable of taking the value “0” (potential equal to 0 volts) or “1” (potential equal to the operating voltage for the internals of the MK, in our case it is 1.8 volts). The number of triggers n corresponds to the number of bits in a word. In turn, a machine word is a platform-dependent quantity, measured in bits (or bytes) and equal to the width of the processor registers and/or the width of the data bus. So, for example, our microcontroller is 32-bit, which means that a word consists of 32 bits (or 4 bytes). Special registers are part of RAM memory. Their functions are determined by the manufacturer and cannot be changed. All bits (flip-flops) of such a register are connected to certain circuits inside the microcontroller, i.e. changing the state of the trigger directly affects the operation of the microcontroller (its individual parts/circuits). For example, by writing “0” to the memory cell of the register responsible for the I/O port, you determine its function: it will work as an input (i.e., receive signals) or as an output (i.e., send signals).
Since we will be using the C programming language, it would be appropriate to recall some operations that will allow us to quickly and conveniently configure the necessary bits in the register. The first thing to remember is bit shift operations. Let's say we need to get the number 8. We already know that 810 is equal to 10002. Thus, to get 8, we just need to move “1” in memory three positions to the left. You can do it like this:
xxxxxxxxxx
mask = 1 << 3; // mask = 8
We will call the bit we want to change a mask. The mask will allow us to access the desired register bit directly.
However, we also need the bitwise logical operators AND, OR, and NOT. In order to write “1” to the desired bit of the register, we can act on the register bit by bit with a mask using the “OR” operation. Let's remember the truth table:
A | B | A | B |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
As you can see, if there was a “1” in the register bit, then we will not overwrite it with our mask and will only change the bit that interests us. You can do it like this:
xxxxxxxxxx
uint32_t mask = 1 << 3;
// reg = 0000 0000 0000 0000 0000 0000 0000 0100; reg = reg | mask; // reg = 0000 0000 0000 0000 0000 0000 0000 1100;
or like this:
xxxxxxxxxx
reg |= mask;
In order to write “0” to the required bit, we need the “AND” operation, the truth table of which is shown below:
A | B | A&¬B |
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
As you can see, we will erase all the bits that do not contain a “1”. Before we apply this operation, we need to invert the mask (i.e. apply the NOT operation):
xxxxxxxxxx
mask = mask;
// mask = 0000 0000 0000 0000 0000 0000 0000 1000 // ~mask = 1111 1111 1111 1111 1111 1111 1111 0111 reg = reg & (~mask);
Now apply the AND operation to the register using a modified mask:
xxxxxxxxxx
// reg = 0000 0000 0000 0000 0000 0000 0000 1100;
reg = reg & (~mask);
The short entry looks like this:
xxxxxxxxxx
reg &= ~mask;
Now we are ready to work with registers, but before that a few words about other important parts of the microcontroller.
The principle of operation of the microcontroller
Despite the complex design, the operating principle of the microcontroller is very simple. It is based on the analog operating principle. The system understands only two commands (“there is a signal”, “there is no signal”). From these signals, the code of a specific command is written into its memory. When the MK reads a command, it executes it.
Each MK has its own basic sets of commands. And only these he is able to accept and carry out. By combining individual commands with each other, you can write a unique program that will make any electronic device work exactly as required.
Depending on the set of programs contained in the MK, they are divided into:
CISC is a complex of a large number of basic commands;
RISC - only the necessary commands.
Most controllers contain a RISC kit. This is explained by the fact that such a microcontroller is easier to produce, it is cheaper and is more in demand among developers of electronic equipment.
How does a microcontroller work?
Well, in general, you can find out about this if you carefully read the manual for a specific microcontroller. But to put it simply, the microcontroller works something like this:
- When the power is turned on, all microcontroller modules are reset to their original state, and the program is loaded into RAM and begins to execute. Typically a program is executed in a loop. That is, all commands are executed sequentially one after one. After the last command is executed, the first one is executed again and so on ad infinitum - until the power is turned off or a reset is performed.
- The clock generator sets the clock frequency. This allows you to synchronize in time all processes occurring inside the microcontroller. For example, if the clock frequency is 1000 Hz, then this means that in one second the generator produces 1000 clock signals.
- Each microcontroller has a specific set of commands (instructions) that make up the program. For example, there is a command to read an input, there is a command to set an output, there are commands to perform arithmetic operations, etc.
- Each program command takes one or more clock cycles to complete. For example, if a command takes 2 clock cycles, then this means that at a clock frequency of 1000 Hz it is executed in 1 / (1000 / 2) = 0.002 s. If there are 100 such commands in our program, this will mean that the entire program will be executed in 0.002 * 100 = 0.2 seconds. This is, of course, oversimplified. But I think you get the point.
- The program, as a rule, reads some input values, processes them, and outputs signals in accordance with the program logic. For example, we have a New Year’s garland with two operating modes (let it be “running fire” and “running shadow”), which are set by a switch. Then the microcontroller, depending on which input the switch is closed to (which mode is selected), will, at certain intervals, alternately send a signal to the outputs (light the LED - running fire), or remove a signal from the output (extinguish the LED - running shadow). Time intervals are also programmed when creating a program.
That is, the simplified operating principle of the MK is as follows:
- Read inputs
- Process the received data
- Set outputs
Purpose and scope of microcontroller
Due to the fact that AVR microcontrollers are very easy to use, have high integration capacity and low power consumption, their application areas are diverse:
- automotive industry;
- robotics;
- aircraft and shipbuilding;
- industrial equipment;
- electronic children's toys;
- computers, phones;
- electronic musical instruments;
- Appliances;
- medical equipment;
- control of barriers and gates;
- traffic lights, semaphores;
- railway transport.
This is not a complete list of areas of application of MK.
The main purpose of the MK is to control all processes that occur on its platform. From turning lights on or off with a clap to raising the curtains when the light outside changes. In essence, MK monitors the state of certain variables and changes the system under dynamic conditions.
An example of using an Arduino microcontroller
When choosing your first project, you will most likely look at many different examples of using Arduino, but we can give you the most popular ones:
- Smart house systems . These are various smart switches, curtains, fans and various alarms. They allow you to make your interaction with housing more interactive.
- Automatic greenhouses.
- A variety of sensors , up to a special collar for a pet, showing its location and pulse.
In general, in terms of application, you are limited only by your own imagination!
Microcontroller power supply
To operate, a microcontroller, like any electronic device, requires energy. The voltage of the Atmel AVR MK is in the range of 1.8–5.5 Volts and depends on the model and series. Most appliances operate on 5 Volts. But there are also low-frequency models (Attiny 2313), the lower limit of which is from 1.8 V.
In addition, the frequency of the incoming current also affects the operation of the MC. Low voltage also requires low frequency limits. The higher the frequency, the faster certain models work.
So, in order to ensure the operation of AVR series controllers, 5 V must be supplied to all positive inputs, and the zero input must be grounded.
If the model has several power inputs and outputs, then they all need to be connected.
Power is supplied to the analog-to-digital converter through additional filters. This will help eliminate interference that may change the voltage readings. In this case, voltage is supplied to the positive input through a filter choke. And the zero pins are divided into digital and analog. Moreover, they can only connect at one point.
In addition, it is necessary to install capacitors, preferably ceramic ones, at the rate of 1 per 100 nanofarads.
Electronics for everyone
Microcontroller
this is, one might say, a small computer.
Which has its own central processor ( registers, control unit and arithmetic-logical unit
),
memory
, as well as various
peripherals
, such as
input/output ports
, timers, interrupt controllers, various pulse generators and even analog converters. You can't list everything. It is impossible to list all the applications of microcontrollers.
But, if we greatly simplify everything, then the main function of the microcontroller is “jumping its legs”. Those. it has several pins (from 6 to several dozen depending on the model) and on these pins it can set either 1 (high voltage level, for example +5 volts) or 0 (low voltage level, about 0.1 volts) depending on the software algorithm hardwired into its memory. The microcontroller can also determine the state of the signal on its legs (for this they must be configured as an input) - whether the voltage there is high or low (zero or one). Modern microcontrollers also almost universally have an Analog-to-Digital Converter on board - this is a thing similar to a voltmeter, it allows you not only to track 0 or 1 at the input, but to fully measure the voltage from 0 to the reference (usually the reference is equal to the supply voltage) and present it as a number from 0 up to 1024 (or 255, depending on the ADC bit size)
You can use it to make a smart home, the brains for a home robot, an intelligent aquarium control system, or just a beautiful LED display with running text. Among MK electronic components, this is one of the most versatile devices. For example, when developing the next device, I prefer not to bother with various kinds of circuit design perversions, but to connect all the inputs and outputs to a microcontroller, and do all the operating logic in software. It dramatically saves both time and money, which means money squared.
There are very, very many microcontrollers. Almost every self-respecting company producing radio components produces its own controller. However, there is order in this diversity. MKs are divided into families; I will not list them all, but I will describe only the most basic eight-bit families. MSC-51
The most extensive and developed is
MSC-51
, the oldest of all, coming from
the Intel 8051
and now produced by a lot of companies.
Sometimes called C51
.
This is an 8-bit architecture, differs from most other eight-bit devices in that it is a CISC
architecture.
Those. One command can sometimes perform a rather complex action, but commands are executed over a large number of clock cycles (usually 12 or 24 clock cycles, depending on the type of command), have different lengths and there are many of them, for all occasions. Among the controllers of the MSC-51
, there are both dinosaurs like
the AT89C51
, which have a minimum of peripherals, tiny memory and poor performance, and monsters like the products of
Silicon Laboratories
, which have on board a very meaty mince of different-sized peripherals, huge bins of RAM and permanent memory, powerful interfaces from simple
UART
to
USB
and
CAN
, as well as a brutally
fast core
, delivering up to 100 million operations per second. As for me personally, I adore the C51 architecture for its damn nice assembler, which is just a blast to write. Gigabytes of code have already been written for this architecture, all conceivable and inconceivable algorithms have been created.
Atmel AVR
My second favorite family is
the AVR
from
Atmel
.
In general , Atmel
also produces
MSC-51
controllers, but they still focus on
AVR
.
These controllers already have an 8-bit RISC
architecture and execute one command per clock cycle, but unlike the classic
RISC
cores they have a very extensive command system, although not as convenient as the C51, which is why I don’t like them.
But AVRs
are always equipped like for war and are simply stuffed with various peripherals, especially controllers of the
ATMega
.
They are also very easy to flash; this does not require specialized programmers or any other complex equipment. All you need is five wires and a computer with LPT
port. The ease of learning has allowed this controller to firmly fall into the hearts of many, many radio amateurs around the world.
Microchip PIC
.
Another 8-bit RISC
microcontroller, it has a very perverted command system, consisting of only a couple of dozen commands.
Each command is executed in four clock cycles. There are a number of advantages, primarily low power consumption and quick start. The average PIC
controller does not have as many peripherals as the AVR, but there are so many modifications of
PIC
controllers themselves that you can always choose a crystal with peripherals that suit exactly the task, no more, no less.
on PIC
'ax.
Which family should you choose? Oh, that's a tough question. At numerous forums and conferences there are still fierce battles on the topic of which family is better, AVR
squabble with
MSC-51
, simultaneously not forgetting to kick the
PIC
sheep in the kidneys, to which they respond in kind.
The situation here is like in Starcraft Who is cooler? People? Zerg? Protoss? It's all about the application, the scale of the tasks and a host of other parameters. Each family has its own advantages and disadvantages. But personally, I would choose AVR and for these reasons:
- 1. Availability in Russia. These controllers are deservedly popular and loved by the people, which means our merchants are willing to carry them. However, like PIC. With MSC-51 the situation is worse. It’s not a problem to get obsolete AT89C51, but who needs them? But modern silabs are already exclusive.
- 2. Low price. In general, the PIC is famous for its low price in the world, but the irony is that the freebies only start if you buy it by the carload. In fact, on a real counter, AVR will be 30-40 percent cheaper than PIC with slightly more functionality. With MSC-51 the situation is clear on the first point. Exclusiveness is not only rare, but also expensive.
- 3. A lot of peripherals at once. For a serial device this is rather a disadvantage. It’s much better to have only what is needed for the current task, and let the rest not get in the way and waste energy. PIC is famous for this with its wide range of models, where you can find a controller that will have what you need and will not have what you don’t need. But we are going to study and do it for ourselves! So it’s better for us to have everything at once and in reserve. And here AVR is head and shoulders above PIC, rolling out more and more stuffed controllers over and over again. I bought myself some AtMega16A and that’s it, you can study the whole family.
- 4. Single core. The fact is that all modern AVRs have the same core with a single command system. There are only some differences at the peripheral level (and those are minor). Those. code from some tiny ATTiny13 can be easily copied and pasted into ATMega64 and works almost without modifications. And vice versa with almost no restrictions. True, older AVR models (all sorts of AT90S1200) have limited top-down compatibility - they have a slightly smaller command system. But it's up with a bang. Microchip has a whole bunch of families. PIC12/16/18 with different command systems. The 12th family is usually a tiny little thing (like Tiny in AVR), and 18 is already more serious controllers (analogous to Mega AVR) And if the code from 12 can be dragged to 18, then back fig.
- 5. Extensive command system for AVR controllers. AVR has about 130 commands, while Microchip PIC has only 35. It would seem that PIC is a winner - fewer commands, easier to learn. Well, yes, that’s exactly what the microchip slogan sounds like, something like “Only 35 teams!” Only this is actually bullshit. After all, what is a processor command? It's a tool! Just imagine two calculators - a regular one, an accounting one and an engineering one. Accounting is much easier to learn than engineering. But try to calculate the sine on it? Or logarithm? No, you can, I don’t argue, but how many button presses and intermediate calculations will it take? Same thing! It’s much more convenient to work when you have a bunch of different actions at hand. Therefore, the larger the command system, the better.
- 6. Availability of free cross-platform C compilers. Of course, you can always find a crack. Where where, but in our country this has never been a problem. But why steal something if you have something free?
- 7. Well, the last argument is usually the most powerful. The presence of someone who would teach and advise. Helped with advice and directed me on the right path. I chose AVR for myself and on this site (at least for now) this particular family will be thoroughly examined, which means you don’t have much of a choice :))))))
Oh, but there are a whole bunch of these same AVRs. Which one should I take???
Interest Ask. In general, it is better to choose MK for the task. But to study it, it’s better to grab something stuffed.
First, let’s look at the markings so that you can immediately understand from the price list what kind of animal is in front of you. Here's an example for you
ATmega16A - 16PI
- AT
- made in Atmel - Mega
is a species of the family. There is also Tiny and Xmega (the new one is terrible stuff, a complete helicopter). In general, it was thought that Tiny was, like, low-budget with a small amount of minced meat and generally flawed, and Mega, on the contrary, was everything at once. In reality, the difference between the Tini and Mega families in terms of minced meat is now minimal, but Tini has less memory and cases it comes with a number of pins from 6 to 20. - 16
is the amount of flash memory in kilobytes. Actually, it's not all that simple. The memory number is a power of two. So Mega162 is not a controller with 162KB of flash, but a kind of Mega16 modification2 with 16KB of memory. Or Mega88 is not 88kb, but 8kb of flash, and the second 8 is kind of a hint that this is a further development of Mega8. Likewise Mega48 or Mega168. The same goes for Tini's family. For example, Tini2313 - 2 kilobytes of flash. What is 313? Who the hell knows what they meant Or Tiny12 - 1kb Flash. In general, the chip cleared. - A
is the energy consumption prefix (usually). This letter may not exist, but in the new series it is present almost everywhere. For example, the V and L series are low-voltage and can operate from 2.7 volts. True, you have to pay less frequency for low voltage. But overclocking is possible here too, nothing human is alien to us. A and P have new AVR series with PicoPower technology i.e. ultra-economical. There is no difference in the stuffing and internal structure with their non-index models, the only difference is in the operation of all sleep modes and power consumption. Those. Mega16A can easily be changed to Mega16 without A. And nothing else needs to be changed. - 16
— Limit clock frequency in megahertz. In reality, you can overclock it to 20 - P
—hull type. Important feature. The fact is that not every case can be soldered at home without hemorrhoids. For now, I recommend paying attention to the P-DIP housing. This is a bulky monster, but it is easy to solder, and, most importantly, it easily sticks into a special socket and is taken out of it again. It’s better to put SOIC (index S) or TQFP (index A) housings aside for now. Without good soldering experience and the ability to etch a high-quality printed circuit board, it is better not to bother with them. - I
- Type of tinning of leads. I - lead solder. U - lead-free. There is absolutely no difference for you. Take the one that is cheaper.
I recommend the following models:
- ATMega16A-16PU - inexpensive (about 100-150 rubles), many pins, a lot of peripherals. Available in different housings. It’s simple, my training course and all further examples are tailored to it.
- ATTiny2313-20SU is an ideal option for making all kinds of clocks/alarm clocks and other small home automation. Cheap (40 rubles), compact. The downside is that there is no ADC.
- ATmega48/88/168 any of these controllers. Compact (in the tqfp case it is the thinnest and smallest of the AVRs), cheap (100-150 rubles), stuffed to the brim.
- ATmega128 for the experienced. Big, powerful, loads of memory. Expensive (about 400r)
Connection
Through a microcontroller you can connect any device to the local network. As such, we can consider Ethernet. First of all, let's define the concepts.
Ethernet is a set of IEEE 802.3 standards that describe a variety of local network technologies: a common data link layer and a set of physical layer technologies, including optical fiber, twisted pair, and coaxial at various speeds for information transmission.
You can understand how a local network works through the OSI model. It includes several levels:
- Physical. It consists of a twisted pair cable, drivers and transformers through which data is transmitted.
- Duct. Ethernet frames are transmitted through it between local network nodes.
- Network. Packets are transmitted over it. They can be transmitted through several networks that differ in physical and data link layer technologies.
- Transport. Connects nodes together. Before sending data, the transport layer presents it as a network layer packet and transmits it to another node. It can send groups of packets simultaneously. If a connection-oriented protocol is used, then before sending the transport layer establishes a connection, monitors its quality, and only then transmits the data packet.
- Applied. Solves applied problems, those for which it was created. It exchanges data with the outside world using a standard or exclusive protocol.
Each of the subsequent levels is served by the previous or underlying one. This is how vertical inter-level connections are formed. The service features of each level are hidden from the rest.
When two networks interact, each level of one network contacts a similar level of the other. This is how horizontal connections are formed.
Microcontroller control
MK management can be carried out in two ways:
- Wired path. The actuators are controlled through an electrically conductive connection of control circuits and actuators. Switching on - by pressing a button on the control center or push-button remote control.
- Wireless way. This control method does not require a wired connection. A signal is transmitted from the transmitter or remote control (RC) and goes to the receiver.
Wireless connection signals can be:
- Optical. Similar signals control home appliances: TVs or air conditioners.
- Radio. There are several options: Wi-Fi, Bluetooth, etc.
The development of modern means of communication makes it possible to control controllers both through the remote control, being in close proximity to the device, and via the Internet from anywhere in the world via a local network.
Provides support for the Wi-Fi network of the ESP 8266 MK. It can be sold in the form of a microcircuit or soldered like an arduino. It has a 32-bit core and needs to be programmed via the UART serial port. There are more advanced boards with the ability to flash firmware via USB - these are NodeMCU. They can store information recorded, for example, from sensors. Such boards work with various interfaces, including SPI, I2S.
Supports a large number of functions:
- task Manager;
- timer;
- ADC channel;
- generation of a PWM signal at the output;
- audio player and much more.
The board can be used as an independent device and as a module for wireless communication with Arduino.
Block diagram of AVR microcontroller
Let's look at the figure below and figure out what blocks the microcontroller consists of and how they are connected to each other:
Rice. 2. Block diagram of the AVR microcontroller.
Let's take a brief look at what is shown on the blocks in the diagram:
- JTAG Interface (Joint Test Action Group Interface) - in-circuit debugging interface (4 wires);
- FLASH - reprogrammable memory for saving the program;
- Serial Peripheral Interface, SPI - serial peripheral interface (3 wires);
- EEPROM (Electrically Erasable Programmable Read-Only Memory) - reprogrammable ROM, non-volatile memory;
- CPU (CPU) - central control processor, the heart of the microcontroller, 8-bit microprocessor core;
- ALU (ALU) - arithmetic-logical unit, the basis of the CPU unit;
- RAM (Random Access Memory) - processor RAM;
- Program Counter - command counter;
- 32 General Purpose Registers - 32 general purpose registers;
- Instruction Register - register of commands, instructions;
- Instruction Decoder - command decoder;
- OCD (On-Chip Debugger) - internal debugging unit;
- Analog Comparator - analog comparator, analog signal comparison unit;
- A/D Converter (Analog/Digital converter) - analog-to-digital converter;
- LCD Interface (Liquid-Crystal Display Interface) - interface for connecting a liquid crystal display, indicator;
- USART (Universal Asynchronous Receiver-Transmitter), UART - universal asynchronous transceiver;
- TWI (Two-Wire serial Interface) - serial interface with two-wire connection;
- Watchdog Timer - watchdog or control timer;
- I/O Ports - water/output ports;
- Interrupts - block of control and reaction to interruptions;
- Timers/Counters - modules for timers and counters.
Microcontroller clocking
The clock frequency of the MK is the number of cycles per second performed by the controller. The higher it is, the more operations it can perform.
There are several ways to clock the MK. They depend on the use:
- Internal RC oscillator. It can only operate at 1, 2, 4, 8 MHz. If you need a different frequency, then it will not work. If it is necessary to use precise time intervals, this method cannot be used either, since its setting frequency fluctuates depending on the temperature.
- External quartz. This method has a more complex connection. The capacitance of the capacitor should be in the range of 15–22 pF. One output is connected to the resonator, and the other is grounded.
- External generator. This generator is also unstable at different temperatures, just like the internal one.
- RC chains. For this circuit, a capacitor with a capacity of 22 pF and a resistor of 10–100 kOhm is suitable.
For the simplest microcontrollers, an internal or external generator and RC circuits are suitable. To design more accurate MCUs, stable clock sources will be required.
Read more about the internal blocks of the microcontroller
Now let’s take a closer look at all the microcontroller blocks, figure out what is needed and why, and give simple examples in accessible language.
JTAG Interface is an important interface that allows internal debugging directly on the chip using the internal debugging unit ( OCD ), without the use of emulators. We can say that JTAG is an interface for “hardware” debugging of a microcontroller. Through a JTAG adapter, the microcircuit is directly connected to the software package for programming and debugging.
Using this interface, you can execute the program directly in the microcontroller in a step-by-step mode, watch how the contents of the registers change, how the indicators and LEDs that are connected to the microcontroller blink after each step, etc. To connect to the JTAG interface, 4 conductors are enough: TDI(Test Data In), TDO(Test Data Out), TCK(Test Clock), TMS (Test Mode Select).
The JTAG interface is not available in all AVR microcontrollers; as a rule, chips with 40 or more pins and a memory capacity of at least 16 KB have such a tasty addition. For serious tasks - serious materials and tools. )
FLASH - program memory, non-volatile ROM (read only memory) made using FLASH technology. The program that will be executed by the ALU unit of the microcontroller is stored here. The flash memory of the chip can be rewritten many times, thereby changing or adding to the program code for execution. This type of memory can retain data written to it for 40 years, and the number of possible erase/write cycles can reach 10,000.
Depending on the microcontroller model, the size of FLASH memory can reach 256 KB.
Serial Peripheral Interface, SPI is a serial peripheral interface (SPI) that is often used to exchange data between several microcontrollers at speeds of up to several MHz (several million clocks per second).
To exchange data via the SPI interface between two devices, 3 conductors are enough:
- MOSI (Master Output Slave Input) - Data from master to slave;
- MISO (Master Input Slave Output) - Data from slave to master;
- CLK (Clock) - clock signal.
Devices with an SPI interface are divided into two types: Master and Slave. If several devices are connected to the interface, then additional communication lines (conductors) are needed to exchange data between them so that the master can select a slave device and make a request to it.
The SPI interface is also used for in-circuit SPI programming; a programmer is connected to the microcontroller via this interface.
EEPROM is a non-volatile data memory in which data will be stored even when the microcontroller's power is turned off. In this memory you can store program execution settings, collected data for device operation statistics and other useful information. For example, having assembled a small weather station on a microcontroller, you can store data on air temperature, pressure, wind force in EEPROM for every day, and then at any time read this collected data and conduct statistical studies.
EEPROM has a separate address space that differs from the RAM and FLASH address space. The EEPROM memory of a microcontroller is a very valuable resource, since it is usually very small - from 0.5 to several kilobytes per chip. The number of rewrites for this type of memory is about 100,000, which is 10 times more than the FLASH memory resource.
ALU is an arithmetic-logical unit that, synchronously with the clock signal and based on the state of the program counter ( Program Counter ), selects the next instruction from program memory ( FLASH ) and executes it.
The clock signal for the microcontroller is generated by a clock generator, and can be supplied from several available sources to choose from:
- internal RC oscillator that can be calibrated to the desired frequency;
- ceramic or quartz resonator with capacitors (not available on all models);
- external clock signal.
The clock source is set using FUSE bits.
FUSES (from English: melting, plug, fuse) - special 4 bytes (4 * 8 = 32 bits) of data that configure some global parameters of the microcontroller during the firmware process. After flashing the firmware, these bits cannot be changed through the internal program that is written into the MK.
With this bit configuration we tell the microcontroller this:
- which master oscillator to use (external or internal);
- divide the generator frequency by a factor or not;
- use the reset pin (RESET) for reset or as an additional I/O pin;
- amount of memory for the bootloader;
- other settings depend on the microcontroller used.
The CPU is the brain of the microcontroller, which contains the ALU, registers and RAM.
A block of 32 general purpose registers ( 32 General Purpose Registers - register memory) is connected to the ALU, each of which represents 1 byte of memory (8 bits). The address space of general purpose registers is located at the beginning of random access memory (RAM) but is not part of it. With the data that is placed in registers, you can perform a variety of arithmetic, logical and bit operations. Performing such operations in RAM is not possible. To work with data from RAM, you need to write it to registers, perform the necessary operations in the registers, and then write the resulting data from the registers to memory or to other registers to perform some actions.
RAM - random access memory. You can write data from registers into it , read data into registers, all operations with data and calculations are performed in registers. For different families of AVR chips, the RAM size is limited:
- ATxmega - up to 32 KB;
- ATmega - 16 KB;
- ATtiny - 1 KB.
Analog Comparator - this block compares two signal levels with each other and stores the comparison result in a certain register, after which the received result can be analyzed and the necessary actions performed. For example: you can use this block as an ADC (Analog-to-Digital Converter) and measure the voltage of the battery, if the battery voltage has reached a low level, perform some actions, blink the red LED, etc. This module can also be used to measure the duration of analog signals, read the set operating modes of the device using a potentiometer, etc.
A/D Converter - this block converts an analog voltage value into a digital value, which can be worked with in the program and based on which certain actions can be performed. As a rule, the voltage range that is supplied to the ADC input in the AVR microcontroller is in the range of 0-5.5 Volts. For this unit, it is very important that the microcontroller is powered from a stable and high-quality power source. Many AVR microcontrollers have a special separate pin for supplying stable power to the ADC circuit.
LCD Interface - interface for connecting a liquid crystal indicator or display. They are used to display information, the status of the device and its components.
USART is a serial asynchronous interface for exchanging data with other devices. There is support for the RS-232 protocol, thanks to which the microcontroller can be connected to exchange data with a computer.
For such a connection between the MK and the COM port of the computer, you need a converter of logical voltage levels (+12V for COM to +5V for the microcontroller), or simply RS232-TTL. For similar purposes, MAX232 microcircuits and the like are used.
To connect the microcontroller to a computer via USB using the UART interface, you can use a specialized FT232RL microcircuit. Thus, on new computers and laptops, without having a physical COM port, you can bind a microcontroller using a USB port via the USART interface.
TWI is an interface for data exchange over a two-wire bus. Up to 128 different devices can be connected to such a data bus using two data lines: a clock signal (SCL) and a data signal (SDA). The TWI interface is analogous to the basic version of the I2C interface.
Unlike the SPI interface (one master and one/several slaves), the TWI interface is bidirectional; it allows you to organize a small internal network between several microcontrollers.
Watchdog Timer is a system for monitoring device freezing and then restarting it. It's like an automatic RESET button for an old computer with a buggy OS. ))
I/O Ports , GPIO is a set of input/output port blocks to the pins of which you can connect a variety of sensors, execution devices and circuits. The number of input/output pins that come from the ports in the microcontroller can be from 3 to 86.
Output drivers in the AVR microcontroller ports allow you to directly connect a load with a current consumption of 20 mA (maximum 40 mA) at a supply voltage of 5V. The total load current for one port should not exceed 80 mA (for example, hang an LED with a current of 15-20 mA on 4 pins for one of the ports).
Interrupts is a block that is responsible for reacting and launching certain functions when a signal arrives at certain inputs of the microcontroller or due to some internal event (for example, a ticking timer). For each interrupt, a separate subroutine is developed and recorded in memory.
Why is this block called an interrupt block? - because when an event specific to an interrupt occurs, the execution of the main program is interrupted and the subroutine that was written for the current interrupt is executed in priority. Upon completion of the subroutine, the execution of the main program returns from the moment where it was interrupted.
Timers/Counters - a set of timers and counters. A microcontroller typically contains from one to four timers and counters. They can be used to count the number of external events, generate signals of a certain duration, generate interrupt requests, etc. The width of timers and counters is 8 and 16 bits (look in the datasheet for the chip).
Microcontroller families
All MKs are united into families. The main characteristic by which this division occurs is the structure of the nucleus.
By the core of a microcontroller we mean a set of specific instructions, the cyclic operation of the processor, the organization of both program memory and databases, an interrupt system and a basic set of peripheral devices (PU).
Representatives of the same family differ from each other in the amount of memory of programs and databases, as well as the variety of control units.
All MKs are united into families by the same binary programming code.
Families are divided into:
- MSC-51, manufactured by Intel. Monocrystal MCU based on Harvard architecture. The main representative of this family is the 80C51, created using CMOS technology. And although these controllers were developed back in the 80s of the last century, they are still widely used. And today many companies, such as Siemens, Philips, etc., produce their controllers with a similar architecture.
- PIC (Microchip). MK Harvard architecture. It is based on a reduced instruction set architecture, built-in command and data memory, and low power consumption. This family includes more than 500 different MKs (8, 16, 32-bit) with different sets of peripherals, memory and other characteristics.
- AVR (Atmel). High-speed controllers are developed on our own architecture. The controller is based on a Harvard RISC processor with independent access to program and database memory (Flash ROM). Each of the 32 general purpose registers can act as an accumulator register and a set of 16-bit instructions. High performance of 1 MIPS per MHz clock speed is achieved due to the order of execution of instructions, which involves executing one instruction while preparing for the next one. To support its products, Atmel releases a free and high-quality Atmel development environment
- ARM (ARM Limited) are developed on their own architecture. The family includes 32 and 64-bit MCUs. ARM Limited is engaged only in the development of kernels and their tools, and sells production licenses to other companies. These processors consume little energy, so they are widely used in the production of mobile phones, game consoles, routers, etc. Companies that have purchased licenses include: STMicroelectronics, Samsung, Sony Ericsson, etc.
- STM (STMicroelectronics). 8-bit controllers (STM8) are classified as highly reliable, low power consumption products. The same family includes STM32F4 and STM controllers. They are based on 32-bit Cortex. Such controllers have a perfectly balanced architecture and have great development prospects.
These are not all microcontroller families. Here we have given only the main ones.
What are I/O ports?
Perhaps the main thing that makes the microcontroller so interesting is the input/output ports (general-purpose input/output). Why are they called that? It's very simple - they either receive or send a signal.
A port is not just one leg of a microcontroller: in our case, there are up to 16 legs on one port (numbering goes from 0 to 15). In turn, the ports are marked with letters - A, B, C, etc. For example, an LED can be connected to pin PD8 (port D, pin 8).
The leg can have several operating modes, and they are configured using the appropriate registers. How to find these registers, what they are called and what needs to be done with them to enable this or that mode, we will talk when we start programming, but now we will look at these very modes. Below is a diagram of the structure of one leg of our MK.
Image from Reference Manual, Figure 13. Basic structure of a standard I/O port bit
The first distinctive feature that can be noticed (and simply deduced from the name) is that the leg can work as an entrance and exit. The output has four operating modes:
- output open-drain - in this case, when writing “0” to the output register (English output register), N-MOS is activated, and when writing “1” the port goes into a high-impedance state (also this mode called Hi-Z, P-MOS is never activated);
- output push-pull - in Russian literature it is called “push-pull output”, and its principle is simple - writing “0” in the Output register activates N-MOS, writing “1” activates P- MOS;
- alternate function push-pull – the previously described push-pull output, only for the alternative function;
- alternate function open-drain.
In turn, the entrance has different operating modes:
- floating input - the pull-up is disabled (without the pull-up, the leg is in the Hi-Z state, which means that the input resistance is high, and any electrical interference (interference) can cause a “1” or “0” to appear at such an input ");
- input pull-up - pull-up to power supply (for STM32 it is usually 3.3 volts);
- input pulled to the bottom (eng. Input-pull-down) - pull-up to the ground (0 volts);
- analog input - if the pin is configured as an analog input, then the ADC module is used if it is connected to this pin.
To use GPIO, you also need to enable port clocking... and to do this you need to understand what clocking is!
Microcontroller Case Types
There are no external differences between the MK and other microcircuits. The crystals are placed in cases with a certain number of outputs. All MKs are produced only in 3 types of cases:
- The DIP package has two rows of pins. The distance between them is 2.54 mm. The leads are inserted inside the holes on the pads.
- SOIC package. It is suitable for installation that involves surface soldering of outputs to the contact pad. The distance between the outputs is 1.27 mm.
- QFP (TQFP) packages. Conclusions are located on all sides. The distance between them is 3 times less than in DIP. The body has a square shape. Intended for surface soldering only.
- QFN housing. The smallest one compared to the previous ones. Contacts exit 6 times more often than in DIP. They are widely used in industrial production, as they can significantly reduce the dimensions of manufactured devices.
Each of the housings has its own points of application. The first 3 can be used by radio amateurs.
Connection and control
The chips are connected through special connectors called pins. Those, in turn, are divided into:
- Responsible for nutrition . Standard combination of neutral, phase and ground. The latter is most often ignored.
- Data Entry Responsible.
- Responsible for data output . They can be divided into analog and digital, the main difference has already been mentioned above, and each of the outputs has its own advantages and disadvantages.
With the help of all these “legs” the system is controlled, and their required number directly depends on the task at hand.
What is the difference between a microcontroller and a microprocessor?
All computer functionality of a microprocessor (Micro Processor Unit - MPU) is contained on a single semiconductor chip. In terms of characteristics, it corresponds to the central processing unit of a computer (Central Processing Unit - CPU). Its scope is data storage, performing arithmetic and logical operations, and systems management.
The MP receives data from input peripheral devices, processes it and transmits it to output peripheral devices.
A microcontroller combines a microprocessor and the necessary supporting devices combined into one chip. If you need to create a device that communicates with external memory or a DAC/ADC unit, then you only need to connect a constant voltage power supply, a reset circuit, and a clock source.
Features of Arduino microcontrollers
But still, for the majority, when they mention MK, the name “Arduino” comes to mind, and this is not surprising. After all, this type of polycrystalline chips has characteristic features that make it stand out from its competitors:
- Low entry threshold . Since the software environment has already been written and tested for you, there is no need to invent any “bicycles”.
- Optimization for specific tasks . The creators have a whole line of different chips that differ greatly in characteristics, making it easier to choose the right one.
- A ready-made platform and many solutions to various problems or tasks in the public domain.
Microcontroller devices
Each type of controller has its own peripheral devices that operate autonomously, i.e., independently of the central core. Once the peripheral has completed its task, it may or may not report this to the CPU. It depends on how it is programmed.
The MK may have the following devices:
- Analog comparator. Its main task is to compare the incoming (measured) voltage with the ideal one. If the measured voltage is higher than ideal, then the comparator produces a logical 1 signal (the device turns off), if lower, then a logical 0 (the device continues to work).
- Analog-to-digital converter (ADC). Measures analog voltage over a period of time and outputs it in digital form. Not everyone has MK.
- Timer/counter. It is a combination of 2 forms of timer and counter. The timer forms time intervals, and the digital counter counts the number of pulses coming from the internal frequency generator or signals from external sources. One of the representatives of the timer/counter operation can be PWM (pulse width modulator). It is designed to control the average voltage value under load.
- Watchdog timer. Its task is to restart the program after a certain period of time.
- Interrupt module. It informs the MK about the occurrence of an event and interrupts the execution of the program. After the event ends, resumes the interrupted program.
Not all of these peripherals are necessarily included in every MCU. There are other, less common devices.
Electronics development. About microcontrollers on your fingers
When conceiving a technology startup, you do not have to be an ace in electronics; a specialist with knowledge of the basics of marketing has a much better chance of coming up with a good idea, but even when ordering someone to develop it, it is imperative to navigate the capabilities of the modern element base and present the price of the solution. Otherwise, you can demand the impossible, or get a device with an inflated cost on an outdated element base. Below the cut is an attempt to briefly and simply talk about the capabilities of modern microcontrollers to people who are far from them. For those who have an idea for a new electronic device, but have no idea what a microcontroller is. Those who want to take the first step from entertaining experiments with the Arduino platform to designing their own devices can also find simple but useful tips in it. I tried without dwelling on technical details; for this, even a book is not enough to outline the essence and give some simple but useful tips on circuit design in order to warn beginners against basic mistakes.
Summary of the article:
How microcontrollers conquered the world ARM architecture - today's leader in the microcontroller market Competition with younger brothers About laying asphalt, the benefits of sleep and its varieties Very briefly about manufacturing technology and how series of microcontrollers appear The periphery of the simplest ARM microcontroller for half a buck The cheapest way to get additional functions What will the transition to Cortex-M4 add, besides the price increasing by a couple of times? Cortex-M7 - when you want more...
Code security, upgradeability and versatility have helped microcontrollers conquer the world
Any smart device requires control.
In most cases today, this is done by microcontrollers - chips that combine a microprocessor core, memory and peripheral modules responsible for communication with other components of the device and the outside world. Microcontrollers are jacks of all trades. One microcontroller can replace dozens of specialized microcircuits that would be necessary to perform the required functions if the role of the computer were occupied by a microprocessor.
One of the indisputable advantages of the microcontroller is that the program under which it operates is hidden inside its case (in a section called “program memory”) and is very well protected from hacking, of course, if the microcode developer took care of this by activating the built-in mechanisms protection. This way you get as much intellectual property protection as you can get these days.
What cannot be hacked can be copied. Why try to read the code built into a microcontroller program using expensive contraptions when it is easier and cheaper to find a professional who can write it again? Perhaps the result will be even better, and the functionality will be richer than that of the prototype. Yes, it costs money, but the contents of the FLASH memory of today's microcontrollers are so well protected that attempts at brute force “hacking” will cost even more. In addition, the problem of intellectual property is solved, and you, along with the source codes of the program, get the opportunity to develop and improve your device.
The program memory in modern universal microcontrollers is rewritable, and the rewriting process can be repeated more than tens of thousands of times. It is tempting to use this fact to update the software in order to eliminate errors found in it or expand the functions of an already working device. This is quite simple to implement - by adding a special piece of code called a “bootloader” to the program, you get the opportunity to update the software of your device in various ways: at a service point (if the device has a special connector hidden inside the case from prying eyes), by connecting to computer via USB, network or even wireless interface. The main thing is to provide the device with the necessary peripherals for this. When providing the ability to update software, you should always think about security; if this process is not sufficiently protected, not only can attackers steal your code, they can modify it and use it for their own, perhaps insidious, purposes. For example, take control of the things in your “smart home” or spy using a WEB camera installed in your home.
ARM architecture is today's leader in the microcontroller market
Since the time of Tsar Pea, microcontrollers have been divided according to the bit depth of the data on which they perform operations. In the vast majority of cases, today, in new developments, it is worth choosing 32-bit microcontrollers with an ARM core. There are a huge number of their modifications and you can always choose a copy that is best suited to solve your problem. Depending on the set of functions and performance, the price of a chip can range from tens of cents to tens of dollars. Microcontrollers (MCU), depending on the architecture of the computing core, are usually divided into large families. Today, for the development of devices of low and medium complexity, the most popular are microcontrollers with cores from Cortex-M0 to Cortex-M7. The larger the number, the greater the computing (and not only) capabilities, price and maximum power consumption. Continuity of architecture played an important role in the popularity of ARM. A developer can modify the program code of his previous developments with minimal costs, moving from microcontrollers from one manufacturer to chips from another and migrating between cores with different performance.
Competition with younger brothers
However, ARMs did not always rule.
I remember well the times when 8-bit microcontrollers were the absolute market leaders and, from their positions, their 16-bit colleagues unsuccessfully tried to push them aside, but, ironically, only their 32-bit older brothers managed to do this. It so happened that by the time they appeared, chip manufacturing technologies had greatly reduced the cost of integrating large amounts of FLASH memory into them. Taking advantage of the opportunity, programmers began to move from assembler to a higher-level language - C, the structure of which fit perfectly with the 32-bit architecture. As a result, 32-bit microcontrollers performed calculations much faster than their 8 and 16-bit counterparts, but there was one problem - they had higher current consumption. Therefore, at first, they were used in cases where greater computing performance was required.
It is known that the average current consumption of the computing core of a microcontroller increases significantly with an increase in its clock frequency. At first, 8-bit microcontroller models were distinguished by noticeably lower consumption at a similar frequency and, in addition, were capable of operating at low clock frequencies, up to 32 kHz.
The power consumption of microcontrollers strongly depends on the clock frequency of the core and periphery; in order to regulate it, a PLL-based clock frequency generation unit, widely used in radio transmitting devices, began to be used for generation. This made it possible to change the clock frequency within a wide range without changing the master quartz resonator. Peripheral modules do not necessarily have the same clock speed as the computing core. To reduce their power consumption, the frequency began to be supplied to them through dividers with a software-controlled division ratio. We introduced the ability to disable unused modules. These measures greatly reduced power consumption, but it still remained significantly higher than that of 8-bit.
For a short time, parity emerged - 32-bit MCUs captured the niche of top applications, and 8-bit MCUs confidently held their positions in devices for which low power consumption was important. It persisted until 32-bit MCUs mastered the “pulse” operating mode to perfection.
8-bit workers, by that time, also learned to do this, but, due to low productivity, they had to stay awake much more and, as a result, they began to lose in energy consumption, especially in tasks requiring calculations, as illustrated by the picture below.
About laying asphalt, the benefits of sleep and its varieties
So, microcontrollers learned to count so well that they began to do their work very quickly and most of the time they were forced to “throw away”, consuming energy to perform idle cycles.
In self-powered devices, this greatly reduces battery life or operating time on a single battery charge. Watch the construction workers laying asphalt. They sharply intensify their work when a truck arrives with a new portion of asphalt, and after laying it they slow down. Likewise, microcontrollers can increase and decrease the core clock frequency. However, this is not as easy for them as it is for workers - at the same time, the operating frequency of the entire internal periphery will also change, therefore, parts of it that are sensitive to this will have to be reconfigured. Isn’t it easier, after completing all the work quickly, to get some sleep? Often, yes. Moreover, the types of sleep of microcontrollers differ even more dramatically than those of humans.
You can just take a nap. In this case, our chip is always ready and as soon as the timer alarm rings or is disturbed by an external interruption, it wakes up almost instantly. Just as a person can relieve tension during a nap, but not get a good night’s sleep when you are constantly being tugged at, so a microcontroller can reduce its power consumption in this mode “only” 10 times; this mode is called SLEEP.
The best way to get a good night's sleep is to undress, go to bed, close the curtains on the window and turn on the alarm clock. However, after such a dream, you won’t immediately get back to work. You will have to at least rinse yourself with cold water and get dressed. The microcontroller also has such a mode, when it limits the number of external stimuli and turns off the main clock generator. This is STOP mode. It is possible to reduce consumption by 1000 times, but it will take significant time to get out of it.
Now, imagine that before going to bed you drank a hefty dose of sleeping pills, turned off the alarm clock and phone, and closed all the windows and doors. This will be STAND BY mode. The microcontroller can only be brought out of this mode using special pins, and most of the memory of what it was doing before such a sleep will be lost forever, and you will have to start working again. But being in this mode, the MCU consumes even two times less.
The last, very exotic mode, resembles a coma, from which you cannot get out without special equipment. In this case, only a special generator works, which is part of a microcontroller on a separate clock quartz, which can operate from its own power source and has literally a few bytes of RAM, the purpose of which is to remind the microcontroller of the state from which it fell into this coma. If the remaining parts of the microcontroller are disconnected from the power supply, then the power consumption may already be one ten-thousandth of the active mode.
When choosing a power saving mode, you must remember the consequences of using
:
- the deeper the sleep, the longer the awakening
- the deeper the sleep, the fewer ways to get the microcontroller out of it
- the deeper the sleep, the less information remains about the previous state of the microcontroller
- To achieve the minimum declared values, in many modes it is necessary to take additional measures, for example, turning off peripherals
- To minimize the power consumption of the device as a whole, it is necessary to correctly design the circuitry of the entire device
- To minimize the power consumption of the device as a whole, care must be taken to ensure that other components and circuits also have micro-consumption in idle mode. It is stupid to make enormous efforts to lower the consumption of a microcontroller below one microampere and, at the same time, use a cheap stabilizer in the device with an internal current consumption of 100 microamperes, but this happens all the time
- To successfully use deep sleep modes, not only the program, but also the circuitry must be carefully thought out, otherwise, instead of saving, you can get very serious problems - a rarely occurring, but “dead” freeze of the device for an inexplicable reason, or too frequent awakening and, as result, consumption is orders of magnitude higher than expected
If your programmer and circuit designer have been blaming each other for not the first day for being crooked and, together, the manufacturer for publishing unrealistic numbers in datasheets for the microcontroller, and your device drains batteries an order of magnitude faster than you expected, this is a reason to at least turn to independent highly qualified experts.
Very briefly about manufacturing technology and how series of microcontrollers appear
The physically active part of the microcontroller, like the vast majority of other microcircuits, is usually formed on a monosilicon wafer (let's call it, in this context, a CHIP).
Chips occupy a very small area, but it is technologically advantageous to produce wafers of large diameter, therefore, usually a large number of chips, like honeycombs, are placed on one large wafer and formed during one technological process. Subsequently, the plates are cut into pieces, obtaining separate chips, which are placed in housings. Developing the topology and debugging the technological processes of a new chip is very expensive, and the space occupied by one chip on the wafer is, as a rule, not large. It is profitable for manufacturers to produce chips in large quantities, but users require microcontrollers in different packages - for some it is important to get a smaller and cheaper package, for others, on the contrary, they need more pins to control an LCD or external memory with a parallel interface. It is profitable for manufacturers to cover all niches so that customers do not switch to competitors without finding the optimal model for themselves. Very often it is more profitable to produce one universal chip in a large batch and place it in different packages than to launch a dozen different ones. For chips placed in packages with a small number of pins, some of the ports (in this context, by ports we mean contact pads on the surface of the chip, which are used for communication with the outside world) will simply remain unconnected. Manufacturers often go further - in order to increase the demand and price for microcontrollers with a large number of legs, they artificially cut off the functionality of those that have fewer of them - they disable some functions, limit the amount of available memory, etc.
So, based on one chip, a series of microcontrollers are formed, which differ significantly in memory capacity and set of peripheral modules, sometimes at several times in price. At the same time, the chips installed in them can be cut from the same wafers. Since the area on which one chip is placed is small, its contribution to the cost of the final product is also small and can be sacrificed. It becomes advantageous to disable additional memory and other functions, for example, during the testing phase - either using one-time programmable configuration bits, or by burning jumpers with a laser. Only for the most mass-produced products does it make sense to create a slightly modified photo template for this purpose. Moreover, it is not at all necessary that there will be physically no unused memory there; again, it can simply be disabled by removing the jumpers in the template.
This is how a whole series of microcircuits is formed from one standard chip design.
Peripherals of the simplest ARM microcontroller for half a buck
The processor core is the brain, but in order for it not to be like a “spherical horse in a vacuum,” analogs of the senses and limbs are required.
In a microcontroller, their role is played by pins on the case, to which the ports (contact pads) of the chip can be connected inside the case. In turn, through internal switches, various peripheral modules can be connected to the same port. First, let's look at the periphery of one of the simplest series from ST based on the Cortex-M0 core - stm32F03.
For this series we have the following set of basic functions:
Real Time Clock (RTC)
, which can be powered using a separate pin and operates from a separate low-frequency resonator. This module consumes extremely little energy; in the event of a main power failure, it can operate for hours on a charged capacitor, or for years on a small battery built into the device. In addition, it can serve as an alarm clock, waking the microcontroller from even the deepest sleep state at a predetermined time.
WatchDog
- a guard dog that prevents the microcontroller from falling asleep forever, for example, by falling into an endless loop or going to a non-existent address. Its operating principle is simple. The programmer sets the anti-freeze timer for a certain period of time, say a second, and starts it. Then he places, at places in the program of his choice, short sections of code that restart the timer from zero. If not a single timer reset occurs within a second, WatchDog believes that something is wrong with the program and restarts the microcontroller. The program starts working from the beginning, and it is possible to determine whether WatchDog was the initiator of the reset and take this fact into account when starting.
General Purpose Input-Output GPIO
- This is the most common function that is supported by most microcontroller pins. They can be configured as either inputs or outputs.
Consider work as an input. If the voltage at the input of the microcontroller is less than a certain threshold (usually close to half the supply), then it is perceived as a logic zero, otherwise as a 1. Digital inputs usually have very high input impedance, so if they are left unconnected, their state may jump from zero to one and back, under the influence of electromagnetic fields. To prevent this from happening, there are special modes when inside the chip the input is connected through a resistance of 20 - 50 KOhm to the plus of the microcontroller power supply (pull-up) or minus (pull-down).
If the pins are configured as digital outputs, then they can be switched by software to a high level equal to the microcontroller supply voltage, or to a low level. There are more tricky modes, but we won’t go into too much detail.
Tips for Beginner Developers
Pinouts The microcontroller is a jack of all trades, but you should follow simple rules so as not to damage them. Despite all the precautions taken by chip manufacturers, they are afraid of static and overvoltage, so you should not connect them directly to connectors that extend beyond the board. In this case, it is necessary to take measures - either use special integrated protection components, or provide a suppressor, zener diode or protective diodes in the circuit, plus install a current-limiting resistance in the gap between the connector pin and the port.
The figure above shows a section of the circuit of a device I designed (satellite modem), with elements of the simplest protection of microcontroller ports. X4 - connector for external communications. We are interested in contacts 5-7, to which panic buttons are connected. The alarm signal is a ground fault, therefore, in normal condition, the microcontroller supply voltage must be present at the ports, which is provided by resistors R24-R26, rated 1 KOhm. Suppressors VD4-VD6 limit the voltage to 5 volts, this is acceptable because the microcontroller I use, although powered by a voltage of 3.3 volts, has ports tolerant to a voltage of 5 volts. Resistors R29-R31 100 Ohm. Such protection will save the ports of your microcontroller from external overvoltages. On some microcontrollers, individual ports are not afraid of voltages exceeding their supply voltage. So, on many STM32Fxx microcontrollers, almost all ports, when configured as digital, can work with 5-volt circuits, but if they operate in analog mode, for example, as an ADC input, they lose this ability and this must be taken into account when designing the circuit.
Please follow safety precautions. Do not leave free, floating microcontroller ports configured as inputs, especially in devices that sometimes go into deep sleep - at the very least, this can significantly complicate the process of passing your device's EMC (electromagnetic compatibility) test. If you leave them as inputs, it is better to short them to ground or power. Or programmatically configure the outputs.
There is another life hack. Sometimes they can be left as an input and connected to another circuit. This helps, in the case of very dense routing, to pass the conductor “through” the microcontroller, which is especially important for double-layer boards.
When using microcontroller ports as outputs, it is also worth checking the datasheet.
Individual ports may have different limits on the maximum current that can be obtained from them without fear of their failure - load capacity. In addition, the chip itself has a maximum load capacity of all outputs in total, which should not be exceeded. The last thing I want to mention is that the output ports of ARM microcontrollers do not respond to software instructions instantly, like 8-bit microcontrollers. They are controlled via the bus, and their performance depends on the clock frequency of the corresponding node, which can be changed by software. If you want a quick response, take care to increase this frequency; if it is more important to reduce power consumption, on the contrary, select a lower speed mode. Temperature sensor
The microcontroller has its own temperature sensor, although it is not very accurate, however, it can, with certain assumptions, be used to measure the temperature inside the device body.
Unique serial number
Each microcontroller has its own unique serial number assigned to it at production. A very convenient feature that can be used when organizing mass production of your products.
Data exchange interfaces
Various microcontrollers of this series can have several of the most common interfaces, which greatly facilitate communication with other chips and the outside world:
- USART is an asynchronous serial port, often used to communicate with a computer where it is called COM or RS232, modems and other devices
- SPI is a high-speed interface that many chips have, for example external memory
- I2C is a two-wire interface designed to communicate with sensors and other peripherals over short distances and low exchange rates. Its big advantage is that dozens of different devices can be connected to one bus at the same time
All these interfaces are easy to implement in software using regular GPIOs, but they will work much slower and take up a lot of core resources.
Analog-to-digital converter ADC or ADC
which will have to be discussed in more detail.
An extremely useful module that is capable of measuring the voltage of analog signals. He estimates them in fractions of the value of the reference signal source, in our case this is the supply voltage of the analog microcontroller module, which can be equal to or slightly lower than the main supply voltage of the chip. The theoretical accuracy of an ADC depends on its bit capacity. In modern microcontrollers, a 12-bit successive approximation ADC is most often used, less often 10, and 16 is more exotic.
With a power supply of 3 volts, the 12-bit ADC of the microcontroller will have a resolution of 3/4096 = 0.00073 Volts - better than one millivolt.
But in practice, achieving this ideal is not easy.
Details for novice developers
In practice, everything is not so beautiful and the accuracy of measurements can decrease for many reasons. Below I list the main ones, well known to any experienced electronics engineer, as well as simple but effective ways to reduce their harmful effects to a minimum: voltage instability of the ADC power supply
- use linear stabilizers with good parameters to power the MCU
- use highly stable reference voltage sources to power the analog part of the MCU
impulse noise on the ADC power supply
- connect analog power to digital power through simple low-frequency filters - supply power to the analog part of the MCU through inductance and install a ceramic capacitor with an XR7 dielectric with a capacity of 100 nanofarads in close proximity to the microcontroller input, or even better, connect a tantalum capacitor with a capacity of one in parallel to it - two microfarads.
pulse noise at the ADC input
- pass the input signal through at least the simplest low-pass filter, consisting of a resistor and capacitor. To combat interference from transmitting radio paths and short pulsed noise, sometimes a single capacitor with an NP0 dielectric with a capacity of several tens of picofarads, installed between the input and ground, in the immediate vicinity of the ADC input, is sufficient.
- do not skimp on blocking capacitors, at least of the microcontroller itself, install them in close proximity to each power pin and in other places recommended by the manufacturer, at a value recommended by him
- carefully select the location of components and follow the rules for routing power circuits and especially ground; ideally, analog and digital grounds should be connected at one point - next to the analog ground pin of the microcontroller
high output resistance of the signal source
is dangerous because at the moment the measurement of the successive approximation ADC, which is most often used in microcontrollers, starts, its input consumes some non-zero current and this can lead to a decrease in the true voltage value, since the signal is actually supplied through a divider voltage.
- choose the right ADC settings, for example, in many microcontrollers you can increase the charging time of the input circuit, although here you have to make a compromise, reducing performance
- install buffer amplifiers based on an op-amp (operational amplifier) or voltage followers at the ADC input. There is no point in choosing them based on the cheapest ones; you may not improve, but worsen the situation, and significantly. If you lack your own experience, it is better to look for ones specifically recommended by manufacturers for such applications.
Above is a section of a real circuit for supplying power to the analog part of the microcontroller in a battery-powered device.
In this case, I used an ADC to digitize the signal from an analog MEMS microphone and therefore it made sense to separate not only the analog power supply, but also the analog ground into a separate circuit. In most cases, this is redundant; in order for it to really be useful, it also needs correct routing. The entire digital part of the microcontroller is powered from the VBUT circuit. Just in case, I give the ratings of the elements: R5-10 Ohm, C10 0.1 µF, in most cases you can do without inductances L1 and L2 BLM18PG471SN1D.
Another interesting example from my practice. The board, which housed a large number of high-power ASIC chips, needed to measure their temperature. The easiest and cheapest way is to use high-resistance thermistors. I used fairly large capacitors as filters, taking advantage of the fact that the temperature changes relatively slowly. For digitizing sound, such a trick would definitely not work.
It remains to mention one more important feature of the ADC, characteristic of microcontrollers.
Actually, there are usually one or two ADC modules in it, but there can be many inputs. In the described series there is 1 module, but there can be up to 16 inputs. How can this be? Very simply, the inputs are connected to it via a switch. If you are going to measure voltage from 10 inputs, you must organize a cycle - sequentially switch the switch to each of the 10 inputs and take a measurement. This must be taken into account when calculating measurement times. In this series, the ADC is theoretically capable of making a measurement in 1 microsecond. It turns out that a full cycle of 10 measurements will take you exactly more than 10 microseconds! The DMA or DMA direct memory access system
is another extremely important thing. This module allows you to transfer data from peripherals to memory or vice versa.
For example, with its help you can allocate a section of memory to store data coming from an ADC and make a ring buffer out of it. Next, the ADC is started in data reading mode at regular intervals. Using DMA mechanisms, the read data will, without the participation of the kernel, be placed on its own, byte by byte, into a dedicated buffer. When the buffer is completely full, the kernel will receive the signal and begin processing it in software, and the DMA system will begin the boot process all over again. Since DMA has several channels, no one bothers us to implement automatic output of data from the buffer to the USART in our case. As a result, we will get a process that works without using a core, transferring data read from the ADC to the USART, and the programmer’s hard work on the DMA configuration will pay off handsomely.
Pulse width modulation module PWM or PWM
, due to the limitations of the article, we will not dwell on it in detail, I will only note that this is an extremely useful and widely used function, with which it is possible to control the brightness of LEDs, the rotation speed of motors, steering gears, design intelligent DC-DC converters and even synthesize sound.
What can you get by adding 30 cents?
Transition to Cortex-M0+. The cheapest way to get additional features
And what additional goodies does the newest series of microcontrollers with a slightly more modern core Cortex-M0+ offer, at a cost of 20-50 cents more than analogues in the series discussed above in terms of housing and number of pins?
Table of differences between series
- the maximum clock frequency has doubled
- The minimum supply voltage decreased from 2 to 1.7 volts
- The ADC can operate two and a half times faster
- two channels of a 12-bit digital-to-analog converter appeared. This is an extremely useful function, with which it is possible to generate a signal of a given voltage at the pins with an accuracy better than 1 mV, for example, arbitrary-shaped signals in the audio frequency range
- Comparators have appeared - devices for comparing the values of two analog signals, this can be useful, say, for determining the moment when an overcurrent occurs
- A USB interface has been added, through which you can connect devices to your computer. Of particular interest is the availability of support for power management options for implementing a USB type3-C compatible interface. I talked about it in one of my articles on Habré
- AES accelerator has appeared for 256-bit encryption/decryption procedures
- UART has the ability to work in sleep modes and hardware support for the LIN (simple network, widely used in the automotive industry), IRDA (data transfer protocol via infrared LEDs, remember TV remote controls), SIMcard...
- expanded capabilities of timers and PWM module
- the upper limit of the operating temperature range rose to 125 degrees
- Operation reliability has been increased by expanding restart modes when power problems occur.
- added “fair” hardware random value generator - a useful feature in cryptography
Well, for many applications, a slight addition in price is quite worth it, since you can refuse to switch to more expensive microcontrollers of older model series.
What will the transition to Cortex-M4 add, besides the price increasing by a couple of times?
- The maximum clock frequency increases to 80 MHz
- A block has appeared to speed up floating point calculations
- Of course, the maximum built-in memory has increased
- Models with 100 or more legs support external static memory
- USB has learned to work in HOST mode
- A CAN interface controller has appeared. This is a very promising interface designed for highly reliable applications. He began his victorious march with the automotive industry and for almost 20 years he has been waging a protracted war with the long-outdated RS-485 in the extremely conservative industry of industrial automation.
- An interface for connecting SDcard has appeared. A very useful feature - you add a holder to your device for 50 cents and get removable media tens of gigabytes in size! It is possible to work with most cards using regular SPI, but much slower
- We added a built-in Operational Amplifier with a wide variety of operating modes. It was thanks to this and the previous functions that I had to choose the M4 instead of the M0+ for my latest wireless stethoscope project. As a result, it became possible to control the signal amplification from a MEMS microphone and save tens of hours of audio recordings of heart activity on an SD card
- The cryptomodule has learned to calculate HASH functions in hardware.
- The touch application controller has been improved and now supports not only buttons, but also scrolling elements
Cortex-M7 - when you want more...
In the vast majority of projects, the capabilities provided by the kernels described above are sufficient, but there are exceptions. Personally, this happened to me only a couple of times, and only once for a really good reason - high performance was required to prepare data for ASIC, an Ethernet controller and a CAN-FD bus with an increased exchange rate.
If at the level of universal microcontrollers with Cortex 4 cores and below, in my subjective opinion, ST is now the leader in terms of price/functionality, then in the field of higher-performance chips it is losing leadership to ATMEL, or rather, to MICROCHIP, which has now recently absorbed it. Therefore, I chose the ATSAMV71 series, starting at $6.
In addition to the above (Ethernet controller and CAN-FD bus), by and large, we get a core with an operations accelerator that significantly increases performance, operating at a clock frequency of up to 300 MHz, interfaces for connecting a video matrix and support for dynamic memory.
In conclusion, I will ask those who have experience in communicating with microcontrollers to choose the appropriate answer to the question.
What is needed to program a microcontroller
In order for the microcontroller to perform the necessary functions and solve certain tasks, it must be programmed.
The programming path goes through several stages:
- Before you start writing program code, you need to decide on your ultimate goal.
- An algorithm for the program is compiled.
- Direct writing of program code. The codes are written in C or Assembly language.
- Compiling a program, i.e. translating it into a binary or hexadecimal system of 1 and 0. This is the only way the MK can understand it.
- The compiled code is written to the controller memory.
- The MK is flashed using a programmer. They come in two connection types: via COM or USB port. The simplest and cheapest USBASP programmer.
- Testing and debugging of MK on a real device.
Radio amateurs sometimes get by without writing down the algorithm of the program on paper. They keep it in their heads.
Programming languages
Programming languages for microcontrollers are not much different from classical computer languages. The main difference is that MKs are focused on working with the periphery. The MK architecture requires bit-oriented instructions. Therefore, special languages were created for controllers:
- Assembler. Lowest level of language. Programs written in it are cumbersome and difficult to understand. But despite this, it allows you to fully reveal all the capabilities of the controllers and get maximum performance and compact code. Suitable mainly for small 8-bit MCUs.
- C/C++. Higher level of language. A program written in it is more understandable to humans. Today there are many software tools and libraries that allow you to write codes in this language. Its compilers are available on almost any MK model. Today it is the main language for programming controllers.
- An even more easy-to-understand and design language. But it is rarely used for MK programming.
- An ancient programming language. Today it is almost never used.
The choice of programming language depends on the tasks to be solved and the required quality of code. If you need compact code, then Assembler is suitable; for solving more global problems, the choice will be limited to C/C++.
Principle of operation
In the previous paragraphs we operated with abstract concepts, now it’s time to move on to real and practical examples. The operating principle of any, even the most complex controller, comes down to the following algorithm:
- It accepts certain variables or other data that must first be converted into a binary signal. This is necessary because at the lowest level the system is capable of perceiving only 2 states - there is a signal or there is no signal. This principle is called analog. There is a similar algorithm when the signal is constantly present, but varies in frequency - digital. They have many differences, both in areas of application and in the features of signal operation, but the essence is the same - the processor is only capable of perceiving the values 0 and 1, or true and false, and it does not matter in what ways microprocessors and microcontrollers will read them.
- A set of special instructions is stored in the internal memory of the device, which allows, through basic mathematical transformations, to perform some actions with the received data. It is these basic operands that are used by compiled programming languages when it is necessary to write a library of ready-made functions. The remaining nuances of programming languages are the syntax and theory of algorithms. But in the end, it all comes down to the basic operands, which are turned into binary code and processed by the processor's internal system.
- Everything that was received and stored after processing is output. In fact, this point is always fulfilled, the only difference is that the output can also be a transformation of the state of an object of some system. The simplest example would be the closure of an electrical circuit if current is supplied to a special sensor, as a result of which the light bulb lights up. Here everything depends on the type of device, for example, an 8051 microcontroller can perform several types of outputs, having 14 pins, while some others can only do one, because it has 1 pin per output. The number of outputs affects the multi-threaded properties of the device, in other words, the ability to output information to several devices at once or perform several actions simultaneously.
In general, any mono or polycrystalline unit works according to this algorithm, the only difference is that the second is capable of performing several calculations in parallel, and the first has a specific list of actions that must be performed sequentially.
This directly affects the speed of operation of devices, and it is precisely because of this characteristic that 2-core devices are more powerful than 1-core ones, but have a higher hertz (the ability to perform a greater number of transformations per unit of time).
But why is the Aries microcontroller not capable of performing some of the actions characteristic of the 8051, and what classification even exists in this area?
Development environment
Today it is impossible to find a universal environment for programming MK. This is due to its internal structure and the presence of technical support for writing code into the controller’s memory.
Here are some programming environments:
- FlowCode is a universal graphical environment. It is programmed by constructing logical structures of block diagrams.
- Algorithm Builder. Also a graphical environment. But writing code is 3-5 times faster than in FlowCode. It combines a graphic editor, a compiler, a microcontroller simulator, and an in-circuit programmer.
- It combines Assembler and C/C++. The functionality of the environment allows you to independently flash the MK.
- Image Craft. Like the previous one, it supports Assembly and C/C++ languages. It includes a library that allows you to work with individual MK devices.
- A popular medium for hobbyists. It has a C-like language, but different from others. It is more understandable to humans. Supports libraries that contain drivers for connecting some platforms.
There are paid and free environments. When choosing a specific environment, you need to proceed from its functionality, programming language, supported interfaces and ports.
ARM architecture
Our goal is not to provide an exhaustive description of the kernel; on the contrary, our goal is to give a superficial idea so that we can start doing something. More information about the kernel architecture can be found in special publications or in the documentation.
Cortex includes not only the core, but also various control and debugging components, which are interconnected by AHB and APB buses. Two more components that we will need later are:
- NVIC is a built-in interrupt controller, which we will talk about later. The number of possible interrupts is determined by the chip manufacturer. This controller is tightly coupled to the kernel and contains system control registers.
- SysTick is a system timer, which is a subtractive counter that can be used to generate interrupts at regular intervals (even if the MCU is in sleep mode)
Image from Reference Manual, Figure 1. Low and medium density value line system architecture)
Basics of programming
Before you start programming the MK, you need to select a language. It's better to start with Assembler. Although it is quite complicated to understand, if you put in the effort and still understand its logic, then it will become clear what exactly is happening in the controller.
If assembler turns out to be difficult, then you can start with C. One of its strengths is that it transfers codes well from one type of MK to another. But to do this, you need to write everything down correctly, dividing the working algorithms and their implementations in the machine into different parts of the project. This will allow you to transfer the algorithm to another controller, redoing only the interface layer in which access to the hardware is written, leaving the working code unchanged.
Then proceed according to the following scheme:
- Choosing a compiler and installing the environment (more about them was written above).
- Launching the environment and selecting a new project in it. You will need to indicate the location. The shortest path must be chosen.
- Project setup. The classic action would be to create a makefile that contains all the dependencies. On the first page they also indicate the operating frequency of the MK.
- Setting up paths. You need to add the project directory to them. You can add third-party libraries to it.
- Formulation of the problem.
- Assembling the circuit. At this stage, you need to connect the USB-USART converter module to the same pins of the MK. This will allow you to flash the microcontroller without a programmer. You need to put on jumpers connecting LED1 and LED2. With this action we will connect LEDs 1 and 2 to pins PD4 and PD5.
- Write down the code.
- Adding libraries and headers with definitions.
- Main functions. The C language consists of only functions. They can be nested and called in any order relative to each other and in different ways. But they all have three required parameters: 1) return value; 2) transmitted parameters; 3) function body. Depending on the data, all returned or passed values must be of a certain type.
- Compiling and running emulation.
- Debugging the program.
After you have written a program in C, you can observe how and what happens in MK. This will help to build an analogy with assembly language programming.
Tips for novice microcontroller programmers
So that your first experience in MK programming does not end in failure and forever discourage you from doing this business, you need to follow some tips:
- Start by studying the periphery and its features.
- Each large task must be divided into as many small ones as possible.
- At the beginning of your journey, you should not simplify your life and use code generators, non-standard features, etc. things.
- It is necessary to study programming languages (C and Assembly).
- Read the Datasheet.
- Gather the necessary set of tools. This costs some money, but will pay for itself in time savings and quality of work.
It's never too late to become a radio amateur, whether you're 30 or 50. And it's not necessary to have a specialized higher education. Nowadays there is a lot of available information on the Internet, by studying which you can understand the structure of microcontrollers and learn how to program them.
Microcontrollers for Beginners
The best example of a microcontroller for novice engineers would be the Arduino board, for the reasons already mentioned.
You can quickly figure it out thanks to the low entry threshold, but also, if you wish, learn various interesting design and problem-solving patterns.
All this will allow the beginner to develop, get to know the world of radio engineering, and possibly programming, which in the future will become a good basis for studying more complex things and implementing large projects. Therefore, there is no other, more suitable platform for beginners.