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
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
This value (YY)h is loaded in TH0 and TL0 register in program.
Can you please provide a code for Pulse triggering using Microcontroller ?
ReplyDelete