EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Hi Ajish, Here is the bad

Hi Ajish, Here is the bad

|

Microcontroller › 8051 › GENERATING VARIABLE PWM › Hi Ajish, Here is the bad

August 6, 2012 at 6:47 am #8406
Varun Srivastava
Participant

Hi Ajish,

 

Here is the bad news…i tried on implementing TIMERS btu didnt succeeded…nd then came back again to FOR LOOPs…did a very little change to the logic provided by….

 

The Program is lyk dis…

 

#include <reg51.h>
sbit INCREASE = P2^6;
sbit DECREASE = P2^7;
sbit MTR = P1^0;
void MSDelay(int value);
void main()
{
unsigned int on,off;
on=20;                                                                                             //initial value of ON time delay
off=0;                                                                                              //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(INCREASE==0 && on<20)                                                 //if key increase is down check whether it has max value or not
    {

        on++;
        off–;                                                                                     //—-increment ON time delay if it is not maximum–//

       //


//
    }
    else if (TWO==0 && on>0)                                                     // if key decrease is down check whether it ON time delay >0//
    {

        on–;
        off++;                                                                                  //—-decrement ON time delay if it is not zero—-//

        //


//
    }
}

}
void MSDelay(int value)                                                               // Delay function //
{
int x;
for(x=0;x<=value;x++);
}

 

 

 

Now the above thing works very fine in Multisim but when i tried with my hardware….i m getting only two states either my load goes fully on or fully off….no in between states…

 

Now i dnt knw where the problem is…is it possible that the case may be of switch debounce…!!!

 

 

expecting your reply soon…thnx

RSS Recent Posts

  • RC Electronic Speed Control Capacitors February 11, 2026
  • CR2/CR123A Batteries In Projects February 11, 2026
  • Variable audio oscillator February 11, 2026
  • XLR splitter to mono. February 11, 2026
  • To couple or decouple February 10, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise