Specifications
50
4.6.10 Initialisation of Ports and Interrupts
There are several different subroutines used to initialise ports and define interrupt
control. One exists for each of the following: Pulse width modulation, port P; Port A;
Key wake up Port G and the serial port. It is essential that these initialisation
subroutines are run at the start of the program before any actual running commences.
This ensures the interrupts are set ready to work, the serial port is communicating and
that all input and output is taken care of.
The Pulse Width Modulation (PWM) is the method of controlling the speed of the
motors. The Motorola HC12 has four channels devoted to PWM and can easily be set
using the following code. Each of the bytes moved into the PWM control registers
provides a certain setting required for the desired use of the PWM channels. Clear
explanation of each bit can be found in the data sheet for the Motorola HC12. First
specification set is the pre-scaler. This is used to slow down the clock for use as the
PWM. Extremely high frequencies are not desired as they create excess power loss and
heating through the H Bridge switching. Used here is a pre-scaler of 128 which means
the frequency of the PWM will be 128 times smaller than the frequency of the
microcontroller clock. The PWPOL byte takes care of which clock to use for each
channel and also the polarity of the duty cycle for each cycle. PWEN simply enables all
the selected lines to be output regardless of the data direction register. PWCTL sets
port P to have an active pull up device enabled.
;***************************************************************************
;SETUP PWM Channels
INITPWM MOVB #%00111111,PWCLK ;PRESCALER OF /128
MOVB #%00001111,PWPOL ;PPOL
MOVB #%00001111,PWEN ;ENABLE ALL OUTPUTS
MOVB #%00000010,PWCTL ;PULL UP DEVICE ENABLED
SETPWM MOVB #$FF,PWPER0 ;|
MOVB #$FF,PWPER1 ;|PERIOD FOR PWM
MOVB #$FF,PWPER2 ;|
MOVB #$FF,PWPER3 ;|










