
211
7.10 Program Example for 8-bit PWM Timer
This section gives program examples for the 8-bit PWM timer.
s Program Example for Interval Timer Function
r Processing description
Generates repeated interval timer interrupts at 5 ms intervals.
Outputs a square wave to the PWM1 pin that inverts after each interval time.
With a main clock master oscillation FCH of 4.2 MHz, and the highest speed clock selected
by the speed-shift function (1 instruction cycle time = 4/FCH), the COMR register is set for an
interval time of approximately 5 ms. (AN internal clock period of 64 tinst is selected as the
count clock.) The COMR register setting is calculated as follows:
COMR register value = 5 ms/(64 × 4/4.2 MHz) - 1 = 81.0 (051H)
r Coding example
CNTR1
COMR1
EQU
001EH
001FH
; Address of the PWM 1 control register
; Address of the PWM 1 compare register
TPE
TIR
EQU
CNTR1:3
CNTR1:2
; Define the counter operation enable bit.
; Define the interrupt request flag bit.
ILR3
EQU
007EH
; Address of the interrupt level setting
register 3
INT_V
IRQ9
INT_V
DSEG
ORG
DW
ENDS
ABS
0FFE8H
WARI
; [DATA SEGMENT]
; Set reset vector.
;-------- Main program ----------------------------------------------------------------------------------------------
CSEG
:
CLRI
CLRB
MOV
SETI
:
TPE
ILR3,#11110111B
COMR1,#051H
CNTR1,#00101011B
; [CODE SEGMENT]
; Stack pointer (SP) etc. are already
initialized.
; Disable interrupts.
; Stop counter operation.
; Set interrupt level (level 1).
; Value compared with the counter value
(interval time)
; Operate interval timer, select 64 tinst, start
counter operation, clear interrupt request
flag, enable TO pin output, enable interrupt
request output.
; Enable interrupts.