Freescale Semiconductor DRM079 manual KBISCKBACK, Kbisc, MTIMSCTOF, Mtimsc

Models: DRM079

1 34
Download 34 pages 61.79 Kb
Page 30
Image 30
Variable Speed DC Fan Control using the MC9RS08KA2, Rev. 0

Implementation

;X indicate the coil to be driven ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SetPWM:

mov

#255, MTIMMOD

 

; OF period

mov

#(mMTIMSC_TRSTmMTIMSC_TOIE), MTIMSC; Reset and Start Timer

lda

#20

 

; Enable Interrupt & Edge only

mov

#(mKBISC_KBIE), KBISC

bset

KBISC_KBACK, KBISC

; Clear Flag

stx

PTAD

 

; Drive coil

TimingLoop:

MTIMSC_TOF, MTIMSC

; Clear TOF

bclr

wait

KBISC_KBF, KBISC, HallFound

; HALL sensor edge found

brset

dbnza

TimingLoop

; If no HALL output, Stop the driving

jmp

MotorHang

HallFound:

MTIMCNT, DriveTime

 

mov

 

cbeqa

#20, StableDrive

 

mov

#MaxDeadTime, DriveTime

 

StableDrive:

DeadTime

 

 

lda

 

 

add

DriveTime

 

 

sta

ActualPeriod

 

; Disconnect coil

clr

PTAD

 

mov

#(mKBISC_KBACK), KBISC

; Clear Flag and mask interrupt

mov

#(mMTIMSC_TSTPmMTIMSC_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_CLKMTIM_DIV_8), MTIMCLK; Change Timer resolution

mov

#63, MTIMMOD

; OF period

mov

#(mMTIMSC_TRSTmMTIMSC_TOIE), MTIMSC; Reset and Start Timer

mov

#(mACMPSC_ACMEmACMPSC_ACIEACMP_OUTPUT_RAISING), ACMPSC

bset

; Enable ACMP, start RC rise

ACMPSC_ACF, ACMPSC

; Clear ACMP Flag

wait

; delay to OF and make the read process deterministic

brclr

ACMPSC_ACF, ACMPSC, NoReading

 

mov

MTIMCNT, SensorReading

; Clear ACMP Flag

bset

ACMPSC_ACF, ACMPSC

clr

ACMPSC

; disable ACMP

wait

#(mMTIMSC_TSTPmMTIMSC_TRST), MTIMSC; mask interrupt and clear flag

mov

mov

#(MTIM_BUS_CLKMTIM_DIV_256), MTIMCLK; Reset Timer resolution

rts

 

 

30

Freescale Semiconductor

Page 30
Image 30
Freescale Semiconductor DRM079 manual KBISCKBACK, Kbisc, MTIMSCTOF, Mtimsc