








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An example of using a microcontroller's timer function as an output compare (oc) device to generate desired frequencies. The example covers setting the omx and olx bits, detecting tocx matches, and adjusting frequency accuracy. Users will learn how to determine the low and high bounds of the frequencies that can be generated.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









Figure 1 Square wave schematics showing the half-wave duration, t, and the low (L) and high (H)
states.
i) * Define variable
Half wave duration DT = 2 bytes
ii) Initialize
Initialize index X to REGBAS
Initialize timer OC3 function:
set to toggle (OM3=0, OL3=1)
iii) Store initial time + DT in TOC
iv) Wait and loop until OC3F is set;
when OC3F set, proceed
v) Reset OC3F
vi) Update TOC3: add DT to current
time and store in TOC
vii) Branch back iv)
Define variables:
Half wave duration DT = 2 bytes
SWI
Initialize index X to REGBAS
Initialize timer OC3 function:
set to toggle (OM3=0,
OL3=1)
START
Store TCNT+DT in TOC
Check if OC3F is set
LABEL
Reset OC3F
Store TCNT+DT in TOC
ORG DATA
DT RMB 2
ORG PROGRAM
START LDX #REGBAS
LDAA #%
STAA TCTL1,X
LDD DT
ADDD TCNT,X
STD TOC3,X
LABEL1 LDAA TFLG1,X
ANDA #%
BEQ LABEL
LDAA #%
STAA TFLG1,X
LDD DT
ADDD TCNT,X
STD TOC3,X
BRA LABEL
SWI
Hz
DT s
f raw
Hz
DT s
f raw
Desired f Half-period Raw Delay DT Time,
s f=1/
t error %
Hz
s hex hex t_1 t_
t Hz
500 1000 07D0 07d0 1012 2023 1011 495 -1.1%
07c0 1007 2010 1003 499 -0.3%
1000 500 03E8 03e0 508 1015 507 986 -1.4%
03d0 503 1002 499 1002 0.2%
2000 250 01F4 01f0 260 520 260 1923 -3.8%
01e0 256 506 250 2000 0.0%
5000 100 00C8 00c8 112 223 111 4505 -9.9%
00c0 112 218 106 4717 -5.7%
00b8 108 210 102 4902 -2.0%
00b0 103 200 97 5155 3.1%
00b4 103 205 102 4902 -2.0%
WHAT YOU HAVE LEARNED
EMCH 367 Fundamentals of Microcontrollers qkd57d-823709-3288346-q-20example-oc-doc.doc
OUTPUT COMPART TIMER FUNCTION