CMSIS files from ARM provides ARM Math functions. There are also PID controller functions in different formats for f32, q31 and q7. This tutorial/project will talk about how to implement PID controller on STM32F4xx using PID functions from ARM.
Fast about PID controller. PID stands for Proportional-Integral-Derivative controller. This is a control loop feedback mechanism widely used in industrial control systems. It calculates the error between measured value and the desired setpoint value. According to the error, it then calculates output value to minimize this error.
After first FFT project, I’ve decided to make a simple snake game. Basically I’ve made it in Labview first for my partial exam at the university. It looked great so why not port it also to STM32F429-Discovery board which has everything already prepared for us.
You just need USB OTG cable and external keyboard to drive keyboard and you are ready to work.
Works on STM32F429-Discovery board
Supports external keyboard using USB HID Host stack on STM32
Supports selecting different speeds
More speed, more points
Standard snake game mode
Your goal is to make snake larger as possible
Supports 2 game modes
Mode 0: If you hit wall, game is stopped
Mode 1: If you hit wall, snake will come out at the other side of game area
MPU-6050 is a 3-axes accelerometer and 3-axes gyroscope MEMS sensor in one piece. It can also measure temperature. It is very cheap device but also very powerful. It can measure simultaneously three (X, Y and Z) channels for accelerometer and gyroscope at the same time with 16-bit resolution. This chip is also compatible with MPU9150, except that MPU9150 has 3axes magnetometer (or compass) included.
4 selectable full scales (2G, 4G, 8G and 16G)
4 selectable full scales (250°, 500°, 1000° and 2000°)
Selectable LSB bit for I2C address, used with AD0 pin
AD0 low: I2C address is 0xD0
AD0 high: I2C address is 0xD2
Max SCL speed is 400kHz
Read accelerometer data
Read gyroscope data
Read everything above in one single function or separatelly
Use 2 independent MPU-6050 devices on the same I2C bus
Library 42 allows you to simple connect and interface RC servo motors with STM32F4. They are small, cheap motors, commonly used for RC (Radio Control), small scale robotics and more.
Servos are really simple to interface. They expect 50Hz signal on the input. According to the pulse length (duty cycle) they rotate between 0 and 180 degrees. If signal has 1ms pulse length, motor rotation will be 0 degrees and if signal has 2ms length, then it will have 180degrees rotation. Any pulse length between will set degrees linear to the value.
Equation for pulse length to get specific rotation is:
As you maybe know, STM32F4 is Cortex M4 with DSP instructions. This allows you to make a FFT with a few simple steps. For that purpose, I have made an example, on how to create FFT with STM32F4.
When the ARM company issued Cortex-M4 core, it also published DSP libraries for mathematics and other stuff. And there are also FFT functions. When you’ve downloaded ST’s standard peripheral drivers, you also downloaded CMSIS (Cortex Microcontroller Software Interface Standard), which are designed for all Cortex-M4 processors from every company.
Note: Tutorial below for Keil DSP does not work anymore with my project. For that purpose I’ve update my project and include all DSP libraries inside. All other libraries are also included in project.
CMSIS libraries are also included in Keil uVision (5 and newest), you just need to enable them. Under “Manager Run-Time Environment” -> CMSIS select DSP. DSP or Digital Signal Processing is a library for “high mathematics” instructions, which are supported by Cortex-M4 with floating point unit.
Enable DSP library in Keil uVision
Fast Fourier Transform – FFT
Very fast about FFT. FFT or Fast Fourier Transform is an algorithm to convert time based signal into frequency domain. In other words, you are able to know from which sinus components is some signal created.