STM32
- 1.1 Software
- 1.1.1 MCU config tool
- 1.1.2 IDE
- 1.1.3 STM32CubeProgrammer
- 1.1.4 Input capture with timers
- 1.1.5 SPI
- 1.1.5.1 Wheel encoder
- 1.1.5.1.1 Example
- 1.1.5.1 Wheel encoder
- 1.2 Hardware
- 1.1 Software
- 2 Version 1.0
Software
MCU config tool
STM32CubeMX - STMicroelectronics
IDE
STM32CubeIDE - STMicroelectronics
STM32CubeProgrammer
STM32CubeProg - STMicroelectronics
Input capture with timers
Code example: https://controllerstech.com/input-capture-in-stm32/
SPI
HAL doc:
good overviews:
https://deepbluembedded.com/stm32-spi-tutorial/
https://deepbluembedded.com/how-to-receive-spi-with-stm32-dma-interrupt/
Wheel encoder
The STM32 is setup with four timers and four input capture interrupts, one for each wheel. Each timer is free running and with each interrupt we store the current counter. When we have encountered two falling edges or two interrupt events on one channel we can calculate the difference in time and get the current rotational speed.
The system clock is at 2.097MHz, the timers have a clock divider of 16 which means each count is 7,629947544us.
2.097MHz/16 = 131,0625kHz
We have a 16bit counter → 65536
1/131,0625kHz * 65536 = ~0.5 or 2Hz would be the lowest speed we could capture.
The difference is stored in a 16 bit value which then is divided by two and stored in a 8 byte arrary. The difference is the raw count value (0 → 65536 ) of the timer so the conversion to Hz or RPM need to be done elsewhere.
Front Right B[0]: MSB B[1]:LSB
Front Left B[2]: MSB B[3]:LSB
Back Right B[4]: MSB B[5]:LSB
Back Left B[6]: MSB B[7]:LSB
To get the value from the STM32 simply clock out 8x8 clock pulses. It dose not matter if there is data on the MOSI line.
Example
Front_right = (dataIn[0]<<8) + dataIn[1];
Front_right = (1 / (Front_right * 0.000007629948)) / 2; // 1/(count * sec/count) we have two magnets per wheel so divide everything by 2 and you get Hz
Hardware
reference design: https://www.st.com/resource/en/user_manual/um1956-stm32-nucleo32-boards-mb1180-stmicroelectronics.pdf
Crystal load capasitance
Pinout
page 37 for pin description: https://www.st.com/content/ccc/resource/technical/document/datasheet/42/c0/ab/e5/71/7a/47/0b/DM00206508.pdf/files/DM00206508.pdf/jcr:content/translations/en.DM00206508.pdf
Footprint
Version 1.0