Forum breadcrumbs - You are here:ForumGeneral: HelpATMega328P Timer0 in TCNT mode
You need to log in to create posts and topics.

ATMega328P Timer0 in TCNT mode

I am not sure what to think about this ; but whith an OCRO0A value @ 9, the frequency should be 12,7Hz ; instead Simulide gives 127 Hz. Worse  it stays at 127Hz whatever OCRO0A value is given (127 in the picture below....

The program works as expected with real Arduino Nano and oscilloscope.

Attached the firmware source code.

 

Uploaded files:

Thank you. Already fixed the problem.

By now you can clear TCNT0 right before restarting the timer and it should work ok:

delay_timer0:             ;0.64 ms delay via Timer0
    ;---------------------------------------------------------
    LDI   R20,9
    OUT   OCR0A, R20      ;OCR0 = 9
    LDI   R20, 0b00000010
    OUT   TCCR0A, R20     ;timer0: CTC mode

    CLR   R20             ;                               <<------------------------
    OUT   TCNT0, R20      ;initialize timer0 with count=0 <<------------------------
    LDI   R20, 0b00000101
    OUT   TCCR0B, R20     ;prescaler 1024
    ;---------------------------------------------------------

 

 

Christian has reacted to this post.
Christian

Thank you for your fast answer! Confirm the work around is doing the job.

arcachofo has reacted to this post.
arcachofo