8. Embedded Programming¶
Comparison between different microcontroller families¶
There are multiple families and framework when it comes to microcontroller.
Introduction to microcontrollers¶
A µ-controller is an integrated circuit (IC) that is like a very small computer, able to perform specific tasks. They are programmed to perform these tasks over and over again, on loop (but can be programmed to respond to conditions of course).
A µ-controller contains multiple parts: a processing unit of course but also some memory. This memory is either volatile: DRAM (dynamic, inexpensive and space-efficient and SRAM (static, much faster but also more expensive) that will be erased when not powered or non-volatile like EEPROM or Flash memory.
The µ-controller does not work on its own but is rather embedded and works with other components so it needs inputs and outputs (I/O) for peripheral access.
Finally, a big requirement for the µ-C to function is the clock which is sometimes provided externally and allows the µ-C to perform timer conditions.
µ-C Families¶
There are multiple microcontroller families.
In particular, we can compare the Atmel, Microchip and Espressif µ-C. Atmel produce both the AVRs and the ARMs: AVRs are manufactured by Atmel (now bought by Microchip actually) and the most common examples are the ATTiny and ATmega chips which are cheap and effective. That is somewhat of an issue as if you produce something industrially that relies on an AVR controller and Atmel (now Microchip) stops producing them but it should not happen soon. AVRs are usually 8-bit, cheap µ-C.
ARMs are produced by multiple companies and are usually used for embedded systems as they provide more features and memory than their AVRs counterparts. They are however more difficult to solder (less DIP format and usually more pins), less available in general and are usually constrained to 3.3V (requires additional converter from 5V therefore). ARMs are usually 32-bits, more powerful and more expensive that AVRs.
They both use RISC (reduced instruction set computer) instructions, meaning they require a few clock cycles (usually one) to perform an instruction but these instructions are rather primitives, allowing more space for registers.
1 2 3 4 5 6 7 8 |
|
The ESP32 is a µ-C developed by Espressif, a new Chinese manufacturer. It is very recent and features very advances features at a somewhat low-cost: WiFi, Bluetooth, 240MHz clock with 500kB of RAM, …
µ-C programming¶
As said before, a µ-C can perform specific tasks like switching an LED on or off or actuating some servo-motors. To specify these tasks, the µ-C needs to be programmed.
To be programmed, a µ-c must first be loaded with a bootloader, i.e. a small piece of code that can reprogram the rest of the memory based on what is sent to the µ-C and is interpreted by the bootloader. At reset, it’s the bootloader that runs first and has a look at the programming port to either reprogram the rest of the memory or jump directly to the programmed main code. Then, code can be sent to program the µ-C the way you want it.
AVR¶
AVRs are programmed using ISP (in-system programming), PDI (Program and Debug Interface) or UPDI (unified Program and Debug Interface). The latter is the one used on newer AVR devices and consists in a one-wire interface.
ARM¶
ARMs are programmed using either a JTAG (Joint test Action Group, the group who designed the standard) interface or a SWD (Serial Wire Debug) interface.
JTAG uses 5 pins: clock, mode select, data-in, data-out and reset. It can be reduced to only serial data and clock.
SWD is an implementation of JTAG for ARM processors and consists of simply two pins: data and clock (SDIO and SDCLK) along with VDD and GND obviously and an optional reset.
ESP32¶
The ESP32 is programmed using the UART pins. Most development boards come with a FTDI converter for USB-serial conversion. It is also possible to program it “Over The Air” (OTA) that, if enabled, the ESP32 will open a web socket when connected to the WiFi and the OTA service will handle the transfer and the flashing of the ESP32.
µ-C capabilities¶
The memory of the controller is usually implemented either in the EEPROM (which is the case for the ATTiny1614 and the ATMEGA328p) or in the flash memory.
The processor frequency, multiplied by the number of bits per instruction (see above for RISC vs CISC) will give an approximate idea of the computing power offered by the chip.
name | company | year | type | GPIO | ADC | prog. mem. | data mem. | RAM | f_CPU (max) |
---|---|---|---|---|---|---|---|---|---|
ATmega328p | Atmel | 2010 | 8-bit | 23 | 6 | 32kb | 1024b | 2kb | 20MHz |
ATtiny1614 | Atmel | 2018 | 8-bit | 12 | 10 | 16kb | 256b | 2kb | 20MHz |
PIC32MX320F064H | Microchip | 2008 | 32-bit | 53 | 16 | 64kb | 12kb | 16kb | 80MHz |
SAMD11C14 | Atmel | 2015 | 32-bit | 12 | 5 | 16kb | 6b | 4kb | 48MHz |
ESP32 | Espressif | 2016 | 32-bit | 34 | 18 | 16Mb | 4Mb | 520kb | 240MHz |