Go Down

Topic: LED flickering - please advise (Read 628 times) previous topic - next topic

Shadowed

Hello to all Arduiners !

I was thinking about the pulsing LED issue for a long time, but cant see the reason, though the program and the hardware is so simple that I dont even know where to look... So, the schematics is very basic, RGB LED on pins 3, 5 and 6, common anode via resistor hooked to +5V pin. Pot's on pins A0, A1 and A2. The link to video:

www.youtube.com/watch?v=RjVit-2rtu0

When controlling separate colors - everything seems to be OK, though I had LEDs flashing randomly, for example, red on 50%, green and blue at 0%, but still there were G and B flashing randomly (together) and brightly. Maybe due to bad contact in the board... Unlikely.
From 25th second in the video you can see the LED flickering, this is not a camera thing, it is really flickering, or pulsing, call it what ever you want... Why could this be happening ?
Program is very basic, generally one line in the loop per POT/LED:

analogWrite (red_led, map (analogRead (red_pot), 0, 1023, 0, 255));

So, what is creating the pulsing/flickering...?

UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Shadowed

Uch, first time in my life I did the schematics in Paint :D, but Eagle is at home, so dont want to waist 8 hours till I get there... So, the schematics:

And the program code:
Code: [Select]
// Iejimai

const int raudonas_pot = A0;          // ********************************
const int zalias_pot = A1;            // * Nustatom potenciometru pinus *
const int melynas_pot = A2;           // ********************************

// Isejimai

const int raudonas_led = 3;           // ********************************
const int zalias_led = 5;             // * Nustatom PWM isejimus LEDams *
const int melynas_led = 6;            // ********************************

void setup() {
  pinMode (raudonas_led, OUTPUT);     // ***************************************
  pinMode (zalias_led, OUTPUT);       // * Nustatom, kad LEDu pinai - isejimai *
  pinMode (melynas_led, OUTPUT);      // ***************************************
  digitalWrite (raudonas_led, HIGH);  // ***************************************
  digitalWrite (zalias_led, HIGH);    // * Inicializuojam LEDus (isjungiam)    *
  digitalWrite (melynas_led, HIGH);   // ***************************************
}

void loop() {

  analogWrite (raudonas_led, map (analogRead (raudonas_pot), 0, 1023, 0, 255));
  analogWrite (zalias_led, map (analogRead (zalias_pot), 0, 1023, 0, 255));
  analogWrite (melynas_led, map (analogRead (melynas_pot), 0, 1023, 0, 255));
}

BulldogLowell

I suspect that since the separate PWM frequencies are not in phase that you may be seeing sort of a Moiré effect.

The "flickering" may be able to be reduced if you muck about with the timers driving the PWM.


Shadowed

Had the exact same idea in the end of couple of hours experimenting with HW and SW, about not matching PWMs, just did not knew the name of effect. Thanks Bulldog !

Shadowed

But then again - check the video:

www.youtube.com/watch?v=U42wC47hxUI

R and G channels at some small step, maybe 5%, R at 0%, bul still R and other flashes at full (maybe) power. Got those flashes even at all R, G and B channels set to 0%.

PaulMurrayCbr

Weird as hell. You hook the cathose to the pin, so that means the led goes on when  the PWM is low. NOw the question is: when the PWM is low, what's the resistance between it and ground? Is it tied to ground? Is it floating? Will doing this fry something important?

Shadowed

You're right, LED is ON when PWM low. I am not sure about resistance between GND and, lets call it - pin output, but still, according to data sheet pin can sink and source, holding up to 40 mA, with 120R it should be around 20-25 mA, so in the safe zone. There are some more limitations considering maximum Amps, but it applies when most of pins are controlling LEDs or something. Even if it is not GND when PWM is low - the current will only be lower.

Go Up