M
M
Mark Chigrin2020-11-09 20:02:07
Microcontrollers
Mark Chigrin, 2020-11-09 20:02:07

How to properly design an application for a microcontroller?

Problem I am solving:

There are sensors that need to be polled every 25 ms, cached and sent to the server in case of a network. I would also like to add keystroke processing - to reset the settings.

I'm going to take the ESP-32 as a basis . I would like to write in Micropython , but not necessarily.

As far as I understand, this should be done using a cycle (event-loop'a) with tasks. (for micropython there is uasyncio)
But how to exit the sending task correctly in order to read the data - I have a bad idea (or sending one eth (or tcp packet?) frame will be less than 25 ms and most likely I will have time to return from the task?)

Recommend literature /sites about how to write for microcontrollers correctly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor P., 2020-11-10
@Jeer

A lot of different topics in one question. You start doing and more specific questions will appear.
How to design:
Take a sheet of paper, write down all your Wishlist line by line, prioritize and complete tasks in turn.
What does cycle with tasks mean? In the most primitive case, you usually have some kind of cycle in your microcontroller, and use it. The tasks of polling sensors or sending data are wrapped in separate functions, and these functions are simply called in a loop.
About "every 25 ms". The cycle is simple, it works endlessly and without stopping. But in some line there is a suspension of the program. That is, the loop does not start every 25 ms, but the loop pauses for 25 ms.

A
Alexey Artyushkov, 2020-11-12
@frank_sider

Look at the iterator and command design patterns - for your task they will go like clockwork. And the architecture is very simple: each sensor will be a structure object with one single element - a pointer to the function of measuring and writing the measurement results to the ethernet packet. Thus, you can support completely different types of sensors (analog with ADC measurement and digital with I2C, SPI, UART and etc. interfaces). In your code, you can implement any bypass and packet formation algorithm (the order of bypassing the sensors will depend on the packet structure). As soon as the packet is formed, you immediately send it to the controller for sending (you can do it through buffering and interrupts, or you wait until the controller sends the previous packet, but in general the best way to send it is via DMA). Sending in the third way takes a few nanoseconds, and the hardware will take care of the rest of the work. In the second case - a little longer, in the first - at a speed of 10 Mbps 150 µs, at a speed of 100 Mbps 15 µs, at a speed of 1 Gbps - 1.5 µs.
On the button, everything is also quite simple here - you start an external interrupt and do what the button should do. Or you can use a command patter and you can buffer operations from an entire dashboard.
PS Imkho to write under microcontrollers on python is not the best idea. It is much easier in pure C, since you have access to all the features of hardware and you are not limited to language and libraries.
PPS Writing programs for microcontrollers is practically no different from writing programs for ordinary computers - it will code in Africa too. The difference is that on the microcontroller you will have to work directly with the hardware and understand how it works and understand the physics of the communication interfaces. And sites - the benefit of them in bulk: easyelecronics, microsin, osdev. In short google to the rescue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question