Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@harshad-ukH5ww • May 20, 2014
I 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-ukH5ww • May 20, 2014
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-# -
@maya2012-GhITdp • Jun 4, 2014
thanks...😁..for the help -
@harshad-ukH5ww • Jun 4, 2014
Welcome ! You got it working?maya2012thanks...😁..for the help