STM32 Algorithms

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
xuraax
Posts: 2
Joined: Thu Jan 09, 2025 6:33 am

STM32 Algorithms

Post by xuraax »

I am not certain this is the right forum for posing the following enquiry. If not I apologize.
ShaftSignal1.jpg
ShaftSignal1.jpg (86.08 KiB) Viewed 332 times
The above is the cleaned up signal output from a sensor monitoring the angular position of a shaft. It is made up of 23 pulses plus one gap. I need to pick up ideally the centre of that gap using any option possible on an STM32 controller.

The pulse widths in that photo are dependent on shaft rotation speed which can easily go up to x2 or even x3 the speed of when that picture was taken.

I would be grateful for any suggestions on how to achieve this.

Alternatively if one can suggest alternative forums where this type of issues are discussed I would be grateful too.

regards
GonzoG
Posts: 502
Joined: Wed Jan 15, 2020 11:30 am
Answers: 36
Location: Prudnik, Poland

Re: STM32 Algorithms

Post by GonzoG »

Wrong subforum - you're asking about STM32 and posted in STM8.

This won't be done automatically by MCU (with one or a few simple commands).
First you need to measure length of pulses or time between them and by comparing them find the gap to get your program synchronized. Then you can count pulses to find gap, measure it's time and calculate center.
It can be done using interrupts, but interrupts need additional time to execute, or directly in main thread.

I think using hardware timers is the best option:
https://github.com/stm32duino/Arduino_C ... er-library
xuraax
Posts: 2
Joined: Thu Jan 09, 2025 6:33 am

Re: STM32 Algorithms

Post by xuraax »

OOPS!!!! Sorry.

Did not realise I was in the wrong subforum.

Can the administrator shift it to the right subforum or should I restart it there?

On the use of timers. I have thought long and hard on how to use those but given the fact that the pulse widths will vary unpredictably and by a large amount I have yet to think up a way to achieve my target.

By the way, for a bit more information, That shaft is actually the crank shaft of a motor cycle and the gap indicates the point when the piston has arrived at top dead centre (TDC). That pulse train was recorded at 1,700rpm and the engine can rev up to above 10,000rpm.
Post Reply

Return to “General discussion”