PWM ramp up and down
Re: PWM ramp up and down
I ve uploaded the program with the code you have just posted and now the LEDs should be at 100% but its at 0% now
Re: PWM ramp up and down
here is the pwm code i placed in my pde:
Code: Select all
// Have PWM on from 4p to 1a, with gradual 60 minute ramp up and down starting at the given times
// From 4p to 5p, the PWM will slowly ramp from 20% to 100%
// From 12a to 1a, the PWM will slowly ramp from 100% to 20%
ReefAngel.PWM.SetActinic(PWMSlope(16,0,1,0,20,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(16,0,1,0,20,100,60,ReefAngel.PWM.GetDaylightValue()));
if ((NumMins(hour(now()),minute(now())) < NumMins(16,0)) || (NumMins(hour(now()),minute(now())) > NumMins(1,0)))
{
ReefAngel.PWM.SetDaylight(0);
ReefAngel.PWM.SetActinic(0);
Re: PWM ramp up and down
The controller should do that. What will happen is initially (as in right at startup), it will restore to what the internal memory is set at. Once it starts running through the loop of the functions, it will resume the PWM where it should be based on the PWM calculations.ahmedess wrote:thats great thanks a lot.
About starting up from a power outage I would like the controller to check the time and resume the pwm light schedule instead of using internal memory's stored value.
That's how it has worked for me during all of my testing and I do believe that is how it has worked for everybody else.
curt
Re: PWM ramp up and down
Curt,
Is there anything wrong with the code i posted above? I have this code placed in loop()
Is there anything wrong with the code i posted above? I have this code placed in loop()
Re: PWM ramp up and down
I don't have the drivers connected to my controller yet cause I ve ordered them and they are on their way. The only way I could tell if its working or not is through the display of AP and DP on the LCD screen and the display says they are both Zero when they re supposed to be 100. Is it possible that the displayed values are incorrect and the output is correct?
Re: PWM ramp up and down
Yes, there is a problem with the code above. The additional IF statement is incorrect. That statement will always be true and always set your PWM to 0%.ahmedess wrote:Curt,
Is there anything wrong with the code i posted above? I have this code placed in loop()
Your code says: if the current time is before 4pm OR after 1am, set the PWM to 0%
When this is tested, just about every minute encountered will be after 1am and therefore cause that if statement to evaluate to true. The OR conditional indicates that if either expression is true, the entire condition will be true.
You have some options:
- Remove the IF statement completely and leave the ramp up and down alone
- Remove the IF statement completely and change the ramp up and down to be from 0% to 100%
- Change the IF statement around. Since you are running the PWM from 4p to 1a, your logic in the if statement needs to be changed to work properly
Code: Select all
if ( (NumMins(hour(), minute()) > NumMins(1,0)) &&
(NumMins(hour(), minute()) < NumMins(16, 0)) )
{
ReefAngel.PWM.SetActinic(0);
ReefAngel.PWM.SetDaylight(0);
}
So there are your options with the solutions to them all.
curt
Re: PWM ramp up and down
I still get the displayed values on the LCD screen for AP and DP equal to zero when they should be 100. Is it possible that the problem is with the displayed values?
Re: PWM ramp up and down
It seems that b_s_c1 had the same issue with the displayed values. the problem is that i dont have the LEDs at the moment to test whether the output is correct or not. if its the problem with the displayed value how can I fix it?b_s_c1 wrote: One more question. Should the PWM reading on the RA display be the current output? Mine stays at 0% all the time but the ramp up works correctly.
I changed the scale to 0% to have the ramp up and down turn on and off the lights to avoid the inrush current on the drivers.
Re: PWM ramp up and down
The display gets the value from the PWM every time it is updated. So the value is not just stored and displayed.ahmedess wrote:I still get the displayed values on the LCD screen for AP and DP equal to zero when they should be 100. Is it possible that the problem is with the displayed values?
When I've tested the PWM slope function, I watched the values go up and down appropriately as others have experienced as well.
I do not have anything attached to the PWM to confirm or deny this but it should be working appropriately. My thoughts are that your IF statement is messing things up (even though I sent you an update for it, I never tested it). I want you to remove that IF statement (or comment it out or whatever) and run your code. I think you will find that it will work as it is supposed to. When you start changing the PWM outside the slope function, that's when things can start to get tricky and confusing and other undesired results happen.
Comment out the IF statement and test again (try the first 2 options of my previous post is what I'm saying).
curt
Re: PWM ramp up and down
I've tested with this:
Here is the results:
4:00:00 = 0%
15:59:59 = 0%
16:00:00 = 20%
16:11:40 = 34%
16:27:10 = 56%
16:43.30 = 77%
17:16:40 = 100%
20:03:23 = 100%
23:59:59 = 100%
0:0:0 = 100%
0:11:04 = 86%
0:44:05 = 40%
0:50:08 = 34%
0:59:59 = 22%
1:00:00 = 20%
1:00:59 = 20%
1:01:00 = 0%
4:01:34 = 0%
09:56:48 = 0%
Code: Select all
ReefAngel.PWM.SetActinic(PWMSlope(16,0,1,0,20,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(16,0,1,0,20,100,60,ReefAngel.PWM.GetDaylightValue()));
if ( (NumMins(hour(), minute()) > NumMins(1,0)) &&
(NumMins(hour(), minute()) < NumMins(16, 0)) )
{
ReefAngel.PWM.SetActinic(0);
ReefAngel.PWM.SetDaylight(0);
}
4:00:00 = 0%
15:59:59 = 0%
16:00:00 = 20%
16:11:40 = 34%
16:27:10 = 56%
16:43.30 = 77%
17:16:40 = 100%
20:03:23 = 100%
23:59:59 = 100%
0:0:0 = 100%
0:11:04 = 86%
0:44:05 = 40%
0:50:08 = 34%
0:59:59 = 22%
1:00:00 = 20%
1:00:59 = 20%
1:01:00 = 0%
4:01:34 = 0%
09:56:48 = 0%
Roberto.
Re: PWM ramp up and down
I have tried to ramp from 0 to 100 and I have tried to remove the IF statement but still no change.
Here is what I've found out:
After leaving the code running on the controller for 24 hrs, AP and DP values on the LCD screen have changed according to the correct schedule.
So this is what's happening, If the controller was powered on during the "LED on" period, lights will remain off until it goes through the cycle and starts a new one then it will turn on according to schedule. so it has to go through the on period then through the off period then it will turns on correctly.
Roberto, Is it possible that you run your test again but instead of begining on a time when the lights are off could you begin on a time when the lights are 100% and go through a cycle of "on" "off" "on" instead of an "off" "on" "off" cycle.
Here is what I've found out:
After leaving the code running on the controller for 24 hrs, AP and DP values on the LCD screen have changed according to the correct schedule.
So this is what's happening, If the controller was powered on during the "LED on" period, lights will remain off until it goes through the cycle and starts a new one then it will turn on according to schedule. so it has to go through the on period then through the off period then it will turns on correctly.
Roberto, Is it possible that you run your test again but instead of begining on a time when the lights are off could you begin on a time when the lights are 100% and go through a cycle of "on" "off" "on" instead of an "off" "on" "off" cycle.
Re: PWM ramp up and down
quick off topic question for you guys...
I want to switch to LEDs and meanwells only time to 15%... what setup are you guys using and where did you get it such that it can start at 0%??? Please feel free to PM me so I don't mess up this thread anymore.
I want to switch to LEDs and meanwells only time to 15%... what setup are you guys using and where did you get it such that it can start at 0%??? Please feel free to PM me so I don't mess up this thread anymore.
Re: PWM ramp up and down
I'm using Mean Well drivers. What I'm doing that I start from 0% then jump to 20% ramp to 100% then go back the same way. I m not using the drivers in the 0% to 20% range
Re: PWM ramp up and down
My tests were with resetting the controller for every reading.
I'm not going to sit and wait the clock to get to the reading I needed
I'm not going to sit and wait the clock to get to the reading I needed
Roberto.
Re: PWM ramp up and down
I thought you run the test using simulation. I know I've been bugging you and Curt with a lot of questions. Your help is really appreciated. I'm just trying to figure out why I m having this problem.
About the function:
I m trying to understand its code. this function returns two values, one is oldValue and the other is depending on the if statment. lets say this condition is true " else if ( Now > StartD && Now < StopD ) " then the function will return with oldValue and endPWM. are their values any different? Also what is the use of oldValue in this function?
About the function:
Code: Select all
byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
int Now = NumMins(hour(), minute());
int Start = NumMins(startHour, startMinute);
int StartD = Start + Duration;
int End = NumMins(endHour, endMinute);
int StopD = End - Duration;
if ( Now >= Start && Now <= StartD )
return constrain(map(Now, Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( Now >= StopD && Now <= End )
{
byte v = constrain(map(Now, StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( Now > StartD && Now < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: PWM ramp up and down
Almost there.
When the code finds a return statement, it just exits the function returning whatever it is passed after the return.
Som, in the case you mentioned, it would return endPWM.
The oldValue is one of the input parameters of PWMSlope function
It will only return oldValue if none of the 3 if statements are true.
When the code finds a return statement, it just exits the function returning whatever it is passed after the return.
Som, in the case you mentioned, it would return endPWM.
The oldValue is one of the input parameters of PWMSlope function
Code: Select all
byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
It will only return oldValue if none of the 3 if statements are true.
Roberto.
Re: PWM ramp up and down
I have found out something very interesting. I wanted to test if PWMSlope() was returning oldValue for some reason so i changed the function's input parameters to this:
ReefAngel.PWM.SetActinic(PWMSlope(16,0,1,0,20,100,60,100));
instead of this:
ReefAngel.PWM.SetActinic(PWMSlope(16,0,1,0,20,100,60,ReefAngel.PWM.GetActinicValue()));
and then compiled and loaded the code to the controller and the result was AP=100% while the daylight function which was left as it is was at zero.
There is a bug that causes the function to return oldValue when it should return endPWM and this only happens if you schedule endHour to be smaller than startHour in value. In my schedule StartD= 1020mins and StopD=0mins when you do this comparison
if ( Now > StartD && Now < StopD )
and lets say Now=1200mins which should return true for this condition returns False because Now is not less than StopD
ReefAngel.PWM.SetActinic(PWMSlope(16,0,1,0,20,100,60,100));
instead of this:
ReefAngel.PWM.SetActinic(PWMSlope(16,0,1,0,20,100,60,ReefAngel.PWM.GetActinicValue()));
and then compiled and loaded the code to the controller and the result was AP=100% while the daylight function which was left as it is was at zero.
There is a bug that causes the function to return oldValue when it should return endPWM and this only happens if you schedule endHour to be smaller than startHour in value. In my schedule StartD= 1020mins and StopD=0mins when you do this comparison
if ( Now > StartD && Now < StopD )
and lets say Now=1200mins which should return true for this condition returns False because Now is not less than StopD
Re: PWM ramp up and down
I have modified the PWMSlope function a bit incase any one wants to set his LEDs off time after midnight. here is the modified function:
Code: Select all
byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
int Now = NumMins(hour(), minute());
int Start = NumMins(startHour, startMinute);
int StartD = Start + Duration;
int End = NumMins(endHour, endMinute);
//Time correction if end time chosen is after midnight
if ( Start > End )
{
End= End+1440; // 1440mins = 24hr*60mins
}
int StopD = End - Duration;
if ( Now >= Start && Now <= StartD )
return constrain(map(Now, Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( Now >= StopD && Now <= End )
{
byte v = constrain(map(Now, StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( Now > StartD && Now < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: PWM ramp up and down
sadly, i think I ve just noticed that the ramping down is not working so I m gonna try working on it tomorrow