8051 pwm generation using timers
how to generate a signal whose on time (initially 1ms) and increments by .1ms everytime we push a button.i.e frst push gives 1.1ms then 1.2ms and so on upto 2ms using timer1 in AT89c51. can anyone suggest an idea??
Replies
-
Harshad ItaliyaI had one example code for PWM running on Timer 0. I will find that out and post here so you can get idea about the working.
Remember It is not giving you exact your timing you have to work on that code to convert according to your timing. -
Harshad Italiya
unsigned char uPWMWidth; bit uPeriod = 0; void timer0() interrupt 1 { if(!uPeriod) { uPeriod = 1; P1_1 = 1; TH0 = uPWMWidth; TF0 = 0; } else { uPeriod = 0; P1_1 = 0; TH0 = 255 - uPWMWidth; TF0 = 0; } } void main() { TMOD = 0; uPWMWidth = 160; EA = 1; ET0 = 1; TR0 = 1; while(1) { //do your other work here Add routine to sense Key and change [B]"uPWMWidth"[/B] variable based on the switch pressed } }
This is the example code Pin 1_1 is used as a PWM pin, this code gives you fixed PWM width if you want to change it in real time then please add Key sense logic in while loop and update uPWMWidth variable and it will change the PWM width on PWM pin.
Hope this will help you #-Link-Snipped-# -
maya2012thanks...😁..for the help
-
Harshad Italiya
Welcome ! You got it working?maya2012thanks...😁..for the help
You are reading an archived discussion.
Related Posts
Hey guys, long time lurker, first time poster, etc etc. Forgive me if this belongs in another forum.
I'm a mining engineer working for a mining company. We design &...
Quote:
For six months each year, the perennially dark and wind-swept plains of the southern polar ice cap have an average temperature of about 58 degrees Fahrenheit below zero. In...
Quote:
WHETHER YOU ARE A HIGH SCHOOL STUDENT, SCIENCE MAJOR IN COLLEGE OR A LIFELONG LEARNER, WORLD SCIENCE U IS WHERE YOU CAN EXPLORE THE WONDERS OF SCIENCE GUIDED BY...
Today at 9:58 PM, earthquake of Richter scale 5.8 rattled eastern India. the epicenter was somewhere in Bay of Bangal. Earthquake tremors were felt at Bihar's Gaya, Patna, Ranchi, Jamshedpur...