Microcontroller › 8051 › GENERATING VARIABLE PWM › Hi Varun,Try the following
Hi Varun,
Try the following code logic. Modifications might be required.
/*
Assume key1 for increasing on time and key2 for decreasing.
*/
on=1; //initial value of ON time delay
off=10; //initial value of OFF time delay
while (1)
{
while(ONE==1 && TWO==1) //when both keys are open
{
//—-generating PWM
//
MTR=1;
MSDelay(on); //applying ON time delay
MTR=0;
MSDelay(off); //applying OFF time delay
//
//
}
//—when any of the key is down, exit from while loop and check which key is down–//
if(ONE==0) //if key on is down
{
//—-increment ON time delay–//
on++;
off–;
//
//
}
else
{
//—-decrement ON time delay-//
on–;
off++;
//
//
}
/*put some delay waiting here, if required*/
}
Kindly update the result asap. And next time when you post a code, make sure that it is properly commented like the one above.Also give a hint about hardware connections, like what would be voltage reading when the key is pressed etc.