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 February 25, 2012 at 14:50

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.

Some basic math involved, 6.25 us is 160 KHz, TIMCLK is 24 MHz

24,000,000 / 160,000 = 150;

Prescale = 0; // ie 1 - 1, no division

Period = 150 - 1;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mayakk12
Associate II
Posted on February 27, 2012 at 11:31

hi,

Thanks a lot for ur help.

can you tell me why subtraction is required there..??

mayakk12
Associate II
Posted on February 27, 2012 at 11:34

hi ..

thanks a lot for the help..

can u tell me why subtration is required there?

Posted on February 27, 2012 at 14:02

can u tell me why subtration is required there?

 

The value is the final count, zero based, thus a divide by N is achieved by programming a value of N-1 into the period. Please refer to part documentation for more details.

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 26, 2013 at 07:49

Can anyone tell me how to generate an interrupt of 1.5625 microsecond. I am using Timer 2 . Timer frequency is 84000000. what is the value I should set in ARR and prescalar. Please help me

sanjib
Associate III
Posted on December 26, 2013 at 08:25

Posted on December 26, 2013 at 13:12

1.5625 microsecond = 640 KHz, seems a bit high for an interrupt rate. If you are looking to generate a pin output, connect the timer directly, and don't use interrupts, or consider more carefully what it is you're trying to do.

84,000,000 / 640,000 = 132.25

That's non-integer, so either you'll have to tolerate the frequency being off slightly, or run the CPU at a speed that is cleanly divisible (ie 128 MHz, or whatever)

Prescaler = 0;

Period = 132 - 1;
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 27, 2013 at 07:41

Thanks for the reply. My task is to read the adc channels after 1.5625 microsecond this is the requirement. Input frequency is 160 khz. if we set the vale to 131 we get 1.571428571 us. which is not my requirement. therfore can you explain me briefly so that I can considered my requirement as I am new to stm32 controller.

Thanks in Advance
sanjib
Associate III
Posted on December 27, 2013 at 07:49

how to set the sysclk to 128000000 as 128000000/200 = 640 khz. but I have a doubt that timer frequency is 84 mhz or the maximum is 168 Mhz . So can we set it to 128000000. if yes please say me how to do this. I will be greatful to you as i have no idea and I am new to stm32f4