cancel
Showing results for 
Search instead for 
Did you mean: 

Not desidered auto-reload TIM2

dario
Associate II
Posted on June 06, 2013 at 00:02

Hi,

i'm angry with this simple code.

I need that the timer2 goes from TIM2_ARR to zero and stay zero until a Update EVent is manually generated (with UG from TIM2_EGR of course).

But unfortunately TIM2 seems to reset at every underflow also if UDIS of TIM2_CR1 it's set!

I hope someone can hel me with this simple problem

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

&sharpinclude <stm32f4xx_rcc.h>

&sharpinclude <stm32f4xx_tim.h>

&sharpinclude <stm32f4xx.h>

int state = 0;

int main(void)

{

//

    //  Initialize the peripheral clock.

    //

    RCC->APB1ENR |= RCC_APB1Periph_TIM2;

    //

    // Configure TIM2

    //

    TIM2->PSC = 0xffff;

    TIM2->ARR = 2500;

    TIM2->CR1 |= 0b10 << 8; // CKD

    TIM2->CR1 |= 0b1 << 7; // ARPE

    TIM2->CR1 |= 0b1 << 4; // DIR

    TIM2->CR1 |= 0b1 << 1; //UDIS

    TIM2->CR1 |= 0b1; //CEN

    TIM2->CCR1 = 0xffffffff;

    TIM2->CCR2 = 0xffffffff;

    TIM2->CCR3 = 0xffffffff;

    TIM2->CCR4 = 0xffffffff;

    TIM2->SR &= 0xfffe;

    TIM2->EGR = 0b0;

    while(1)

    {

    state = TIM2->CNT;

    }

}

#update-disable"-"auto-reload" #reload-timer #anyone?"
8 REPLIES 8
Posted on June 06, 2013 at 01:35

i'm angry with this simple code.

The joys of register level code. You should perhaps be using the One Pulse Mode of the timer?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 06, 2013 at 09:10

Clive,

How does ''register level programming'' relate to misunderstanding of function of UDIS flag (and exact meaning of ''update event'' in context of STM32F' timers), and how does the use of the so called ''peripheral drivers library'' replace or amend the grossly inadequate description of the timers' function given in the user manuals and other available materials?

Jan

zzdz2
Associate II
Posted on June 06, 2013 at 09:58

Jan,

there's no accounting for taste. You and I prefer direct register access, others may prefer ''library''.

By surprise, direct access usually results in shorter, cleaner code, OTOH using library can be safer, especially for beginners.

No way to tell which one is better.

dario
Associate II
Posted on June 06, 2013 at 10:44

Yes, i'm a beginner!

For these simple command i prefer to set/reset registers because

1) read the reference manual

2) find the register

3) try to understand how it change the behavior of the micro

4) write the code

Using libraries it's for me very confusing because i don't know where to search the right info.

And i onestly think that they're more confusing than helpful at this time.

Do you suggest to use the library instead?

However...

I already bypassed the problem using OPM (altough opm stops AFTER auto-reload and in CNT register there's the value of ARR register, but it's not a big problem).

But i was inquiring. Why this code doesn't do what i want?

Is the code wrong?

UDIS does not avoid underflow update event?

And if so, why the counter auto-reload?

Thank you for your reply
zzdz2
Associate II
Posted on June 06, 2013 at 11:56

But i was inquiring. Why this code doesn't do what i want?

 

Is the code wrong?

 

UDIS does not avoid underflow update event?

 

And if so, why the counter auto-reload?

 

If I understand correctly UDIS only disables reloading of the ARR shadow register itself with new value from ARR preload register. It doesn't affect CNT reload.

Posted on June 06, 2013 at 12:31

I was just expressing my own frustration from how the timers (and many other things) are ''documented''.

----

If I understand correctly, ''update event'', however confusing the name is, is an internal signal in the timer, which has several uses - as Kink said above, it causes the shadow registers to be reloaded if this is enabled (again the word ''shadow'' might be confusing, as these are the real working registers from which the timer reload/compare etc. ''happens''); triggers interrupt/DMA transfer if enabled; can be output as a TRGO to a chained slave timer.

However, this is NOT the signal which reloads the timer - that one is unnamed (for the mere users).

The signals/''events'' in the timers are unusually complex, and a thorough block diagram of them would go quite a long way in explaining the timers' workings; unfortunately, I know of no such.

JW
Posted on June 06, 2013 at 13:37

How does ''register level programming'' relate to misunderstanding ...

The timer design sucks, the documentation and examples also suck, welcome to general solutions in silicon. I'm acknowledging a) I read the original post, but b) don't care to unravel the bit minutia of register level code, and c) suggested a mode of the timer likely to work in the way desired, and which it doesn't currently use. I can understand the frustration and anger with the code, but I don't want to share it.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dario
Associate II
Posted on June 06, 2013 at 18:39

Damn! I really thought that UDIS it is used to avoid the counter to reload... Really frustrating.

Thank you to all!!!

I'll use OPM...