Friday, May 29, 2015

Timer Time: Using Internal ATTiny13A Chip’s Timer “Normal” Mode (Slightly Modified)

Our timer is static, it have to wait TCNT0 to count from 0 to 255 and then start over.

We could modify it so it count from x to 255 to make it count faster

so we need to pre-set/pre-load TCNT0 to some value

ldi a, 200
out TCNT0,a

With that, we could make the delay time faster. Set the TCNT0 to lower value for longer delay



We  need to modify it

.include "../tn13Adef.inc"
.def a=r16
.org 0000

init:
    sbi ddrb,0          ; pin b0 output
    ldi a,0b00000101    ; prescaler 1024
    out TCCR0B,a
    
main:
    sbi pinb,0          ; flip the B0 bit
    rcall timer
    ldi a,200           ; set lower for longer delay
    out TCNT0,a
    rjmp main

timer:
        loop:
    in a,TIFR0          ; wait 
    andi a, 0b00000010  ; (1<<TOV0) is TOV0 still 1 or flagged to 0?
    breq loop
    
    ldi a, 0b00000010   ; set TOV0 to 1 again after flagged
    out TIFR0,a
    
    ret