📜 ⬆️ ⬇️

Electronics development. About microcontrollers on fingers



Conceiving a technology startup, you are not at all obliged to be an expert in electronics, a narrow specialist with a knowledge of the basics of marketing has a much better chance of a good idea, but even ordering someone to develop, it is necessary 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 overestimated cost on an outdated element base.
Under the cut an attempt to briefly and simply talk about the capabilities of modern microcontrollers to people far from them. For those who have the idea of ​​a new electronic device, but there is no idea of ​​what a microcontroller is. Those who want to take the first step from entertaining experiments with the Arduino platform to design their own devices can also find simple but useful tips. I tried, not dwelling on technical details, for this and the book it is not enough to state the essence and give some simple but useful tips on circuit design to warn against elementary mistakes of beginners.

Summary of the article:


How microcontrollers conquered the world
ARM architecture is today's leader in the microcontroller market
Competition with younger brothers
On laying asphalt, the benefits of sleep and its varieties
Very briefly on manufacturing technology and how a series of microcontrollers appear
Peripherals of the simplest ARM microcontroller for half a dollar
The cheapest way to get extra features.
And what will add the transition to the Cortex-M4, except for the increased price a couple of times?
Cortex-M7 - when you want more ...


Protecting the code, the ability to update it and the variety helped microcontrollers to conquer the world


Any smart device requires control. In most cases today microcontrollers are engaged in this - chips that combine the microprocessor core, memory and peripheral modules that are responsible for communication with other components of the device and the outside world.
')
Microcontrollers - jack of all trades. One microcontroller can replace dozens of specialized chips that would be necessary to perform the required functions if the microprocessor were to take on the role of the computer.

One of the indisputable advantages of the microcontroller is that the program under which it works is hidden inside its case (in the section called “program memory”) and is very well protected from hacking, of course, if the microcode developer took care of this by activating the embedded mechanisms protection. Thus, you get the protection of intellectual property as much as possible today.

What can not be hacked - you can copy. Why try to read the code embedded in the microcontroller of the program with the help of expensive sophisticated devices, if it is easier and cheaper to find a professional who can write it again? Perhaps the result will be even better, and the functionality is richer than that of the prototype. Yes, it costs money, but the content of the FLASH memory of today's microcontrollers is so well protected that attempts at rude “hacking” will cost even more. In addition, the problem of intellectual property is being solved, and you, along with the source codes of the program, get the opportunity to develop and improve your device.

The memory of programs in modern universal microcontrollers is rewritable, and the rewriting process can be repeated more than one thousand times. This suggests the use of this fact to update the software in order to eliminate errors found in it or to expand the functions of an already operating device. This is easy to implement - by adding a special section of code called “bootloader” to the program, you can update the software of your device in various ways: at the service point (if the device has a special connector hidden from prying eyes). computer via USB, via a network or even a wireless interface. The main thing is to provide the necessary peripherals in the device. Providing the ability to update software, you should always think about security, if this process is not sufficiently protected, it’s not only that attackers can steal your code, they can modify it and use it for their own purposes , which is insidious . For example, to take control of the things of your “smart home” or to spy using the WEB camera installed by you at home.

ARM architecture is today's leader in the microcontroller market


Since the time of the Tsar of Peas, microcontrollers are usually divided according to the bit length of the data on which they perform operations. In the overwhelming majority of cases, today, in new developments, one should opt for 32-bit microcontrollers with the ARM core. There is a huge number of modifications and you can always choose a copy that is best suited for solving your problem. Depending on the set of functions and performance, the price of a chip can be from tens of cents to tens of dollars.
Microcontrollers (MCU), depending on the architecture of the computational core, can be divided into large families. Today, for the development of devices of small and medium complexity, the most popular microcontrollers with cores from Cortex-M0 to Cortex-M7. The larger the figure, the greater the computational (and not only) capabilities, price, and maximum power consumption. Not the last role in the popularity of ARM has played the continuity of architecture. A developer can modify the software code of his previous developments with minimal costs, moving from microcontrollers of one manufacturer to chips of another and migrating between cores with different performance.


Competition with younger brothers


However, ARMs did not always rule. I remember well the days when the absolute market leaders were 8-bit microcontrollers and, from their positions, they were unsuccessfully tried to push back 16-bit colleagues, but, ironically, only 32-bit older brothers managed to do it. It so happened that by the time they appeared, the chip manufacturing technology had greatly reduced the cost of integrating large amounts of FLASH memory into them. Taking advantage of the opportunity, programmers began to move from assembly language to a higher level language - C, whose structure perfectly fit 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 computational performance was required.

It is known that the average current consumption of the computing core of the microcontroller increases significantly with the raising of its clock frequency. Initially, 8-bit models of microcontrollers differed noticeably lower consumption at a similar frequency and, in addition, were able to operate from a low clock frequency, up to 32 kHz.

The power consumption of microcontrollers strongly depends on the clock frequency of the core and the periphery, in order to regulate it, to generate the use of the PLL-based clock generation unit widely used in radio transmitters. This made it possible to change the clock frequency over a wide range without changing the quartz resonator. Peripheral modules do not necessarily have the same clock frequency as the computational core. In order to reduce their energy consumption, they began to apply the frequency through dividers with a program-controlled division factor. Introduced the ability to disable unused modules. These measures have greatly reduced power consumption, but it still remained substantially more than 8-bit ones.

For a short time, parity developed - 32-bit MCUs captured a niche of top-end applications, and 8-bit ones confidently held positions in devices for which low power consumption was important. It persisted until 32-bit MCUs mastered the “pulse” mode of operation to perfection.

8-beatniki, by that time, also learned how to do it, but due to poor performance, they had to stay awake much more and, as a result, they began to lose in terms of power consumption, especially in tasks requiring calculations, as the picture below illustrates.



On laying asphalt, the benefits of sleep and its varieties


So, microcontrollers have learned so well to believe that they began to do their work very quickly, and most of the time they were forced to “slack off”, devouring energy to perform idle cycles. In self-powered devices, this greatly shortens the battery life or the operating time from a single battery charge.

Observe construction workers who lay asphalt. They sharply intensify their work when the truck arrived with a new batch of asphalt, and after its laying they slow down. So microcontrollers can increase and decrease the clocking frequency of the core. However, it is not so easy for them as for workers - the frequency of the entire inner periphery will change at the same time, therefore, we will have to reconfigure sensitive parts.
Isn't it easier, after doing all the work quickly, to get some sleep. Often, yes. And the types of sleep microcontrollers differ even more dramatically than in humans.

You can just take a nap. In this case, our chip is always at the ready and as soon as the timer's alarm clock rang or the external interruption disturbed it, it wakes up almost instantly. As a person during a nap, can relieve tension, but not really sleep enough when you are constantly pulled, so a microcontroller can reduce its power consumption in this mode “only” every 10, call this mode SLEEP.

The best way to sleep well is to undress, go to bed, close the curtains on the window and set the alarm. However, after such a dream, you will not immediately turn into work. It is necessary, at least, to pre-rinse with cold water and get dressed. There is such a mode and the microcontroller, when it limits the number of external stimuli and turns off the main clock generator. This is the STOP mode. It can reduce consumption by a factor of 1000, but it also takes considerable time to get out of it.

Now, imagine that you had drunk a good dose of sleeping pills before going to bed, turned off the alarm clock and the phone, closed all windows and doors. This will be the STAND BY mode. The microcontroller can be removed from such a mode only with the help of special conclusions, and most of the memory of what he did before such a dream will be lost forever will have to be restarted. But while in this mode, the MCU consumes another two times less.

The latter, a very exotic mode, reminds already to whom, from which it is impossible to leave without special equipment. In this case, only a special generator works , however, which is part of the microcontroller on a separate watch quartz, which can function from its own power source and have literally several bytes of RAM, the purpose of which is to remind the microcontroller of what state it went into. If the other parts of the microcontroller are disconnected from the power supply at the same time, then the power consumption may be one ten thousandth of the active mode.

Choosing a power saving mode, you must remember the consequences of the application :



If your programmer with a circuit engineer does not blame each other for the first day of curvature and, together, the manufacturer, in publishing unrealistic numbers in datasheets for the microcontroller, and your device puts the batteries 10 times faster than you expected, this is an excuse highly qualified experts.

Very briefly on manufacturing technology and how a series of microcontrollers appear


The physically active part of the microcontroller, like the overwhelming number of other chips, is usually formed on a monosilicon plate (let's call it, in this context, the CHIP). Chips occupy a very small area, it is technologically advantageous to produce plates of large diameter, therefore, usually a large number of chips, like cells, are placed on one large plate and formed, during one technological process. Subsequently, the plate is cut into pieces, getting already separate chips, which are placed in the case. Development of topology and debugging of technological processes of the new chip is very expensive, and the place occupied on the plate with one chip, as a rule, is not large. It is profitable for manufacturers to produce chips in large batches, but users need microcontrollers in different cases - it is important for someone to get a smaller and cheaper case, on the contrary, more conclusions are needed to control the LCD or external memory with a parallel interface. It is profitable for manufacturers to cover all niches so that customers do not run over to competitors without finding the optimal model for themselves.

It is often more profitable to release a large batch of one universal chip and place it in different enclosures than to launch a dozen different ones. For chips placed in housings with a small number of pins, some ports (in this context, ports will be understood as contact pads on the surface of the chip that serve to communicate with the outside world) will simply remain unconnected. Often, manufacturers go further - in order to raise the demand and price for microcontrollers with a large number of legs, they artificially cut off the functionality of those that have less of them - turn off some functions, limit the amount of available memory, etc.

So on the basis of a single chip form a series of microcontrollers, significantly different in memory and a set of peripheral modules, sometimes and at times in price. In this case, the chips installed in them can be cut from the same plates. 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 donated. It becomes advantageous to turn off additional memory and other functions, for example, at the testing stage — either with the help of single-time programmable configuration bits or with laser bridges. Only for the most mass products it makes sense for this to create a slightly modified photo pattern. Moreover, it is not at all necessary that the unused memory will be physically absent there, again, you can simply turn it off by removing the jumpers in the template.


So from one standard chip design a whole series of microcircuits is formed.

Peripherals of the simplest ARM microcontroller for half a dollar


The processor core is the brain, but in order for it not to be like a “spherical horse in a vacuum,” analogs of the sense organs and limbs are required.

In the microcontroller, their role is played by the pins on the case, to which ports (pads) of the chip can be connected inside the case. In turn, through internal switches, different peripheral modules can be connected to the same port.
To begin, consider 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 (Real Time Clock or RTC) , which can be powered using a separate output and operate from a separate low-frequency resonator. This module consumes very little power; in case of a main power failure, it can work for hours from a charged capacitor, or for years from a small battery built into the device. In addition, it can serve as an alarm clock, bringing the microcontroller out of even the deepest sleep at a predetermined time.

WatchDog is a guard dog that prevents the microcontroller from falling asleep forever, for example, by falling into an endless cycle or by going to a non-existent address. Its principle of operation is simple. The programmer sets the “freeze” protection timer for a certain period of time, say for a second, and starts it. Then he places, in the places of the program chosen by him, short sections of code that restart the timer with a zero value. If within a second there was not a single reset of the timer, 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 the initiator of the WatchDog reset was and to take this fact into account at startup.

Universal Purpose Input-Output GPIO is the most common feature that most microcontroller pins support. They can be configured either as inputs or as outputs.

Consider working as an entrance. If the voltage at the microcontroller input is less than a certain threshold (usually close to half the power), then it is perceived as a logical zero, otherwise as 1. Digital inputs usually have a very high input resistance, so if left unplugged, their status can jumping from zero to one and back, under the influence of interference from electromagnetic fields. In order to prevent this from happening, there are special modes when the input inside the chip is connected through a resistance of 20–50 kΩ with a microcontroller power supply (pull-up) or a minus (pull-down) power.

If the pins are configured with digital outputs, then they can be programmatically transferred to a high level equal to the microcontroller supply voltage , or low. There are more tricky modes, but we will not go into excessive details.

Tips for novice developers
The conclusions of the microcontroller are the master of all trades, but simple rules should be followed so as not to disable them. Despite all the precautions taken by chip manufacturers, they are afraid of static and overvoltage, so do not connect them directly to the connectors that go beyond the board. It is necessary, in this case, to take measures - either use special integral protection components, or provide a suppressor, a 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, the device I designed (satellite modem), with elements of the simplest port protection of the microcontroller. X4 - connector for external communications. We are interested in contacts 5-7, which are connected alarm buttons. An alarm signal is a ground fault, therefore, in the normal state, the ports must have a microcontroller supply voltage, which is provided by the resistors R24-R26, 1 KΩ nominal. Suppressors VD4-VD6 limit the voltage at 5 volts, this is acceptable because the microcontroller I use, although powered by 3.3 volts, has ports that are 5 volt tolerant. R29-R31 resistors per 100 ohms.
Such protection will save the ports of your microcontroller from external overvoltages. In some microcontrollers, individual ports are not afraid of voltages that exceed their supply voltage. So for many STM32Fxx microcontrollers, almost all ports being configured as digital can work with 5 volt circuits, but if they work in analog mode, for example, as an ADC input, they lose this ability and this must be taken into account when developing a circuit.

Please observe safety precautions. Do not leave microcontroller ports that are free, hanging in the air, configured as inputs, especially in devices that sometimes go into deep sleep - this at least can significantly complicate the process of your EMC (Electromagnetic Compatibility) test. If you leave them as inputs, it is better to close them to the ground or power. Or programmatically configure the outputs.

There is another life hack. Sometimes they can leave the entrance and closed on another circuit. This helps in the case of very dense tracing to conduct a conductor "through" the microcontroller, which is especially important for dual layer boards.

Using the ports of microcontrollers as outputs, also worth checking with datasheet. Individual ports may have different limits on the maximum current that can be obtained from them without fear of breaking them down - load capacity. In addition, the chip itself has a maximum load capacity of all outputs in an amount that should not be exceeded.
The last thing I want to mention, the output ports of ARM microcontrollers do not respond to software instructions instantly, like in 8-bit microcontrollers. They are controlled via the bus, and their speed depends on the clocking frequency of the corresponding node, which can be changed programmatically. If you want a quick response, take care to increase this frequency, if it is more important to reduce power consumption, on the contrary, choose a lower speed mode.

Temperature sensor The microcontroller has its own temperature sensor, though not very accurate, but it can, with certain assumptions, be used to measure the temperature inside the device.

Unique serial number Each microcontroller has its own unique serial number assigned to it in production. A very convenient feature that can be used in the organization of mass production of your products.

Communication Interfaces Various microcontrollers in this series can have several of the most common interfaces that greatly facilitate communication with other chips and the outside world:


All these interfaces are easy to implement programmatically using regular GPIOs, but they will work much slower and take up a lot of compute core resources.

Analog-to-digital converter ADC or ADC which will have to stop in more detail.

An extremely useful module that can measure the voltage of analog signals. He evaluates them in fractions of the magnitude of the reference signal source, in our case it is the supply voltage of the analog module of the microcontroller, which may be equal to or slightly lower than the main supply voltage of the chip. The theoretical accuracy of the ADC depends on its bit depth. In modern microcontrollers, a 12-bit sequential approximation ADC is most often used, less frequently 10, and as exotics occurs 16.



When powered by 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 far from being so beautiful and the measurement accuracy may decrease for many reasons. Below I list the main, well known to any experienced electronics engineer, as well as simple but effective ways to reduce their detrimental effect to a minimum
voltage instability of the ADC power supply.

  • use linear stabilizers with good parameters to power the MCU
  • use high-stable voltage sources to power the analog part of the MCU

impulse power interference ADC

  • — MCU XR7 100 , , — .



  • , . NP0 , ,
  • , , , ,
  • “”, —

, , , , , .

  • , , ,
  • ( ), . , , , . ,



. MEMS , . , , .

VBUT . : R5-10 , 10 0.1 , L1 L2 BLM18PG471SN1D .



. , ASIC, . — . , , . « ».

, . , , , , . 1, 16. ? , . 10 , — 10 . , . , , 1 . , 10 10 !

The system of direct access to the memory of the PDP or DMA is another important thing. This module allows you to send data from the periphery to memory or vice versa.

For example, with its help you can allocate a section of memory for storing data coming from an ADC and make it a ring buffer. Next, the ADC is started in the data reading mode at regular intervals. Using DMA mechanisms, the read data will, without the participation of the kernel, independently, byte by byte, be placed in a dedicated buffer. When the buffer is full, the kernel will receive a signal and begin to program them, and the DMA system will start the boot process first. Since DMA has several channels, no one bothers to implement for our case automatic output to USART data from the buffer. As a result, we will get the process of transferring read from ADC to USART without using the kernel, and not a simple DMA programmer’s job will pay off.

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 speed of rotation of engines, steering gears, design intelligent DC -DC converters and even sound to synthesize.

What can you get by adding 30 cents?

Switch to Cortex-M0 +. The cheapest way to get extra features.


And what additional buns does the microcontroller of the newest series with the core offer a bit more modern than the Cortex-M0 +, at a cost of 20-50 cents more expensive than its counterparts in the above series in terms of body and number of outputs?

Table of differences between series




Well, for many applications, a minor addition to the price itself pays for itself, since it is possible to refuse to switch to more expensive microcontrollers of the older model series.

Cortex-M4, ?





Cortex-M7 - when you want more ...




In the overwhelming number of projects, the opportunities provided by the kernels described above are sufficient, but exceptions also occur. 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 the ASIC, an Ethernet controller and a CAN-FD bus with increased exchange speed.

If at the level of universal microcontrollers with Cortex 4 cores and below, in my subjective opinion, ST is now leading in terms of price / functionality, then in the field of more high-performance chips it is inferior to ATMEL, or rather, to the recently swallowed MICROCHIP. Therefore, I opted for the ATSAMV71 series, starting at $ 6.

In addition to the above (Ethernet controller and CAN-FD bus), by and large, we get a significantly increasing performance core with an operation accelerator operating at a clock frequency of up to 300 MHz, interfaces for connecting the video matrix and support for dynamic memory.

In conclusion, I will ask those who have experience in communicating with microcontrollers and ask them to choose the appropriate answer to the question.

Source: https://habr.com/ru/post/445936/


All Articles