wave will be sent to the D/A
converter every 65.10416667
microseconds. Since there are 256
points on the sine wave, 256 points
will take 256 x 65.10416667 =
0.0166667 seconds, which is the
exact period of 60 Hz! In other
words, this Wait time produces a
sine wave with a frequency of
exactly 60.000 Hz.
The Wait box in the flow chart
creates the delay by waiting for an
interrupt from the timer system of
the processor. Using a 15. 36 MHz
crystal, this processor will generate a
bus frequency of 15. 36 MHz/2 =
The timer system is thereby
driven from a clock with a
period of 1/7.68 MHz =
The internal timer counter is
programmed to be a modulo
500 counter so that it
overflows and jumps back to
0 at a count of 500. Note
that 500 x 130.2083333 ns
= 65.10416667 µs.
The processor is
programmed to interrupt at
every overflow of the
modulo 500 counter. The
resulting interrupt service
routine lets the processor
pass the Wait state and go
on to create a point on the
sine wave every
If a modulo 600 counter were used instead of the
modulo 500 counter, interrupts would occur at 600 x
130.2083333 ns = 78.125 µs, and the output period is
78.125 µs x 256 = 0.02 seconds, or 50 Hz exactly.
Using a modulo 75 counter produces exactly 400 Hz.
Thus, the three main power frequencies can be precisely
synthesized with a 15. 36 MHz crystal, which is a stock
part with many distributors.
It is important to recognize that for 60 Hz, the
interrupts are spaced 65.18416667 µs apart. The time
necessary for reading the table, sending the data out to
the D/A converter, and incrementing the index register all
take place during the time between interrupts and subtract
from the time in the Wait state.
For example, suppose it takes a total of 30 µs to read
the table, send the data out, and increment X. Then, 30 µs
will already have passed and the system will stay in the
Wait state for only another
65.18416667 – 30 = 35.18416667
µs until the next interrupt occurs. In
other words, part of the interrupt
time period is used to do necessary
tasks and not just waiting.
This system produces exactly 60
Hz, subject only to the accuracy of
the 15. 36 MHz clock. It remains
now to adjust this frequency to the
line frequency, which may deviate
from exactly 60 Hz.
The synchronizer adds some
extra steps into the flow chart in
Figure 5. Its function is to
restart the waveform on the
positive going zero crossing
of the line voltage. This
either chops off a small
segment of the 60 Hz
waveform or extends the
running time of the 60 Hz
waveform; in both cases, to
make it have the exact
period of the line.
The line voltage cannot
be connected directly to the
microcontroller. It is
connected through an
optocoupler such as a 4N35.
The circuit is shown in
The optocoupler — in
addition to isolating the line
— creates an inverted square wave replica of the line at
port B1 of the micro. When the line goes positive, the
square wave is logical zero; when the line goes negative,
the square wave is logical 1. A photo showing the
simulated line voltage and the signal at the B1 port on the
microcontroller is shown in Figure 7.
Consider the case where no line voltage is applied.
The signal at B1 will be continuously High. That is B1=1.
The flow chart shows that under these circumstances, the
main part of the synchronization logic will be bypassed,
and only the flag will be repeatedly reset (with no effect).
The oscillator will work just as previously described. In
other words, the synchronization system has no effect if
the synchronization signal (line voltage) is absent.
Consider next that the line voltage is connected.
When the line voltage is negative, B1=1 and the system
behaves as described above.
April 2017 43
FIGURE 7. Optocoupler output (blue) vs.
simulated line voltage (yellow).
FIGURE 6. Optocoupler circuit.