Go Down

Topic: [SOLVED] Slowing Down Of Lighting Up Led Diode On Pin Of Shield With Chip. (Read 496 times) previous topic - next topic

The_Specialist

Dear,

I m writing a program for stair lighting

The problem is that it's not running smooth.. A specially on pin 5 en 6.  I think it because of..
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

Notes and Warnings
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.

I m working with 3 74HC595D chips and looking for day's to equalize the speed of brighting up the leds for all pins . Does anybody know how to solve this problem with an example please?

Code: [Select]
#define F_CPU 16000000UL  // 4 MHz //1000000UL  // 1 MHz
//#define F_CPU 14.7456E6
#include <util/delay.h>

int calibrationTime = 30;

#define SHIFTPWM_NOSPI                            
const int ShiftPWM_dataPin = 6;                   //  Do not change!!!
const int ShiftPWM_clockPin = 7;                  //  Do not change!!!
const int ShiftPWM_latchPin = 8;                  //  Do not change!!!
const int outputEnablePin = 3;
byte leds = 0; // Variable to hold the pattern of which LEDs are currently turned on or off

#include <ShiftPWM.h>//moet achter de pins staan
const bool ShiftPWM_invertOutputs = false;
const bool ShiftPWM_balanceLoad = false;//true;// false;
unsigned char pwmFrequency = 75;//75;                  // These values affect the load of ShiftPWM
unsigned int numRegisters = 3;                    // Number of shift registers Do not change!!!
unsigned int numOutputs = numRegisters * 8;
unsigned int numRGBLeds = numRegisters * 8 / 3;
unsigned char maxBrightness = 81;                // Here you set the number of brightness levels. Adjust(0-255)!!
int numberOfstairs = 9;                           // Setup Number of Your stairs. Adjust up to 24 !!!!
byte faidoutSpeed = 8;                              // Lichten aan snelheid in miliseconden ..let op gaat in 100stappen aan dus wacht niet te lang :-)
byte faidinSpeed = 12;
boolean sensorUpperActive;
boolean sensorBottomActive;
boolean sensorLightDark;
boolean BlnCheckPirSensor;

#define AnalogePinA0 A0
#define AnalogePinA1 A1//upper
#define AnalogePinA2 A2//Bottom
#define AnalogePinA3 A3
#define AnalogePinA4 A4
#define AnalogePinA5 A5//light
#define AnalogePinA6 A6
#define AnalogePinA7 A7

#define DigitalePinD2 2
#define DigitalePinD3 3
#define DigitalePinD4 4
#define DigitalePinD5 5
#define DigitalePinD6 6
#define DigitalePinD7 7
#define DigitalePinD8 8
#define DigitalePinD9 9
#define DigitalePinD10 10
#define DigitalePinD11 11
#define DigitalePinD12 12
#define DigitalePinD13 13


void setup()
{

 //Serial.begin(9600);
 ////Serial.begin(115200);
 ////Serial.begin(115200);
 ////Serial.setTimeout(0);
 //while (!Serial);
 //Serial.println("Debuging begint");

 pinMode(LED_BUILTIN, OUTPUT); //Blinking led on board //voor led on shield te laten blinken als het programma 1keer geladen is
 ShiftPWM.SetAmountOfRegisters(numRegisters);
 ShiftPWM.Start(pwmFrequency, maxBrightness);
 //hier kunnen we kiezen tussen input en output
 //dit zijn de analoge pins op de nano chip
 //pinMode(AnalogepinA0, INPUT);
 pinMode(AnalogePinA1, INPUT);
 pinMode(AnalogePinA2, INPUT);
 //pinMode(AnalogepinA3, INPUT); // To trigger an interrupt on nano
 //pinMode(AnalogepinA4, INPUT);
 pinMode(AnalogePinA5, INPUT);
 //pinMode(AnalogepinA6, INPUT);
 //pinMode(AnalogepinA7, INPUT);

 //3, 5, 6, 9, 11 Provides 8 - bit PWM output. for nano  These pins provide an 8-bit PWM output by using analogWrite() function.
 pinMode(DigitalePinD2, OUTPUT); // To trigger an interrupt on nano
 pinMode(DigitalePinD3, OUTPUT); //pwm // To trigger an interrupt on nano
 pinMode(DigitalePinD4, OUTPUT);
 pinMode(DigitalePinD5, OUTPUT); //pwm
 pinMode(DigitalePinD6, OUTPUT); //pwm
 pinMode(DigitalePinD7, OUTPUT);
 pinMode(DigitalePinD8, OUTPUT);
 pinMode(DigitalePinD9, OUTPUT); //pwm
 pinMode(DigitalePinD10, OUTPUT);
 pinMode(DigitalePinD11, OUTPUT); //pwm
 pinMode(DigitalePinD12, OUTPUT);
 pinMode(DigitalePinD13, OUTPUT);
}
void loop()
{
 MainSub();
}
void MainSub()
{
 sensorBottomActive = false;
 sensorUpperActive = false;
 sensorLightDark = false;
 sensorBottomActive = CheckPirSensorActive(AnalogePinA2);
 sensorLightDark = CheckPirSensorActive(AnalogePinA5);
 sensorUpperActive = CheckPirSensorActive(AnalogePinA1);
 if (sensorLightDark == true) //pin is bij donker is hij hoog //pin is bij veel licht laag
 {
 if (sensorBottomActive == false && sensorUpperActive == false) //noodverlichting
 {
 EmergencyLights();
 }
 else
 {
 if (sensorBottomActive == true && sensorUpperActive == false)
 {
 LedsOnOffFromDown();
 }
 }
 }
 if (sensorLightDark == false)
 {
 LedsAllOff();
 }
}
void EmergencyLights()
{
 SingleLedAan(numberOfstairs, maxBrightness);
 SingleLedAan(numberOfstairs - 1, maxBrightness);
 for (int i = 3; i < (numberOfstairs - 3); i++)//Doof leds ertussen die nog branden
 {
 SingleLedUit(i);
 }
 SingleLedAan(1, maxBrightness);
 SingleLedAan(2, maxBrightness);
}
void LedsOnOffFromDown()
{
 for (int i = 3; i <= numberOfstairs; i++)
 {
 SingleLedUit(i);
 }
 LedsFromDownOn();
 LedsFromDownOff(); //Stairs on from down to up
}
void LedsFromDownOn()
{
 for (int i = 1; i <= numberOfstairs; i++)//Stairs on from down to up
 {
 SingleLedDimmingOn(i);
 }

}
void LedsFromDownOff()
{
 for (int i = 1; i <= numberOfstairs - 2; i++)
 {
 sensorUpperActive = CheckPirSensorActive(AnalogePinA1);
 sensorBottomActive = CheckPirSensorActive(AnalogePinA2);
 if (sensorBottomActive == true || sensorUpperActive == true)
 {
 break;
 }

 SingleLedDimmingOff(i);
 }
}

void SingleLedDimmingOn(int LedOnPin)
{
 for (int a = 0; a < maxBrightness; a++)
 {
 ShiftPWM.SetOne(LedOnPin, a); //

 delayMicroseconds(faidoutSpeed);
 }

}
void SingleLedDimmingOff(int LedOffPin)
{
 //Serial.println("Single led OFF onethird");
 for (int a = maxBrightness; a >= 0; a--)
 {
 ShiftPWM.SetOne(LedOffPin, a);
 //analogWrite(i + 2, a);
 if (a == 0)
 {
 //Serial.println("led off");//+i);
 ShiftPWM.SetOne(LedOffPin, 0);
 //analogWrite(i + 2, a);
 }
 //delay(faidinSpeed);
 //waitTime = faidinSpeed;
 //wait();
 //reset();
 //delay(faidinSpeed);
 //Fade down
 //for (int i = 255; i>0; i--){
 // OCR0A = i;        //Set new duty cycle value
 // _delay_ms(50);    //delay a litle bit
 //}
 //_delay_ms(faidinSpeed);
 //my_delay_ms(faidinSpeed);
 delayMicroseconds(faidinSpeed);

 }
 //return true;
}

void SingleLedAan(int LedOnPin, int Brightness)
{
 ShiftPWM.SetOne(LedOnPin, Brightness); //
}
void SingleLedUit(int LedOnPin)
{
 ShiftPWM.SetOne(LedOnPin, 0);
}
boolean CheckPirSensorActive(uint8_t BlnCheckPirSensorPin)
{
 boolean BlnCheckPirSensor = false;
 int IntPirValue = analogRead(BlnCheckPirSensorPin);
 if (IntPirValue >= 450) {  
 BlnCheckPirSensor = true;
 }
 else
 {
 BlnCheckPirSensor = false;
 }
 return BlnCheckPirSensor;
}
void LedsAllOff() {
 for (int i = numberOfstairs; i >= 1; i--){
 ShiftPWM.SetOne(i, 0);

 }

}






TomGeorge

Everything runs on smoke, let the smoke out, it stops running....

The_Specialist

I am using a pre assembled pcb. They are embedded. Don't want to put time in developing a board for now. Thanks for your notice.

septillion

Can you post a drawing (circuit, not a Fritzing breadboard mess please) of how it's connected?

millis() uses timer0() free running so there is no effect on the hardware PWM of the timer.

What can cause flicker is calling analogWrite() to often. This might be more noticeable on pin 5 and 6 because they are faster and/or in fast PWM.

Couple of tips:

Variable names are there to help YOU, the compiler doesn't care less. So doing stuff like
Code: [Select]
#define DigitalePinD2 2
is the most useless ever. If you don't want programming aid, fine, just use 2. If you do want to have readable code, give it a useful name what it does in your program. Now it's just a nightmare to read. ;)

En het mengen van Engels en Nederlands commentaar helpt ook niet ;) En daar je dit in het internationale deel plaatst is Engels wel zo netjes.*


*Mixing Dutch and English comments is not very helpful. And because you post this in the international part, English would be the most logical choice.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

The_Specialist

#4
Mar 10, 2019, 09:23 pm Last Edit: Mar 11, 2019, 08:09 pm by The_Specialist
It's not Flickering. Take a look at the video. You don't see flickering with the naked eye. On the video you will see flickering butt pretend there not.

You will see led 5 en 6 goes equaly on.

https://youtu.be/tIlaynspz4A

What can I do to solve this issue?

septillion

Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed


septillion

I know what you want to know. Just ask..
I did, see reply 3 ;) But I still don't see a schematic which makes it quite hard...

For example, I don't see a link between hardware PWM on pins 5 and 6 and having everything controlled by a 595  :smiley-roll:

And if you don't have a schematic because you use a third party shield, than it's time to ask the maker of that shield, not us...
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

TomGeorge

Hi,
Have you got the 595 fitted with bypass capacitors?

In post #6, do you have that board?
I would call that YouTube clip a Primary / Junior School   show and tell, without the tell.
It shows you what it possibly can do, but doesn't tell you how it is done.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?


What model Arduino are you using?


Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

The_Specialist

#9
Mar 11, 2019, 07:57 pm Last Edit: Mar 11, 2019, 08:37 pm by The_Specialist
Quote
Welcome to the forum.
Thank you.

Quote
Is there a reason you didn't use;
https://www.adafruit.com/product/1411

It's a nice board but no +10v outputs.

Quote
Have you got the 595 fitted with bypass capacitors?
There is a capacitor on the 595.

Quote
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
it's a back an front circuit board.. too much to draw. And I don't have a cad drawing for now.
Actually I don't think it's a hardware failure because when it boots it runs nice and suddenly it start to go faster or slower in pin 5 or 6. When I m modifying "delay" in the code, I see better out come, but after a while the same problem returns. I think its somewhere in my code. Always the same problem like you can see in the video.

Quote
In post #6, do you have that board?
I would call that YouTube clip a Primary / Junior School   show and tell, without the tell.
It shows you what it possibly can do, but doesn't tell you how it is done.
That video is mine. Can you see what I am trying to illustrate?


The_Specialist

Quote
Quote
Is there a reason you didn't use;
https://www.adafruit.com/product/1411

It's a nice board but no +10v outputs.
I see now. Which components do you advice to dim 16 ledsstrips 12v (power supply I already have). I see the board has just one chip. Is it powerful enough to run dim cycles?

The_Specialist

I have uploaded the original example program and the problem not appearance with this code
https://stairsautomation.wixsite.com/home/asl-shield

The difference I see is the code below.
Code: [Select]
void BottomTriggerFire() {

if (analogRead(sensorBottom_PIN) >= 500) {      //Depend of the sensor type, if 0 when triggered ,than change the comparison to opposite value
sensorBottomActive = true;
}
}

void UpperTrigerFire() {

if (analogRead(sensorUpper_PIN) >= 500) {
sensorUpperActive = true;
}
}

septillion

Actually I don't think it's a hardware failure because when it boots it runs nice
We're not saying it is. Probably isn't. But without understanding the hardware it's just impossible to give you an answer ;) Especially when you post snippets. We still don't have a clue how hardware PWM / timer0 has anything to do with leds connected to a 595. So if you're to lazy to draw the circuit I suggest you contact the designer of the board with this question :)

And no, the PCA9685 (Adafruit board) can't drive ledstrips directly. But the 74HC595 can't either ;) You can, however, connect that to transistors again.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

The_Specialist

SOLVED IT!!! You guys where right. The problem was my led circuit. Bad wire. I buyed a new solder board. The previous one was worn out!

I found it out buy trying with I code I know would work. The problem didn't appear immediately! When I changed the brightness (in code I know would work).. the slowing down problem started. So I know the code wasn't the problem.

Conclusion: Change brightness for testing and check your wires twice or triple.

Thank you very much for your affords.



Paul__B


Go Up