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 Varun,Try the following

Hi Varun,Try the following

|

Microcontroller › 8051 › GENERATING VARIABLE PWM › Hi Varun,Try the following

July 25, 2012 at 5:22 pm #8330
AJISH ALFRED
Participant

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.

 

RSS Recent Posts

  • Raise your hand if your car had one of these: July 8, 2025
  • Tektronix 2235 channel 1 trace unstable July 8, 2025
  • How to make string LEDs? July 8, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz July 8, 2025
  • The Analog Gods Hate Me July 8, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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