We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am doing a project in 8051 mc in which I have to generate atleast 5 PWM signals with varying period and duration. Is it possible? What is the logic to be used. Is anyone having the assembly code in 8051 or in C language for this? If so please send it to me at epey2p158@nitc.ac.in thanks in advance.
I exactly want what Mr.Graham told. A software method. I don't want a very fast system. The period can be even upto 2 second. But the duration of PWM about 20-100ms. Is it possible to have such a system? Is it possible using only one timer? Can you explain some logic for that. Actually, I want that both period and duration of all the 5 PWMs to be different. The values for duration and period for 5 signals(5*2=10 values) should be taken from some memory location where we are already stored the corresponding values for period and duration. One way or another, you need five timers - one for each PWM. You don't have five hardware timers, so it is necessary to "simulate" these timers in software. Each timer is simply a variable in memory. If it helps, think of each timer as being like the second hand on a clock. The second hand moves with every tick and after 60 ticks it is back where it started. To generate a PWM from the second hand of a clock, the output is simply a matter of how far round the clock the second hand has travelled. To put out 25% PWM, the output will be on for the first 15 seconds and then off for 45 seconds, and so on. The hardware timer you do have can provide a "tick" that triggers an interrupt. It is slightly more efficient to count down than up, therefore I suggest a simulated timer that runs backwards. You will need something like this for each PWM timer:
MOV A,pwm_timer_n DJNZ A,xxx MOV A,#pwm_timer_n_period xxx: MOV pwm_timer_n,A
MOV A,pwm_timer_n CJNE A,pwm_on_time_n,$+3 MOV pwm_output_bit,C