User's Manual

Implementation
Variable Speed DC Fan Control using the MC9RS08KA2, Rev. 0
30 Freescale Semiconductor
; X indicate the coil to be driven
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SetPWM:
mov #255, MTIMMOD ; OF period
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC; Reset and Start Timer
lda #20
mov #(mKBISC_KBIE), KBISC ; Enable Interrupt & Edge only
bset KBISC_KBACK, KBISC ; Clear Flag
stx PTAD ; Drive coil
TimingLoop:
bclr MTIMSC_TOF, MTIMSC ; Clear TOF
wait
brset KBISC_KBF, KBISC, HallFound ; HALL sensor edge found
dbnza TimingLoop
jmp MotorHang ; If no HALL output, Stop the driving
HallFound:
mov MTIMCNT, DriveTime
cbeqa #20, StableDrive
mov #MaxDeadTime, DriveTime
StableDrive:
lda DeadTime
add DriveTime
sta ActualPeriod
clr PTAD ; Disconnect coil
mov #(mKBISC_KBACK), KBISC ; Clear Flag and mask interrupt
mov #(mMTIMSC_TSTP|mMTIMSC_TRST), MTIMSC; mask interrupt and clear flag
rts
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; Read Temperature Sensor Value
; Timer prescalar=8 -> Timer clk~250kHz
; Bus = 2MHz
; Max OF period = 1.02ms
; Timer resolution = 4us
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReadSensor:
mov #(MTIM_BUS_CLK|MTIM_DIV_8), MTIMCLK; Change Timer resolution
mov #63, MTIMMOD ; OF period
mov #(mMTIMSC_TRST|mMTIMSC_TOIE), MTIMSC; Reset and Start Timer
mov #(mACMPSC_ACME|mACMPSC_ACIE|ACMP_OUTPUT_RAISING), ACMPSC
; Enable ACMP, start RC rise
bset ACMPSC_ACF, ACMPSC ; Clear ACMP Flag
wait ; delay to OF and make the read process deterministic
brclr ACMPSC_ACF, ACMPSC, NoReading
mov MTIMCNT, SensorReading
bset ACMPSC_ACF, ACMPSC ; Clear ACMP Flag
clr ACMPSC ; disable ACMP
wait
mov #(mMTIMSC_TSTP|mMTIMSC_TRST), MTIMSC; mask interrupt and clear flag
mov #(MTIM_BUS_CLK|MTIM_DIV_256), MTIMCLK; Reset Timer resolution
rts