cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing PWM Signal with External Signal using STM32 - Algorithm for Drifting Correction

trainyinfi
Associate

I am working on a project where I need to synchronize a PWM signal generated by an STM32 microcontroller with an external signal. To achieve accurate synchronization, I believe I need to implement a drifting correction algorithm. I am seeking guidance on how to achieve this with the STM32 microcontroller. Can anyone suggest an algorithm or approach to achieve this synchronization and drifting correction effectively?

 Anyone have any code examples or code snippets that demonstrate synchronization with an external signal and drifting correction using the STM32 microcontroller?  Are there any open-source libraries or resources available that can help me achieve this synchronization?

Thank you for your help and guidance in advance! I appreciate any insights or experiences you can share to assist me in accomplishing this synchronization and drifting correction task with the STM32 microcontroller.

2 REPLIES 2

Which STM32, they make a handful at this point.

If yours has a 32-bit TIM you could perhaps time-stamp the events from a free running TIM. Say latching the edges of external events, and those of internally wireable connections or associativity, or externally looped. Check the Reference Manual for you part for an understanding of functionality / connectivity options and sources.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

You could tie the timer reset channel to the external signal and use that to reset the timer. That will keep you aligned.

You could use a free running timer in IC mode to capture the duration between edges and update your timer appropriately.

The best/optimal method will depend on the frequency of the outgoing PWM signal and the incoming sync signal.

If you feel a post has answered your question, please click "Accept as Solution".