Weatherproof Flexistrips Flickering with PWM
Moderators: adafruit_support_bill, adafruit

Weatherproof Flexistrips Flickering with PWM

by cjbaar on Sat Mar 23, 2013 6:41 pm

So my buddy picked up some of the 60/m 12v led strips for a lighting project. We've been playing with connecting it to an arduino uno, per the tutorials, using a 12v power supply and three N-channel mosfets.

We have been experiencing weird flickering effects on the blue LEDs. If the blue LEDs are run at max (255), they are steady. If the blue LEDs are run at any level of PWM on their own (with red and green off), they are steady. However, when we try to make any color using blue PWM between 1 and about 250, there is a noticeable flicker. Only the blue channel flickers, as we can see the color change.

We have tried swapping mosfets, using different arduino ports... and have tested this with multiple power supplies and multiple strips. I unable to determine what is causing this, or -- even more confusing -- why it is only affecting the blue channel.

Has anyone else experienced this (or similar) behaviour? This is being used for a permanent access lighting installation, so we need to find some way to eliminate the flicker.

Thanks!
--CJ
cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 4:58 pm

Re: Weatherproof Flexistrips Flickering with PWM

by cjbaar on Sat Mar 23, 2013 7:47 pm

Okay. After much experimentation, we have made a few more determinations. This does not appear to have anything to do with the strips themselves, but rather an issue with PWM on the Arduino. Specifically, on the lower port.

If we move the RGB pins up to 9,10,11... everything works fine. If we use any combination that includes two pins on the lower port, the flickering occurs. Using any combination with only one pin on the lower port works fine.

I still have no idea what's really going on, but this does appear to be an Arduino issue, not an issue with the strips. However, if anyone has any ideas on this, they would be very welcome. The installation was supposed to use two independent strips, so we still need all six PWM pins. We have successfully tested this on a Mega, and it works fine with any combination of pins. However, I would hate to have to waste a mega for such a simple project.
cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 4:58 pm

Re: Weatherproof Flexistrips Flickering with PWM

by adafruit_support_bill on Sun Mar 24, 2013 6:13 am

It has to do with the PWM frequencies. If you combine two slightly different frequencies from different timers you get a "beat frequency". It works with light in much the same way as sound: http://en.wikipedia.org/wiki/Beat_(acoustics)
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: Weatherproof Flexistrips Flickering with PWM

by cjbaar on Sun Mar 24, 2013 10:16 am

So what is the solution for using these strips successfully? I understand that different frequencies can overlap, but that doesn't explain why it is only doing it on portA of an arduino uno. Why is fine on the upper port, or on a mega? Ad, if different frequencies are the cause, why does it flicker when all three are set to the same frequency? Clearly the arduino approach shown in the tutorial is not usable, so what would be a better setup for using these strips?
Thanks.
cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 4:58 pm

Re: Weatherproof Flexistrips Flickering with PWM

by adafruit_support_rick on Sun Mar 24, 2013 11:26 am

The Arduino analogWrite reference page notes an issue with pins 5 and 6:
Notes and Known Issues
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.


That doesn't exactly sound the same as what you're describing, but it may be a clue.

What kind of arduino are you using?
User avatar
adafruit_support_rick
 
Posts: 11661
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: Weatherproof Flexistrips Flickering with PWM

by adafruit_support_bill on Sun Mar 24, 2013 11:32 am

You have three different timers on the UNO. pins 5 & 6 are controlled by timer 0. 9 & 10 by timer 1. 3 & 11 by timer 2.
http://playground.arduino.cc/Main/TimerPWMCheatsheet

why does it flicker when all three are set to the same frequency?

How are you setting the frequency?
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: Weatherproof Flexistrips Flickering with PWM

by cjbaar on Mon Mar 25, 2013 8:19 pm

Code: Select all | TOGGLE FULL SIZE
analogWrite(REDPIN, 50);
analogWrite(GREENPIN, 50);
analogWrite(BLUEPIN, 50);


DB... your explanation makes the most sense, since it does appear to be pin 5 and 6 causing the problem. Any combination of 3,9,10,11 does not flicker. I might recommend updating the tutorial to use 9,10,11... and make note of the problem when using the lower port. I'm kind of surprised, really, that no one else has run into this.
cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 4:58 pm

Re: Weatherproof Flexistrips Flickering with PWM

by adafruit_support_bill on Mon Mar 25, 2013 8:38 pm

Code: Select all | TOGGLE FULL SIZE
analogWrite(REDPIN, 50);
analogWrite(GREENPIN, 50);
analogWrite(BLUEPIN, 50);

AnalogWrite does not change the frequency, it changes the duty cycle. The only way to change the timer frequency is by writing to the timer control registers as in the link I posted earlier.
http://arduino.cc/en/Reference/analogWrite
User avatar
adafruit_support_bill
 
Posts: 29182
Joined: Sat Feb 07, 2009 9:11 am

Re: Weatherproof Flexistrips Flickering with PWM

by cjbaar on Tue Mar 26, 2013 10:34 pm

OK; thanks. Guess I'm wasn't clear on the specific use of the term "frequency." I have adjusted the timer based on the examples shown, using:
Code: Select all | TOGGLE FULL SIZE
 TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00);


No flicker now. I'd still recommend that be added to the example sketch.
Thanks!
cjbaar
 
Posts: 73
Joined: Fri Aug 26, 2011 4:58 pm