Overview Hardware Software Appendix Home

Appendix

Schematics

Figure 3 Schematics for the Station Master project.

Listing 1: Main loop from the stationMaster.asm file

;****************************************************************************

; MAIN LOOP

;

loop:

;check for alarm status

check_alm:

sbrs state,sALARM

rjmp update_motor

;Update motor for alarm state

alarm_motor:

out OCR0A,pwm ;set motor power

rjmp check_button1

;Update motor for normal state

update_motor:

sbrs state,sMOTOR

rjmp motor_OFF

out OCR0A,pwm ;set motor power

rjmp check_button1


motor_OFF:

clr tempb ;turn motor off

; out OCR0A, tempb

out OCR0A, f_lnoiseCnt ;FOR DEBUG>> REMOVE ME LATER

; out OCR0A, f_sampleCnt ;FOR DEBUG>> REMOVE ME LATER


;Read buttons

check_button1: ; control switch

sbrs state,sBUTTON1

rjmp update_filter

; Button 1 pushed -> add station to count.

;clear button press flag ;clear alarm if it is sounding

cbr state,(1<<sBUTTON1)|(1<<sIDLE)|(1<<sALARM)


;Add another station to the countdown.

add_station:

;reset timers

clr countL

clr countH

sbr state,(1<<sLONG) ;Flag for long key press

;increment the alarm setting

ldi tempa,STATION_INC

add alarm,tempa

sbr state,(1<<sMOTOR) ;pulse to acknowledge

ldi ZL,PWM_ZERO ;soft fade in

;Check if motor is off and read adc if an update is due

update_filter:

ldi tempa,(1<<sMOTOR)|(1<<sALARM)

and tempa,state ;dont read acccel when motor is on

brne end

sbrs state,sREADADC ;check if an update is due

rjmp end

cpse alarm,zeroReg ;dont update if no alarm is set

rcall filter ;read ADC and update f_sate etc.

cbr state, (1<<sREADADC) ;clear the flag


end:

; Go to sleep and wait for an interupt to wake us. 

; (IDLE MODE) keep timers running. stop main clock.

sei

ldi tempa,(0<<PUD)|(1<<SE)|(0<<SM1)|(0<<SM0)|(0<<ISC01)|(0<<ISC00)

out MCUCR,tempa

sleep

; just woke up, disable sleep

ldi tempa,(0<<PUD)|(0<<SE)|(0<<SM1)|(0<<SM0)|(0<<ISC01)|(0<<ISC00)

out MCUCR,tempa

cli

rjmp loop

Overview Hardware Software Appendix My Blog