diff --git a/src/clockinator.S b/src/clockinator.S index 2519057..7dd31d5 100644 --- a/src/clockinator.S +++ b/src/clockinator.S @@ -8,13 +8,18 @@ #define __SFR_OFFSET 0 #include + #include "timer.inc" #include "led.inc" - ;#include "bpm.inc" ;#include "midi.inc" .global main +; note for the future +; isr_button interrupt use +; INT0 on the GIMSK, with the button on PB2 +; this enable a more precise/fast interrupt +; useful for the tap tempo stuff isr_stop_blink: rcall stop_blink ; Turn off PB0 when TCNT0=OCF0A @@ -23,9 +28,9 @@ isr_stop_blink: main: ; To compile on AtTiny25/45 comment out the SPH part ; SPH is needed only on AtTiny85 which has >256b of SRAM - ldi r16, lo8(RAMEND) + ldi r16, lo8(RAMEND) out SPL, r0 ; Setup stack pointer LOW - ldi r16, hi8(RAMEND) + ldi r16, hi8(RAMEND) out SPH, r0 ; Setup stack pointer HIGH sei ; Global interrupt flag @@ -33,24 +38,18 @@ main: ;cbi DDRB, PB1 ; Set EC11 clockwise on PB5 as input ;cbi DDRB, PB2 ; Set EC11 counter-clockwise on PB3 as input ;cbi DDRB, PB5 ; Set EC11 button (555 square wave) on PB4 as input - ldi r26, 60 ; Default BPM //TODO: save to eeprom not register, on runtime also ldi on r24 register + sbi DDRB, PB0 ; Set led on PB0 as output + ;ldi r26, 60 ; Default BPM //TODO: save to eeprom not register, on runtime also ldi on r24 register rcall timer0_set - rcall timer1_set + ;rcall timer1_set -; interrupts: -; button (tap tempo loop) tap_tempo: -; encoder (increase/decrease tempo by one) incr_temp: , decr_temp: -; timer 1 -; -; otherwise start from default bpm 60 (r26) - ; loop: calculate tempo (high priority!) and save, led blinking, segment led writing loop: - ldi r24, 30 ; Load current BPM to register //NOTE: hardcoded temporary + ;ldi r24, 30 ; Load current BPM to register //NOTE: hardcoded temporary ; TODO: compare two registers (current bpm and previous bpm) - rcall tempo_calc ; CHANGE: if BPM changed then rcall BPM calculation function else skip because ticks tempo is the value already in [OCR1C] + ;rcall tempo_calc ; CHANGE: if BPM changed then rcall BPM calculation function else skip because ticks tempo is the value already in [OCR1C] ; if this BPM != previous BPM then load this to another register (will be used as the 'previous register') ; final result stored in OCR1C as ticks @@ -59,13 +58,6 @@ loop: ;rcall midi_send ; Send MIDI ping - //FIXME: do this with interrupts. its much more efficient - // remove the polling shit and move stop_blink or an ISR - // check if need to change internal logic on led.inc - ; if midi clock then also do: rcall start_blink - in r16, TIFR0 ; Read Interrupt Flag Register - sbrs r16, OCF0A ; If timer status OCF0A=1 skip jump - rcall stop_blink ; if midi clock then after do: rcall start_blink @@ -73,4 +65,8 @@ loop: ;rcall segment_led ; Output current BPM to 3-digit 7-segment LED [r24] + + ; sleep when BPM is stabilized (whenever BPM calculation are not being done) and outside of midi send + ; to do this explore MCUCR register, it can do a lot of stuff + rjmp loop ; Loopback