cancel
Showing results for 
Search instead for 
Did you mean: 

Timer value calculation

mayakk12
Associate II
Posted on February 25, 2012 at 10:34

hi,

I am using STM32VL board.. In my application i am reading voltage for every 6.25micro sec. so i'm using timer TIM2 in interupt mode for that. can any one tell me what value i need to set fro prescaler and period.

Sys clock is 24Mhz and ADC clock is 12 MZ.

thanks a lot in advance

#timer-value
18 REPLIES 18
Posted on December 27, 2013 at 15:05

It depends on the TIM unit, which APB bus it's on, and what APB dividers are being used.

For the typical 168 MHz system APB2 is at DIV2, and it's TIMCLKs at DIV1 (168 MHz), and APB1 is at DIV4 and it's TIMCLKs at DIV2 (84 MHz)

These setting usually appear in system_stm32f4xx.c, along with the PLL settings. To run the processor at 128 MHz instead of 168 MHz you'd want to change PLL_N from 336 to 256, and adjust other related constants to match the new speed, ie SystemCoreClock

At the sample rate in question I'd probably not use an interrupt, but rather use the TIM to drive the ADC, and in turn the DMA

An F1 example about 3/5 down, not directly applicable to the F4

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Reading%20voltage%20-ADC&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=2527

A dual F4 example about 1/4 down,

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/ADC%20in%20Dual%20Mode%20Simultaneously&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=39...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on January 03, 2014 at 09:58

sanjib
Associate III
Posted on January 03, 2014 at 14:33

Posted on January 14, 2014 at 15:50

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6mv&d=%2Fa%2F0X0000000bvS%2FfWnfhVEsHdscddFOAUFU2Xmnx8GbaZUf171KQDZ2h8c&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on December 30, 2013 at 06:43

Posted on December 30, 2013 at 07:09

I have tried with using the system clock's internal oscillator which  is 16Mhz and APB1 prescalar as 1 which gives me tim2 also 16Mhz. It is giving me the interrupt after every 1 second as  have checked with CRO after setting the prescalr value to 16000 and timer count to 1000. but why it is giving me 9 us interrupt when I am setting the prescalar to 0 and timer count to 25. It should give me 1.5625 us

Having the processor interrupt every 25 cycles, is perhaps, somewhat ill-conceived? Try having the hardware do the heavy lifting, and interrupt less frequently.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on December 31, 2013 at 10:25

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6nY&d=%2Fa%2F0X0000000bvh%2FZ9WnW3SknqqkshOVp.wHlu1bKgkkA56jSrhKpOUW9HM&asPdf=false
sanjib
Associate III
Posted on December 31, 2013 at 10:30

 the prescalar value is 2 and the timer count is 50. The sys clk is 128000000 and the tim2 frequency is 64000000

Posted on December 31, 2013 at 15:19

I really don't want to get dragged into doing your job here.

161 MHz? 160 KHz

Your choice of channels is neither configured correctly, or addresses availability of resources on the STM32F4-Discovery board.

How do you think sending dozens of characters at 9600 baud (say 960 chars per second) is remotely enough for the speed at which you are taking samples?

I don't think I'd be sequencing the samples in this fashion, and would probably use DMA+TIM.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..