Ok I spent many hours building an Aquarium LED controller for a friend. I’ve moved from a Nano to the Due. After many hour moving the code over and getting the Due to work with a Nextion touchscreen I thought I had it working. Now this weird problem shows it self!!!
Ok this controller is running a PCA9685 on I2C. The PWM channels ramp up from a starting time and ramp down after an off time. The ramp up worked great on both Nano and Due. However I was only testing the first channel thinking that when I expand to the other channels it would work fine. NOT AT ALL!!
I get MAD flicker as the PWM output is at its peak. The flicker is “cascading”. I mean the 4th channel output has flicker from about 3300-4096 as the PWM is set. The 3rd channel has flicker from about 3800-4096. the 2nd has flicker at about 4000-4096. And the 1st channel has no flicker at all and works fine. These numbers are an estimate and I’m judging it by my eye. How ever the 4th channel defiantly flickers at around 3300 but only when send a new command to set a PWM.
So I started a simple sketch with the basic PWM library and a loop that ramps the PWM up and down. This basic code does indeed make the same flicker!!
#include <Wire.h>
#include "PCA9685.h"
PCA9685 pwmController;
uint16_t brightness;
uint16_t fadeAmount = 5;
void setup()
{
Wire.begin();
Wire.setClock(400000);
pwmController.resetDevices(); // Software resets all PCA9685 devices on Wire line
pwmController.init(B000000); // Address pins A5-A0 set to B000000
pwmController.setPWMFrequency(100); // Default is 200Hz, supports 24Hz to 1526Hz
for (int i = 0; i <= 3; i++)
{
pwmController.setChannelPWM(i, 0);
}
delay(1000);
}
void loop()
{
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 4096)
{
fadeAmount = -fadeAmount;
}
for (int i = 0; i <= 3; i++)
{
pwmController.setChannelPWM(i, brightness);
}
delay(5);
}
I’ve tried changing the pwmController.setPWMFrequency to different values. The flicker is less visible at higher frequencies but is still there no matter the value. I’ve tried changing Wire.setClock to different values. The flicker is less visible at 1mhz and more visible at 100khz. I need to operate below 400khz because I also have an RTC.
Here is a short vid from my phone. You can see the LEDs flicker as the ramping crests the top values and it starts with channel 3 then 2 then 1 and 0 is not effected.
Please discount the shutter effect!!
These are test LEDs running straight from the PWM pin on the PC9685.
Any help with save my sanity :o !! Thx in advance!