2013-06-05 03:02 PM
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?"2013-06-05 04:35 PM
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?2013-06-06 12:10 AM
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? Jan2013-06-06 12:58 AM
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.2013-06-06 01:44 AM
Yes, i'm a beginner!
For these simple command i prefer to set/reset registers because1) read the reference manual2) find the register3) try to understand how it change the behavior of the micro4) write the codeUsing 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 reply2013-06-06 02:56 AM
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.
2013-06-06 03:31 AM
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. JW2013-06-06 04:37 AM
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.2013-06-06 09:39 AM
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...