A short blip when enabling a hardware PWM on ATtiny, why?

20 posts / 0 new
Last post
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to use an ATtiny85 to charleplex some LEDs, and using a hardware timer to generate PWM for a 'fade up / fade down' effect. Code attached.

Randomly, there's an initial "blip" pulse of random length before the correct pulse train starts when enabling PWM. The blip measures from 0 to 2.040 ms in length. This is causing a quick strobe (flash) before the LED is 'fading' up.

What's causing this blip?

Attachment(s): 

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

First thing that jumps out at me is

#define F_CPU 8000000UL  // 1 MHz

Are you running at 8MHz or 1MHz? I'm not sure if this would cause your problem but would at minimum screw up your delay() calls. Maybe something isn't timing like you think.

Hope I can help,
Mike
My Robotics/AVR Blog

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

Sorry, I'm running at 8Mhz, I just forgot to change the comment from the cut&paste.

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

In fadeInOut, why do you call setDuty twice?

Maybe not related, but shouldn't have things there without a reason.

Hope I can help,
Mike
My Robotics/AVR Blog

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

Err, I originally tried this in an Arduino enviroment using both pwm channels and was observing the same problem. I (roughly) brought they code out of Arduino to eliminate it as the cause. But I was sloppy and missed removing the second call to what would be the second pin.

Just tried removing it now, still same problem.

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

madsci1016 wrote:
Err, I originally tried this in an Arduino enviroment using both pwm channels and was observing the same problem. I (roughly) brought they code out of Arduino to eliminate it as the cause. But I was sloppy and missed removing the second call to what would be the second pin.

Just tried removing it now, still same problem.


Yeah I thought it looked odd.

If I was debugging it in front of me I'd have to bring the code a little simpler and then start pulling pieces off until it went away, then poke around that spot a bit.

Unfortunately I can't really see the reason by just skimming your code.

Best of luck. I'm sure someone will chime in soon.

Hope I can help,
Mike
My Robotics/AVR Blog

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

Why are you not including ?

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

Why are you not including ?

Presumably because:

C:\WinAVR-20100110\avr\include\avr>grep "#include " interrupt.h
#include 

 

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

12 downloads and no other thoughts?

Sorry it's messy. When I get back from traveling for work I'll clean it up and simplify it. I was hoping it was something easy like "you forgot poking register ABC"

The best way to summarize what I see is that it's like when I enable the PWM, the IO pin goes HIGH (or LOW) until the timer overflows, then starts correctly running PWM. The manual mentioned something like this in the section on resetting the pre-scaler, and I followed the suggestion (I think) to correct for this, but no change.

I had a temp fix, where I enabled the PWM when the DDR register was set for input, delayed 10ms, then enabled the IO as output. This 'skips' the PWM blip, but i'd really like to figure out why it's doing it in the first place.

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

Well, according to this guy:

http://www.societyofrobots.com/robotforum/index.php?topic=12603.msg94580#msg94580

It seems this is just a thing with ATtiny PWM.

I think I'm just going to do software PWM, since I won't be doing anything else.

Thanks guys for taking the time to look.

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

Looking at your code, you do not start any PWM until you call setDuty() after the first delay(1000).

When you disable COM0A1 bit, the o/p pin reverts to GPIO.

You could achieve your effects in a simpler manner.

David.

Pages