Tuesday, January 28, 2014

Generation of PWM (Pulse Width Modulation) using MC 8051


Generation of PWM (Pulse Width Modulation) using MC 8051



Calculation of timer delay generation for 8051:

TMOD Reg:
D7
D6
D5
D4
D3
D2
D1
D0
Gate
C/T
M1
M0
Gate
C/T
M1
M0

For enable timer0
We use D3-D0 bit
Gate = 0, means the Timer0 is control by software method
C/T(counter/Timer) = 0,Means Timer is Enable
M1  M0    for mode selection
0          0          Mode0: 13 bit timer
0          1          Mode1: 16bit timer
1          0          Mode2: 8bit auto reload timer
1          1          Mode3: Split timer mode



























We are using mode 1

So M1 M0 = 01
D3 = 0; D2 = 0; D1 = 0; D0 = 1; rest all bit are don’t care
TMOD = 0x01;
For count calculation we must know the XTAL value in my case its 11.0592MHz
If we need time delay =1ms, that mean Required delay (Td) = 1ms;
Now we have to find Fin
Fin = XTAL/12           [12 it the total machine cycle]
Fin = (11. 0592x10^6)/12;  Fin=09216x10^6;
Tin = 1/(Fin);             Tin = 1.08506x10^-6;
Count(xx)d = Td/Tin;          count= (1x10^-3)/(1.0856x10^-6);
Count = 921; equalent hex value = 399
(YY)h   =     Max Count     -     Count(xx)d;          16 bit timer max count = FFFF
(YY)h     =     FFFF      -           399  = FC67;

























This value (YY)is loaded in TH0 and TL0 register in program.


For video of above program: Click for Video



1 comment:

  1. Can you please provide a code for Pulse triggering using Microcontroller ?

    ReplyDelete