|
Generating PWM Using AT89C2051
Using an appropriate programming, we can
establish a pwm generator using AT89C2051 microcontroller (this circuit can
be seen at Figure 1). For this implementation, P1 of AT89C2051 has a
function as data input (that normalized to 100), how big the digital signal
that proportional to the analog. The PWM output is connected to P3.0.

Figure 1. PWM generator circuit using AT89C2051

Figure 2. Simulation of PWM with duty cycle 40
%.
Figure 2
explains how PWM signal is proportional to the
analog. For the assumption, analog voltage is 4 volt, the maximum voltage is
10, so the PWM has 40% duty cycle.
Here is the simple code for generating pwm signal out the
circuit as seen at Figure 1.
$mod51
org 00h
jmp mulai
mulai:
mov r0, p0
;r0 berisi data kondisi tinggi
cjne r0, #100,
kecil
ulang:
setb p1.0
djnz r0, ulang
jmp mulai
kecil:
mov a, #100
subb a, r0
mov r1, a
;r1 berisi data kondisi rendah
on:
setb p1.0
djnz r0, on
off:
clr p1.0
djnz r1, off
jmp mulai
end
|