PWM not go to zero

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

Hello

I'm using pwm with led.

When i put zero to OCR0A (for instance) the led don't go down : there is a few light...

Somebody have an idea?

Notice that the led is connected direct to avr (with a R).

Thanks

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

I think the usual suggestion is to use the COM bits to complement the PWM output then set OCR0A to the maximum value.

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

Oh, Clawson, still the first to answer...

Thanks, i will try this.

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Ok it's efficient (sorry for my english)
With ocrx=255 : no light.

But i don't understad why...

Could you explain...
This problem come with 8bit counter (counter0 of attiny2313)
No problem with the other counter...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Here's an example of PWM on the ATtiny85. I'm sure you could adapt it to the 2313.

Mistakes I've made

  • Not copying the .data section to hex using avr-objcopy
  • Overflowing RAM in an ATtiny2313 (128 Bytes)

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

Quote:

Could you explain...
This problem come with 8bit counter (counter0 of attiny2313)
No problem with the other counter...

Then you need to show us the setup for both.

If you are using the full range of the counter, the 8-bit counter will be high 1 of 256 counts--about 1/2% You get some light. On the 16-bit, 1/65536 or about 0.0015%. You can't see that light.

Quote:

But i don't understad why...

What part don't you understand? have you looked at the signals with an oscilloscope?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I'm pretty certain that the data sheet explains that OCR = 0 will actually still give a pulse of one counter clock, which, as The Usch explained, will still be visible using 8 bit PWM.

You can, of course, trap the zero condition and set the output pin for normal operation in this case.
However, Cliff's solution of inverting the sense is probably easier.

Quebracho seems to be the hardest wood.

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

thanks...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

could I use this principle at the and of your example for getting PWM to 0 when the AD convertion is at the lowest level in my source?

 

regards,

Bert

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

Be_logic wrote:
could I use this principle at the and of your example for getting PWM to 0 when the AD convertion is at the lowest level in my source?

Sigh--I see another request; I answered in that thread as well as above.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

sigh, I can ask questions where I like I think?

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

I can ask questions where I like I think?

Not necessarily, if the topic is repeated the thread gets locked. Anyway your question in 9 was to a thread that has been unused for 6/7 years and unlikely to get a reply from the OP.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:
Anyway your question in 9 was to a thread that has been unused for 6/7 years and unlikely to get a reply from the OP.

What is interesting, John, as I mentioned it is probably the same situation.  And OP did dig out the related thread.  The "sigh" is that in both this thread and the other one the probable solution was outlined -- inverted PWM.  Yet Be_logic seems to want more. 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Well, there is the method mentioned in #7 that Arduino uses -- if you set the

"Analog" output to 0 it disables the timer pin and sets the PORT bit to 0.

 

--Mike

 

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

Hi, hopefully the code snippit is enough so when I change adc = ADC_MIN; into adc=0, lowest PWM value is the same, so not zero.

Where can I find an example about #7 trapping the zero condition.

 

The trouble is that the potentiometer on de AD input has a lowest value of 60 Ohm and at that lowest position PWM should be zero.

 

Sorry I could not send the code snippit with <> because I don't know how to use it.

e.g. It's impossible to paste in the window that opens after klicking <>

 

regards,

Bert

 

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

You were told in this thread and the other one how to do it -- use inverted PWM.  I'd guess it has been brought up many times.  It was also explained why it happens.  Yes, if you care to you can turn the timer/PWM off and on.  Often/usually it is simpler just to use inverted PWM if there is no hard requirement for 100% duty.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
I'd guess it has been brought up many times.

https://www.avrfreaks.net/forum/... with a datasheet quote

https://www.avrfreaks.net/forum/... with links to prior

https://www.avrfreaks.net/forum/...

https://www.avrfreaks.net/forum/... see title -- applicable?

https://www.avrfreaks.net/forum/... good explanation in #6

...

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Many thanks!

 

Bert