/
STM32

STM32

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/

https://www.st.com/content/ccc/resource/training/technical/product_training/group0/3e/ee/cd/b7/84/4b/45/ee/STM32F7_Peripheral_SPI/files/STM32F7_Peripheral_SPI.pdf/_jcr_content/translations/en.STM32F7_Peripheral_SPI.pdf

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

Guidelines: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwj0qp_xh8_1AhVOKBoKHYoyAdoQFnoECBUQAQ&url=https%3A%2F%2Fwww.st.com%2Fresource%2Fen%2Fapplication_note%2Fdm00112257-getting-started-with-stm32l0xx-hardware-development-stmicroelectronics.pdf&usg=AOvVaw37RwynR9X34bcA7xiW6fb1

 

Crystal load capasitance

 

image-20240516-134831.png

 

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

 

 

 

Related content

Project roadmap
Project roadmap
Read with this
Wheel encoder
Wheel encoder
More like this
ESP32
ESP32
Read with this
VESC - Vedder's Electronic Speed Controller
VESC - Vedder's Electronic Speed Controller
More like this
STM32 Nucleo-32
STM32 Nucleo-32
Read with this