We could speeding the timer by pre-loading TCNT0 with a value between 0 and 255, so TCNT0’ll start count at our own value instead of zero.  We have to pre-load the TCNT0 at the init subroutine, and pre-load again after flag is set, so we write the command at the timer subroutine.  So, our code now will look like this  .include "../tn13Adef.inc" .def a=r16 .org 0000 rjmp init .org 0003 rjmp timer init: sbi ddrb,0          ; pin b0 output ldi a,0b00000101    ; prescaler 1024 out TCCR0B,a ldi a,0b00000010    ; enable OVF out TIMSK0,a ldi a, 64           ; preload TCNT0 out TCNT0,a sei                 ; enable interrupts globally main: rjmp main timer: sbi pinb,0          ; flip pin B0 bit ldi a,64            ; preload again  out TCNT0,a reti

Using interrupt, we have a subroutine that regularly called, automatically. It called when overflow flag (OVF) is set. As always, the timer/counter (TCNT0 register) counts up from zero toward 255, called an interrupt and rolls over back to zero and starts counts up again.  We could set the output at the interrupt subroutine so we eventually have nothing to do at the main program. main: rjmp main

Clear Timer on Compare (CTC) as its name suggests, will clear the flag if counter has same value with compare value.  Thus, TCNT0 still count fram zero to 255, but if we set OCR0A on 64, timer will clear the flag at 64, restart counter to zero and count up again. If we set OCR0A to 255, then it’ll behave like normal timer in 'Normal’ Mode. If OCR0A value’s lower, then the delay time is faster/shorter. Here's the code. OCF0A is compare flag, the bit-3 on TIFR0 register. Notice that we have to set TCCR0A register to enable CTC mode; in Normal mode we don’t have to do that.

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

Chip’s Internal Timer in ’Normal' mode will count from 0 to 255, set the overflow flag TOV0 to 0 and count again from 0 to 255, set the flag to 0 and so on.  As usual, I used LED as output indicator on Port B0 We used 1024 for pre-scaler/divider value. Set the TCCR0B to 0000 0101 Note that we have to reset the overflow flag to 1 after timer count reached 255 (and set the flag to 0).  Oh, by the way, the register/variable/things that count from 0 to 255 is called TCNT0. We didn’t touch it in the code this time, maybe next.

Kadang datang secara tak disangka. Tak hanya pencerahan relijius seperti Sakti dari Sheila on 7 yang tiba-tiba 'terbangun' saat baca buku "Menjemput Sakaratul Maut ...." di bandara dan majalah Mati Suri di rumah sakit. Kini dia bernama Salman Al Jugjawy. Saya mengalami pencerahan secara musikal, beberapa kali. Saya termasuk telat belajar alat musik. Memiliki gitar di akhir kelas satu SMP. Awalnya belajar lagu standart Koes Plus, Iwan Fals. Dangdut populer, belajar karena ikut ekstrakurikuler band musik, manggung di tempat-tempat yang menginginkan lagu dangdut. Tembang kenangan malam-malam di radio. Saat SMU saya "Naik tingkat". Boomerang, Jamrud, Padi, Dewa19, Sheila On 7, Slank dan musik-musik populer di radio jadi sasaran. Lagi,di akhir SMU mengenal underground music. Pernah sampai diusir yang punya "studio" karena "gak niat", "ngrusak drum", "bikin sakit kuping", "liriknya gak bisa didengarkan", "bahasa apa itu?". Cuma lagu Derek yang easy listening, yang kedua adalah Bendera Kuning (kayak gitu easy listening? Yup, dibanding yang lain, ;) ) Sound gitar suka yang berdistorsi full, masuk akal memang. Efek gitar lebih suka semacam Metal Zone. Semakin djent djent djent semakin keren. Sangat anti dengan efek Overdrive . Tone harus se-treble mungkin. Dan sering frustrasi karena tidak dapat distorsi seperti di fantasi. Paling sulit meniru Eros, ada distorsi tapi nada individual tetap terdengar. Dan pencerahan itu datang.

Jonathan Ive style, Old Macbook Pro sleep indicator LED. Using interrupt, fast PWM on ATTiny13A.

Maybe it's just me, but I recently realized that we have a handy feature on ATTiny13A for flip the value of the bit. so instead of sbic PINB,0 cbi PINB,0 sbi PINB,0 we could just use sbi PINB,0 Saving some clocks, :)

Here's the template .include "../tn13Adef.INC"  .def a=r16 .org $0000              ; startup vector rjmp onReset .org $0006              ; compare match vector rjmp Tim0CompA onReset: sbi DDRB,0          ; port B0 as output ldi a, 0b10000011   ; pwm mode 3 out TCCR0A, a ldi a, 0b00000101   ; divider /1024 out TCCR0B,a ldi a, 0b0000100    ; enable compare interrupt out TIMSK0,a sei main: rjmp main Tim0CompA: in a, OCR0A inc a out OCR0A,a reti
Archive
Label
Popular Posts
Popular Posts
Loading