![]() ![]() In above example I am using 160, you can choose any value from 0 to 255. The width of PWM can be changed by changing the value of R7 re gister. Timer Interrupt service routine will take care of PWM i n the background. MOV TH0, A so the value loaded into TH0 + R7 = 255 CLR TF0 Clear the Timer 0 interrupt flag RETI Return from Interrupt to where the program came from In your main program you need to call this PWM_SETUP routine and your controller will have a PWM output. ÂșInterrupt Service Routine CODE: TIMER_0_INTERRUPT: JB F0, HIGH_DONE If F0 flag is set then we just finished the high section of the LOW_DONE: cycle so Jump to HIGH_DONE SETB F0 Make F0=1 to indicate start of high section SETB PWMPIN Make PWM output pin High MOV TH0, R7 Load high byte of timer with R7 (pulse width control value) CLR TF0 Clear the Timer 0 interrupt flag RETI Return from Interrupt to where the program came from HIGH_DONE: CLR F0 Make F0=0 to indicate start of low section CLR PWMPIN Make PWM output pin low MOV A, #0FFH Move FFH (255) to A CLR C Clear C (the carry bit) so it does not affect the subtraction SUBB A, R7 Subtract R7 from A. If for high level we load a va lue X in TH0 then for low level TH0 will be loaded with 255-X so that total rema ins as 255. Values for high and low level will be lo aded in such a way that total delay remains same. As we have discussed in the introduction of PWM that by changing the Ton time, we can vary the width of square wave keepi ng same time period of the square wave. ![]() Idea Behind Implementation The basic idea behind PWM implementation on 8051 is using timers and switching p ort pin high/low at defined intervals. Now lets take a look at the practical impl ementation of PWM on microcontrollers. if Ton is Ttotal then Vout is Vin or say maximum. ![]() So you can see from the final equation the output voltage can be directly varied by varying the Ton value. ![]() Let Ttotal be time period of the wave such that, Duty cycle of a square wave is defined as The output voltage varies with duty cycle as. Ton is the time for which the output is high and Toff is time for which output i s low. Consider a square wave shown in the figure above. A mathematical explaination of this is given below. â«asic Principal of PWM Pulse-width Modulation is achived with the help of a square wave whose duty cycl e is changed to get a varying voltage output as a result of average value of wav eform. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |