cancel
Showing results for 
Search instead for 
Did you mean: 

How to clock while loop STM32F4

epalaima
Associate II
Posted on July 01, 2016 at 19:28

Hi, I was wondering how I would go about setting up timing/clocking for the while(1) loop in the main of my program. I would like to set it up to be synchronized with the sample rate of the ADC, as right now the two do not seem to be related. I am using the STM32F4 with the built in ADC.

#clock #loop-timing
5 REPLIES 5
Posted on July 01, 2016 at 20:40

The point of doing that would be what, exactly?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
epalaima
Associate II
Posted on July 04, 2016 at 01:00

I am trying to use the STM32 for audio applications, the end goal being to create a dsp effects unit. I'd like to be able to set up a sample rate for the output instead of it being based on however long the code within the while(1) loop takes to execute, which would change based on what kind of processing it is doing. 

The main thing I need out of a sample rate is the ability to set up precise delay times, where the number of samples in a delay has a stable relationship to an amount of time. I also need to control the sample rate to prevent memory issues in this application, since if the while loop is running very fast my sampled delay buffer will fill up very quickly and I will not be able to achieve longer delay times. 

This is my first experience programming microcontrollers, in the past I have mainly worked in a computer environment. Sample rate is always one of the first things that gets set up in my experience with audio programming. Is there a reason that wouldn't apply when using a microcontroller?

Posted on July 04, 2016 at 04:20

Sample rate is always one of the first things that gets set up in my experience with audio programming. Is there a reason that wouldn't apply when using a microcontroller?

Yes, it important in embedded too, but you don't do it counting cycles in a while(1) loop. You'd program a time base via a timer which triggers the ADC to do the conversion at the desired periodicity.  With the STM32, doing multiple channels, TIM+ADC+DMA

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/Internal%20Clocking%20and%20Sample%20Rate%20on%20STM32F4%20ADC&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/AllItems.aspx&currentviews=9]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM32Discovery%2fInternal%20Clocking%20and%20Sample%20Rate%20on%20STM32F4%20ADC&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https%3A%2F%2Fmy%2Est%2Ecom%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FAllItems%2Easpx¤tviews=9

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
epalaima
Associate II
Posted on July 05, 2016 at 16:25

That makes sense. How do I set up a timer? Is there any documentation or examples you can point me to?

Posted on July 05, 2016 at 18:33

There are code examples in the SPL and HAL libraries, and I've posted literally dozens of examples to the forum. Avail yourself of Google, Bing, etc.

The Reference Manual documents the technical connectivity and function of the part, it's what I use to understand how it works.

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/stm32f207%20ADC%2BTIMER%2BDMA%20%20Poor%20Peripheral%20Library%20Examples&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=6018]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2Fstm32f207%20ADC%2BTIMER%2BDMA%20%20Poor%20Peripheral%20Library%20Examples&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=6018

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