14 Common Algorithms in Microcontroller Development

You can click the blue text to follow, reply ‘entry materials‘ to get a comprehensive tutorial from beginner to advanced on microcontrollers

The development board will take you into the field, we will help you fly

Written by | Wuji (WeChat: 2777492857)

The full text is about1906 words, reading takes about 10 minutes

When I was in school, I was addicted to many years of legendary games, from the original version to SF, from a potential academic elite to a complete academic failure.

Sometimes, I couldn’t even tell whether I was better at humanities or sciences.

If I say I am good at science, my grades in science are poor; if I say I am good at humanities, I end up doing scientific work after graduation.

When I first started learning microcontroller development, I was troubled by a question for a long time: can I learn it if my English and math are poor?

Later, when I was really at a dead end, I gritted my teeth and learned it. After several years, I realized that poor English and math were not the threshold for learning programming, but rather the ceiling.

The height of the technical ceiling doesn’t matter; what’s enough is good enough, because one day you will find that 99% of the problems are not technical issues.

There is a contradictory issue: when we develop products with microcontrollers, we will inevitably involve some algorithms. So why do I think that having a poor mathematical foundation does not affect development?

For example, in the special training camp project of our Wuji, when doing some functions, we will use some small algorithms such as wireless communication soft decoding, lithium battery power detection, CRC, MD5, firmware upgrade, etc.

There are two points:

First, many algorithms are readily available online and can be modified.

Second, no matter how complex the algorithm is, in the program, it ultimately involves addition, subtraction, multiplication, division, left shift, and right shift operations. Even if you don’t understand the algorithm, you can pay someone good at math to provide you with an addition and subtraction formula based on your requirements; you just need to implement this calculation with code.

Below are some commonly used types of algorithms in microcontroller development.

1. Basic Mathematical Operations Algorithms

Such as addition, subtraction, multiplication, division, summation, averaging, finding maximum/minimum values, and other simple mathematical operations, which are the basics of algorithms and are often used in data processing and calculations.

2. Sorting Algorithms

Such as bubble sort, selection sort, insertion sort, etc., used to arrange data in ascending or descending order.

3. Filtering Algorithms

Such as mean filtering, median filtering, Kalman filtering, etc., generally used for secondary processing of signals collected by ADC, using software algorithms to filter noise from signals and restore data close to the real value.

4. Searching Algorithms

Including linear search and binary search, used to quickly locate specific elements in a data set.

5. String Processing Algorithms

Involves operations such as comparing, copying, concatenating, searching, and replacing strings. These algorithms are also used in microcontrollers, such as screen display, JSON, and command data processing for IoT modules.

6. Control Algorithms

Such as PID algorithms, which are widely used in industrial control systems. Their main function is to quickly and accurately reach and maintain desired target values for temperature, speed, position, etc.

The PID algorithm acts like an intelligent regulator that automatically adjusts the control quantity based on the difference between the current state of the system and the target state, thus stabilizing the system’s operation at the desired state.

For example, in a constant temperature system, the PID controller adjusts the power of the heater based on the difference between the current temperature and the set temperature to maintain the desired temperature.

In robot navigation, the PID controller can adjust the robot’s direction and speed to ensure it travels along the predetermined path.

7. Data Processing Algorithms

Including data collection, conversion, encoding, decoding, etc. The wireless soft decoding and OTA firmware upgrades in our Wuji microcontroller project involve such algorithms, which are often used in data communication and storage.

14 Common Algorithms in Microcontroller Development

14 Common Algorithms in Microcontroller Development

8. Encryption and Decryption Algorithms

Such as AES, DES, etc., used to ensure data security and prevent unauthorized access and tampering. Generally, there are ready-made solutions available on the market.

9. Data Verification Algorithms

Such as CRC, checksum, XOR check, which are commonly used in serial communication applications.

10. Mathematical Function Algorithms

Such as trigonometric functions, logarithms, exponentials, square roots, etc., which are very useful in solving complex mathematical problems, although in the applications I have encountered, they are relatively rare.

11. Graphics Processing Algorithms

In microcontroller applications that require displaying or processing images, algorithms such as dot matrix display, graphic transformations, and color processing may be used, especially in dot matrix screens and TFT screens. These algorithms are generally designed based on the actual graphics or screen sizes.

12. State Machine Algorithms

This is part of the program architecture, used for state transitions and event handling in complex projects, such as the OSAL system of the TI Bluetooth protocol stack.

13. Search Algorithms

Such as Depth-First Search (DFS), Breadth-First Search (BFS), etc., used to search for specific nodes or paths in graph or tree structures, which are used when implementing queues with linked lists.

14. Optimization Algorithms

Such as genetic algorithms, simulated annealing algorithms, etc., used to find the optimal or near-optimal solutions to problems. For example, genetic algorithms are often used for robot path planning to find the optimal movement path while avoiding obstacles. Those who have worked on simple robot cars should be familiar with this.

Seeing so many algorithms, doesn’t it feel overwhelming?

Don’t worry, I have already sorted out the commonly used ones for you; you can contact me for arrangements, no tricks involved. Store them up, and when you need them next time, just copy and paste, it’s super easy.

14 Common Algorithms in Microcontroller Development

14 Common Algorithms in Microcontroller Development

Finally, a reminder: not all products require algorithms. Just learn them when you need them, and many are readily available; you don’t have to write everything from scratch.

Before I knew it, I had already written for 3 hours (what I mean is, you can give a thumbs up if you appreciate it ^ ^!).

end

14 Common Algorithms in Microcontroller Development

Below are more original works from Wuji regarding personal growth experiences, industry experiences, and technical insights.

1.What is the growth path of an electronic engineer? 10 years in 5000 words summary

2.How to quickly understand other people’s code and thinking

3.How to manage too many global variables in microcontroller projects?

4.Why do most C language microcontroller developments use global variables??

5.How to achieve modular programming in microcontrollers? The practicality is astonishing!

6.Detailed explanation of the use and practical effects of callback functions in C language

7.Step-by-step guide to implementing queue code in C language, easy to understand and super detailed!

8.Detailed explanation of pointer usage in C language, easy to understand and super detailed!

Leave a Comment

×