Motor Controller (MC10B8CV1)
MC9S12XHY-Family Reference Manual, Rev. 1.01
696
Freescale Semiconductor
;------------------------------------------------------------------------------------------
;global motor controller init
;------------------------------------------------------------------------------------------
GLB_INIT: MOVB #$0000,MCCTL0
; fMC = fBUS, FAST=0, DITH=0
MOVB #$0000,MCCTL1
; RECIRC=0, MCTOIE=0
MOVW #$D0D0,MCCC0
; dual full h-bridge mode, left aligned,
; no channel delay
MOVW #$0000,MCPER_HI
; disable motor controller
;------------------------------------------------------------------------------------------
;motor controller startup
;------------------------------------------------------------------------------------------
STARTUP:
MOVW #$0000,MCDC0_HI
; define startup duty cycles
MOVW #$0000,MCDC1_HI
MOVW #MCPERIOD,MCPER_HI
; define PWM period
MOVB #$80,TSCR1
; enable timer
MAIN: LDAA PORTB
; if PB=0, activate shutdown
ANDA #$01
BEQ MN0
JSR TIM_SR
MN0: TST TFLG2
; poll for timer counter overflow flag
BEQ MAIN
; TOF set?
JSR TIM_SR
; yes, go to TIM_SR
BRA MAIN
TIM_SR: LDX TEMP_X
; restore index register X
LDAA PORTB
; if PB=0, enter shutdown routine
ANDA #$01
BNE SHUTDOWN
LDX TEMP_X
; restore index register X
BEQ NEW_SEQ
; all mc configurations done?
NEW_CFG: LDD DTYDAT,X
; load new config’s
STD MCDC0_HI
DEX
DEX
LDD DTYDAT,X
STD MCDC1_HI
BRA END_SR
; leave sub-routine
SHUTDOWN: MOVB #$00,TSCR1
; disable timer
MOVW #$0000,MCDC0_HI
; define startup duty cycle
MOVW #$0000,MCDC1_HI
; define startup duty cycle
LDAA #$0000
; ensure that duty cycle registers are
; cleared for some time before disabling
; the motor controller
LOOP DECA
BNE LOOP
MOVW #$0000,MCPER_HI
; define pwm period
NEW_SEQ: MOVW TABLESIZE,TEMP_X
; start new tx loop
LDX TEMP_X
END_SR: STX TEMP_X
; save byte counter
MOVB #$80,TFLG2
; clear TOF
RTS
; wait for new timer overflow
electronic components distributor