Jump to content
43oh

How to stop doing analogWrite (or how to stop a PWM timer)?


Recommended Posts

What is the preferred way to stop doing analogWrite (PWM) on a pin in Energia?  

 

For instance how should I change a pin to digitalWrite, or change it to input, or to just prepare to stop using the pin?

 

In particular, how do you stop the timer (which is used to generate the PWM)?

 

Studying the code for analogWrite, digitalWrite and pinMode I do not see where PWM timers are ever stopped once they are started.  (I looked at the code on MSP430, Stellaris, and CC3200).  To confirm my impression, I ran a little test on an MSP430.  While I can change mode to output and/or do a digitalWrite to change the pin after doing an analogWrite, it appears that the timer just keeps ticking away, even though it is no longer controlling the pin.

(I haven't tested this on the other platforms or tested whether changing the pin to input stops the timer.)

 

Is there some glitch where the timers have to be left running once started?

 

Why would one care if the timer keeps running?

It uses power (or is this an insignificant amount of power, even on an MSP430 or CC3200 running on a battery).

It might make bookkeeping a little easier if unused timers were stopped.  (e.g. easier to tell which ones could safely be used for other purposes).

 

Thanks.

Link to post
Share on other sites

They are not stopped at all, you are right.  Something we should revisit at some point.  (They also don't update synchronously, and can glitch the PWM waveform when frequent analogWrite()'s are repeated--I have a pull request code patch for this but it does not do anything to help shut off unused timers)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...