LED Fade question

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

I'm using at ATTiny 13a to fade an LED on and off. It's supposed to look like the LED is glowing, but it's also supposed to turn completely off. The sequence is:

Fade in 2s
Fade Out 2s
Off 1s

I've got the PWM working on output B1. The problem is that the fade never turn completely off, and it's kind of a fast fade as well.

I attached my code to show how I'm going about the fade in and out. If anybody has any idea what I'm doing wrong please shoot me some info. Thank you in advance.

(I am working in C, I'm not good with assembly code)

Attachment(s): 

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

Quote:
The problem is that the fade never turn completely off
From the datasheet:
Quote:
The extreme values for the OCR0A Register represents special cases when generating a PWM waveform output in the fast PWM mode. If the OCR0A is set equal to BOTTOM, the output will be a narrow spike for each MAX+1 timer clock cycle.

Quote:
and it's kind of a fast fade as well
The fade you are doing is linear, the response of the eye is not.

Regards,
Steve A.

The Board helps those that help themselves.

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

To elaborate a little, you probably want an exponential dimming curve which you can construct by taking the current value and reducing it by a fixed percentage to get the next value. Try searching for "Weber fraction" and "just noticeable difference". The JND for visual intensity (the largest percentage you'll want to subtract) is somewhat under 8%.

- John

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

Quote:

If the OCR0A is set equal to BOTTOM, the output will be a narrow spike for each MAX+1 timer clock cycle.

I think the usual solution to this is to set the bits to complement the PWM output then when set to "full" it will be fully off.