Enable and disable PWM in software

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 I set up a PWM with clock to drive a LED in hardware. I started the PWM and it runs fine.

   

I assumed I could use PWM_Start() and Stop to control control the PWM in software but the LEDs continue to blink after I issue the Stop API command.

   

To get it running, I put a constant "1" logic on Enable of the PWM. My guess is there is another logical function I could drop onto the enable and set it high or low in software. Is this correct and what component do I use.

   

Or, is there a better way to enable and disable the PWM in software.

   

 

   

Thanks

0 Likes
9 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You may control a PWM using a control register. Depending on your underlying hardware (PSoC 4 or 5) there are some signals you can control. A PWM_Stop() disables the component, so the LED cannot blink. If it does as you reported, there must be something wrong.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Several ways -

   

 

   

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

A couple of corrections in comments -

   

 

   

0 Likes
lock attach
Attachments are accessible only for community members.
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Thanks Guys,

   

My code is below and schematic attached.When I run, the Leds start flashing at 500ms rate, I expect them to flash for 5 seconds and stop flashing for 2 seconds.

   

int main()

   

{

   

    CyGlobalIntEnable; 

   

    PWM_Start();

   

    for(;;)

   

    {

   

      CyDelay(5000);  //Leds flash for 5 seconds

   

      PWM_Stop();

   

      CyDelay(2000);  //Leds off for 2 seconds

   

      PWM_Start();

   

    }

   

}

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

Bye the way, how did you get images into the post. Did you copy and paste or use the image box from menu or something? 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you select stuff on schematic, copy to clipboard, and paste using Firefox works

   

most of the time.

   

 

   

Note on PWM you can also use kill input to force PWM out to a known state.

   

I have filed a CASE because datasheets do not discuss what state output is

   

in when a Stop() is issued, or a disable for that materr.

   

 

   

Lastly here is another approach, using PrISM for led driving -

   

 

   

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Will the Prism module output a constant on/off signal at say 500ms? It appears to be referred to a psuedo random number thta would result in "random" pulse output?

   

I suppose the other way is to set the value of te PWM to 0. Could I just use the clock directly onto the LED?

   

It is just to blink an LED in hardware. And enable/disable it as needed.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

The PrISM is a density output, so not a fixed puslewidth.

   

 

   

In PSOC 3/5LP you can route a clock to an output pin.

   

 

   

For PSOC 4 take a look at this               http://www.cypress.com/?rID=80799

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

The particulars back from Cypress -

   

 

   

    

   

          

   

In the Fixed function implementation the pwm ouput retainins the previous state if a Stop() is issued.

   

In UDB implementation the output pwm1 or pwm2 will reset to logic 0.

   

 

   

A doc update will be done inclduing this info.

   

 

   

Regards, Dana.

0 Likes