AnsweredAssumed Answered

timer6 strange behaviour

Question asked by suy.ronny on Aug 20, 2011
Latest reply on Aug 20, 2011 by Clive One
Hi

I wrote a delay routine using timer6. R2 folds the number of milliseconds to delay.
It works fine , however only from the second time on. the first time there is no delay , the program just 'flies' through the code without a delay.
This is my routine (in assembler)

delayms        ;delay r2 milliseconds

                stmfd    r13!,{r0,r1,r14}        
        
                ldr    r0,=TIM6_CNT        ;start counting from 0000
        mov    r1,#0x0000
        str    r1,[r0]
        ldr    r0,=TIM6_PSC        ;prescaler = 59904 ; gives 1ms/count
        ldr     r1,=59904
        str    r1,[r0]
        ldr    r0,=TIM6_ARR        ;r2 = # milliseconds
        str    r2,[r0]
        ldr    r0,=TIM6_CR1        ;enable counter,no reload, single puls mode
        mov    r1,#0x000d
        str    r1,[r0]
                
delayl        ldr    r0,=TIM6_SR        ;wait for UIF
        ldr    r1,[r0]
        cmp     r1,#0x0000
        beq    delayl        

        ldr    r0,=TIM6_SR        ;clear UIF flag
        mov    r1,#0x0000
        str    r1,[r0]
        ldr    r0,=TIM6_CR1        ;stop the timer
        mov    r1,#0x0000
        str    r1,[r0]
                ldmfd    r13!,{r0,r1,pc}

Does anyone know what the reason could be for this behaviour ?
Any help is welcome !

Ronny Suy

Outcomes