Datasheet
Pulse-Width Modulator (PWM)
M68HC12B Family Data Sheet, Rev. 9.1
140 Freescale Semiconductor
11.4.3 Code Listing
NOTE
A comment line is deliminted by a semi-colon. If there is no code before
comment, an “;” must be placed in the first column to avoid assembly
errors.
INCLUDE 'EQUATES.ASM' ; Equates for all registers
; ----------------------------------------------------------------------
; MAIN PROGRAM
; ----------------------------------------------------------------------
ORG $7000 ; 16K On-Board RAM, User code data area,
; ; start main program at $7000
MAIN:
BSR TIMERINIT ; Subroutine used to initialize the timer:
; ; Out. comp. chan. using OC7 & OC5,
; ; no interrupts
; ; OC7 = PERIOD & OC5 = HIGH TIME of PWM
DONE: BRA DONE ; Branch to itself, Convinient for Breakpoint
;* --------------------------------------------------------
;* Subroutine TIMERINIT: Initialize Timer for PWM on OC5
;* --------------------------------------------------------
TIMERINIT:
CLR TMSK1 ; Disable All Interrupts
MOVB #$0A,TMSK2 ; Disable overflow interrupt, disable pull-up
; ; resistor function with normal drive capability
; ; and Cntr reset by a succesful OC7 compare,
; ; Prescaler = sys clock / 4.
MOVB #$88,TCTL1 ; Init. OC5 to Clear ouput line to zero on
; ; successful compare.
MOVB #$A0,TIOS ; Select Channel 5 and 7 to act as output compare.
MOVB #$20,OC7M ; Initialize OC7 compare to affect OC5 pin(OC7M)
MOVB #$20,OC7D ; Enable OC7 to set output compare 5 pin high(OC7D).
MOVW #$0800,TC7H ; Load TC7 with "PERIOD" of the PWM
MOVW #$0400,TC5H ; Load TC5 with "HIGH TIME" of the PWM.
MOVB #$80,TSCR ; Enable Timer, Timer runs during wait state,
; ; and while in Background Mode, also clear flags
; ; normally.
RTS ; Return from Subroutine
