Can AVR's PWM go to zero?

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I'm trying to make a sign for our RV.  Solar charged (I hope, so far, no joy).  The processor will read the output of the solar cell, and based on the light sensed, change the PWM signal to the LEDs in the sign.   So at full light, the LEDs are off, then as evening approaches, the LEDs are lit up more, until darkness when the LED's are at a minimum (because in full darkness, the sign doesn't need to be nearly as bright to be seen.  But at dusk, it need to be a little bit brighter to be seen in the remaining light).

 

But I do have one question, and that is, will the PWM output go to zero, like, turn off?  Or is the minimum a single count (or something else?).

 

I know I can turn it off manually.   I'm just wondering if I can pick a value, and the PWM signal will go to zero.

 

I'm struggling a bit with the timers.   I get the basics, like capture.  But kinda struggling with the PWM bits.   Seeing some odd stuff, like lots of jitter.   I can't seem to relate different things, like output to various registers.  Like "changing this, has this effect".   That part, I'll get, I just need to play with it more and keep reading some of the tutorials that are here. (Dean's tutorial has helped a good bit with the basics, and another titled "Using AVR Timers/Counters" seems to be more of what I'm looking for (dude, sign yer work!)   More time with a scope will help  (finally got a new one!  yay!)

 

One of the things I am seeing, is the PWM always seems to have a pulse, like there is no zero.  That's why I ask.   

Just gettin' started, again....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With 'Fast PWM', you have a choice.  You can use normal compare output mode which gets you duty cycles from 1/256 through 256/256, or you can use inverting compare output mode which gets you duty cycles from 255/256 through 0/256.

 

With 'Phase Correct PWM' and 'Phase and Frequency Correct PWM', you get both full off and full on, with 0/255 through 255/255.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, thank you for that.   I'm pretty sure I couldn't get the zero because of the numbers I had.

 

I need to spend a lot more time with it, but may not be able to until next week.   Too much stuff I don't want to do this weekend.... bah!   Start with mode one, and just try everything, then mode two... etc...

 

Beastly little things though.

Just gettin' started, again....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 which gets you duty cycles from 1/256

IIRC there are a few AVRs that don't have 0 PWM output as an option.

The Timer/Counter module has a "feature" where it still puts out a pulse when the PWM value is set to zero.

It IS documented in the data sheet.

The first time one encounters it, however, it is quite a surprise.

 

The workaround for this hardware bug is to test for 0 PWM and if so then invert the output and set it for 255, when then gives a 0 output.

Or set the PWM off and simple set the bit to output, low.

 

An O'scope is incredibly useful in learning about the PWM options, and its quirks.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That kinda makes sense.  The way *I* see it, to modulate something, you have to have something in the first place.  If there's no output, it's not "modulated" at all.

 

That's one reason I'm having a hard time, I just not got to the point where I can put a scope on it and check it out and see what's happening.   Too many, um, conflicts around here to actually sit here and work on something like I want to.  My fiance's girl child is staying with us (or should I say "freeloading" with us....).

 

I'm sure I'm going to have to check the values of the solar cell and adjust the output accordingly anyway.

Just gettin' started, again....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Joey said, the trick is to use inverted output, so you get 255 to 0 instead of 1 to 256.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The voltage output of a solar cell saturates at low lux values (ie. after dawn and before dusk) and it will also vary depending on how much current is being drawn from it.
LEDs have a reasonaby linear lux-output versus average-current relationship.
The human-eye has a logarithmic response to lux.
TLDR ;
Create a LUT with 4 (or so) values to drive your PWM.