cancel
Showing results for 
Search instead for 
Did you mean: 

STM32FO30R8T6 TIM1

ali23
Associate
Posted on August 22, 2016 at 16:25

Hi,

i have a question about Timer1 of the �C mentioned above.

I want to use the Timer1 for a SW-Timer with second-resolution.

I have the idea, to start the timer with a frequency of 1 KHz and use the Auto-repition-Counter to Keep times with second-Resolution.

Does anybody have a Startup or initialization-code to start the tim1 with 1 KHz frequency and to configure the Auto-Repition-Counter of Timer1 Count with a frequency of 1 Hz?

Thanks

in advance for any useful support and please excuse my bad English.

#tim1 #timer
4 REPLIES 4
Posted on August 22, 2016 at 16:46

The repetition counter is only 8-bit, so isn't going to handle 1000, but could handle 250

Most people use SysTick for a 1KHz (1ms) ticker.

To use TIM1 to do 1Hz (1second) you'd select the Prescaler (16-bit) and Period to divide down the MHz the timer is running at.

If the TIMCLK is 48MHz, that's like 48000 x 1000, so

Prescaler = 48000 - 1; // Encoded as N-1, so [0 .. N-1] has N states

Period = 1000 - 1;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ali23
Associate
Posted on August 22, 2016 at 18:26

Thanks for the answer. But then Timer is still counting with 1 KHz when you are Setting the prescaler to 47999, thats ok.

But how can I start the TIM1 with any other functions then just counting up and then increment the auto-repition counter every second, I know that the autoreload-value has to be like 999.

It's ok that the repition counter is just 8 bit width. That's good enough.

An init-code would be nice, compatible with the newest HAL-Drivers of STMCubeF0

Posted on August 22, 2016 at 19:35

Sorry, no HAL code from me

The timer will clock at 1KHz, the Update will occur at 1Hz. If you set the repetition count to 60-1 you'd get an interrupt once per minute, but as far as I recall you can't see which second the repeat is counting by looking at the TIM registers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Walid FTITI_O
Senior II
Posted on August 25, 2016 at 12:43

Hi Mr. µCells,

I recommend to get a look to ''TIM_TimeBase'' example in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef0.html

at this path STM32Cube_FW_F0_V1.60\Projects\STM32072B_EVAL\Examples\TIM\TIM_TimeBase

For your case to get 1Hz frequency you just consider Prescaler and period as follow:

/* set the Timer prescaler to get 1MHz as counter clock */
Tim1Prescaler= (uint16_t) (SystemCoreClock / 1000000) - 1; 
/* Initialize the PWM period to get 1Hz as frequency from 1MHz */
Period = 1000000 / 1; 
/* Configure the Timer prescaler */
TIM1->PSC = Tim1Prescaler;
/* Configure the period */
TIM1->ARR = Period-1;

You can aslo use

http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html

tool to generate correctly your initialization code and start you project development.

For other Timer related information you can check the new Timer cookbook application note

http://www.st.com/content/ccc/resource/technical/document/application_note/group0/91/01/84/3f/7c/67/41/3f/DM00236305/files/DM00236pdf/jcr:content/translations/en.DM00236pdf

-Hannibal-