PWM ramp up and down
PWM ramp up and down
I have a DYI LED fixture that uses four 48P drivers, 2 for actinic, and two for white. I currently have them set to come on at 100% at 1pm and off at 11pm using relay #3. I would like to set up a ramp up and ramp down between that time, simulating sun up and sun down. Is anyone willing to code this for me and instruct me on how to place it in the code created by RAGen.
Thanks
Thanks
Re: PWM ramp up and down
A similar issue was discussed in the email group and a solution has been created (by Roberto and Luca plus some others I believe). There is a function called PWMSlope that you can utilize to accomplish what you are wanting to do. You have to manually code this in your PDE file if you want to use it. So after you create the PDE file with RAGen and you have Arduino open with the PDE file in it, you will need to modify it something like what I'm going to list. Here are some examples for you to use:b_s_c1 wrote:I have a DYI LED fixture that uses four 48P drivers, 2 for actinic, and two for white. I currently have them set to come on at 100% at 1pm and off at 11pm using relay #3. I would like to set up a ramp up and ramp down between that time, simulating sun up and sun down. Is anyone willing to code this for me and instruct me on how to place it in the code created by RAGen.
Thanks
(updated code to be proper code exert)
Code: Select all
// Have PWM on from 9a to 6p, with gradual 60 minute ramp up and down starting at the given times
// From 9a to 10a, the PWM will slowly ramp from 0% to 100%
// From 5p to 6p, the PWM will slowly ramp from 100% to 0%
ReefAngel.PWM.SetActinic(PWMSlope(9,0,18,0,0,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(9,0,18,0,0,100,60,ReefAngel.PWM.GetDaylightValue()));
- startHour - Hour of the start the slope/ramp
startMinute - Minute of the start the slope/ramp
endHour - Hour of the end of the ramp/slope (when end value is reached)
endMinute - Minute of the end ramp/slope
startPWM - Beginning PWM value
endPWM - Ending PWM value
Duration - Amount of time (in minutes) it takes to go from the startPWM to endPWM (and vice versa). If the duration is 30 minutes. Then if it starts at 8a, from 8 - 8:30a it will go from startPWM to endPWM. If it ends at 5pm, from 4:30p - 5p it will go from endPWM to startPWM.
oldValue - Should be the existing/current PWM value (ReefAngel.PWM.GetActinicValue() or GetDaylightValue())
Feel free to experiment with the values all you want. You can also look at the code to get a better idea of what is going on:
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;
}
Last edited by binder on Sat Mar 26, 2011 12:34 pm, edited 1 time in total.
Re: PWM ramp up and down
that is really cool! Making me want to get LEDs to replace my MH
Re: PWM ramp up and down
Thanks Curt. I have one more question. Which pde file does the code get placed in and were does it need to be placed?
I just want to make sure I do this correct. I would just copy and paste the top code you listed and modify the time and that is it?
I am a complete idiot when it comes to programming so I need detailed directions.
Thanks for the help.
I just want to make sure I do this correct. I would just copy and paste the top code you listed and modify the time and that is it?
I am a complete idiot when it comes to programming so I need detailed directions.
Thanks for the help.
Re: PWM ramp up and down
No problem at all. The code gets placed in the PDE file that you created to run your controller. If you use RAGen to generate the PDE files, then it will be the file that begins with RA_. So once you have chosen what devices you want on the ports, you generated the PDE file and opened it up inside Arduino.b_s_c1 wrote:Thanks Curt. I have one more question. Which pde file does the code get placed in and were does it need to be placed?
I just want to make sure I do this correct. I would just copy and paste the top code you listed and modify the time and that is it?
This code will need to be placed inside the void loop() function. You can place it anywhere after the ShowInterface() function. Here is an example of what I'm talking about:
Also, I gave you some wrong information earlier. I had an opportunity to look at the code more closely and test things out. The earlier code sample was missing information and would not have worked properly for you. I had copied code from an earlier example. I have the correct code pasted below and am going to update the information on my previous post.
Code: Select all
// This is just an example main loop section of a PDE file
void loop()
{
ReefAngel.ShowInterface();
// Specific functions
ReefAngel.StandardATO(Port1);
ReefAngel.StandardLights(Port2);
ReefAngel.MHLights(Port3);
ReefAngel.Wavemaker1(Port4);
ReefAngel.Wavemaker2(Port5);
ReefAngel.StandardFan(Port6);
ReefAngel.StandardHeater(Port7);
// Place PWM sloping stuff here
// Have PWM on from 9a to 6p, with gradual 60 minute ramp up and down starting at the given times
// From 9a to 10a, the PWM will slowly ramp from 0% to 100%
// From 5p to 6p, the PWM will slowly ramp from 100% to 0%
ReefAngel.PWM.SetActinic(PWMSlope(9,0,18,0,0,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(9,0,18,0,0,100,60,ReefAngel.PWM.GetDaylightValue()));
}
Code: Select all
// Have PWM on from 9a to 6p, with gradual 60 minute ramp up and down starting at the given times
// From 9a to 10a, the PWM will slowly ramp from 0% to 100%
// From 5p to 6p, the PWM will slowly ramp from 100% to 0%
ReefAngel.PWM.SetActinic(PWMSlope(9,0,18,0,0,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(9,0,18,0,0,100,60,ReefAngel.PWM.GetDaylightValue()));
If you go by my examples above, you will have no problems at all getting things to work how you want them to.
curt
Re: PWM ramp up and down
Thanks for the step by step. I have it uploaded but will not beable to verify it works until 10 pm. This is when the lights should start the ramp off. I will keep you informed.
Re: PWM ramp up and down
The code works good. I just need to adjust the code a bit more to get a better look for the sunrise and set. Also I get a flashing effect when the LEDs come on and when they are almost off.
I think if I could start and stop the lights at 20% this would do away with the flashing.
I think if I could start and stop the lights at 20% this would do away with the flashing.
Re: PWM ramp up and down
Cool. Glad it's working for you. To make it start and stop at 20%, all the modification would be changing the 0 to 20:b_s_c1 wrote:I think if I could start and stop the lights at 20% this would do away with the flashing.
Code: Select all
ReefAngel.PWM.SetActinic(PWMSlope(9,0,18,0,20,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(9,0,18,0,20,100,60,ReefAngel.PWM.GetDaylightValue()));
curt
Re: PWM ramp up and down
I once went to the Meanwell office here in CA, which is actually very close by to me.
I went to their lab and worked with their main support tech guy.
The findings we had was that the ELN-60-48 was the only one that had such flashing behavior.
We were able to duplicate it in their lab and he said it was something in their design and there was nothing I could do about it. It bugged me too.
Combine that and the fact that I could only dim it to 15-20% and not lower, and I decided that I was just going to build my own driver, which I did and I'm using it in my tank. It ends up costing a little more, but I can actually dim it down to 1%. The only issue is that it requires a really big power supply. I'm using a regulated 48VDC - 3000mA power supply to power two strings of 12 Crees.
I went to their lab and worked with their main support tech guy.
The findings we had was that the ELN-60-48 was the only one that had such flashing behavior.
We were able to duplicate it in their lab and he said it was something in their design and there was nothing I could do about it. It bugged me too.
Combine that and the fact that I could only dim it to 15-20% and not lower, and I decided that I was just going to build my own driver, which I did and I'm using it in my tank. It ends up costing a little more, but I can actually dim it down to 1%. The only issue is that it requires a really big power supply. I'm using a regulated 48VDC - 3000mA power supply to power two strings of 12 Crees.
Roberto.
Re: PWM ramp up and down
Hence my good price on the drivers !
I think of it as a lightning strike. They have those a lot in the tropics .
I think of it as a lightning strike. They have those a lot in the tropics .
Re: PWM ramp up and down
Is it possible to really trick out the PWM ramp by doing Seasons also.Meaning different lengths off day determined by month. With the phasing Moon light running also?
Roberto does the moonlight Phase start at 100% or the min.? Would love to run a scheme that was similar to a yearly cycle than 24hr. Just thinking out loud . Doesnt seem like it would be too difficult ,but what do I know.
Roberto does the moonlight Phase start at 100% or the min.? Would love to run a scheme that was similar to a yearly cycle than 24hr. Just thinking out loud . Doesnt seem like it would be too difficult ,but what do I know.
Re: PWM ramp up and down
Do you have any reference link on calculating the length of daylight you are trying to accomplish?
Would you be able to explain better the year vs 24hr? I didn't quite understand.
Would you be able to explain better the year vs 24hr? I didn't quite understand.
Roberto.
Re: PWM ramp up and down
Well like summer days have more hrs. of daylight then winter. so if I look at my tide book for ref.
Today sunrise was at 6:52am sunset 7:35pm. with 0% moon phase. Tomorrow 6:51am -7:36pm with 2% moon phase.I would like the moon phase to coincide with the actually moon phase.
but on Dec. 14Th it has changed to 7:17am-4:52pm so basically it has lost 2hrs of daylight. So over the year your daylight tank hours would change according to the season.And the moon would be the same on your tank as outside.
I will look for a calculation on the web.
Today sunrise was at 6:52am sunset 7:35pm. with 0% moon phase. Tomorrow 6:51am -7:36pm with 2% moon phase.I would like the moon phase to coincide with the actually moon phase.
but on Dec. 14Th it has changed to 7:17am-4:52pm so basically it has lost 2hrs of daylight. So over the year your daylight tank hours would change according to the season.And the moon would be the same on your tank as outside.
I will look for a calculation on the web.
Re: PWM ramp up and down
I'm pretty sure that's what the moonphasePWM function is already calculating, isn't it?
We can create the sunset sunrise timing too. We just need the formula.
We can create the sunset sunrise timing too. We just need the formula.
Roberto.
Re: PWM ramp up and down
yes moonphasePWM function is calculating but on 29.5 days. I found something but not sure if it helps kinda got lost reading it but it seems to have a similar caculation in there after all the cloud and thounderstorm stuff( basic day). http://code.google.com/p/arduino-rtc-pw ... dates/list
Could be wrong.
Ill keep looking.
Could be wrong.
Ill keep looking.
Re: PWM ramp up and down
Here is the formula for caculating. I will try it out.
http://williams.best.vwh.net/sunrise_su ... orithm.htm
http://users.electromagnetic.net/bu/astro/iyf-calc.php
http://williams.best.vwh.net/sunrise_su ... orithm.htm
http://users.electromagnetic.net/bu/astro/iyf-calc.php
Re: PWM ramp up and down
Is the math wrong or is it something else?bmhair03 wrote:yes moonphasePWM function is calculating but on 29.5 days.
I think 29.5 days of moon cycle is pretty accurate.
Let me know where I messed up.
Roberto.
Re: PWM ramp up and down
I am still having a little problem with the ramp up and down. I changed the code so the blue lights will come on at 12am and ramp to 100% in an hour. Then the white will start the ramp at 1pm and ramp to 100% in an hour. I also found to get a true ramp the PWM must be set at 0% through RAGen. This works fine when I first down load it and goes through one cycle. Then the next day at 11am both blue and white come on at 100%. I am not sure if the ramp down is working correctly because I am never around to see it. I am thinking the code is holding the 100% value once it gets there and not returning to 0 after it times out.
Can someone help me fix this.
void setup()
{
ReefAngel.Init(); //Initialize controller
// Have PWM on from 11a to 11p, with gradual 60 minute ramp up and down starting at the given times
// From 12pm to 1pm, actinic and 1pm to 2pm daylightthe PWM will slowly ramp from 15% to 100%
// From 10 pm to 11pm, daylight and 11 to 12 actinic the PWM will slowly ramp from 100% to 15%
ReefAngel.PWM.SetActinic(PWMSlope(12,0,23,0,15,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(13,0,22,0,15,100,60,ReefAngel.PWM.GetDaylightValue()));
ReefAngel.FeedingModePorts = B10000000;
ReefAngel.WaterChangePorts = B10000000;
ReefAngel.OverheatShutoffPorts = B00000001;
ReefAngel.LightsOnPorts = B00000100;
InternalMemory.FeedingTimer_write(900);
InternalMemory.LCDTimer_write(600);
InternalMemory.LEDPWMActinic_write(0);
InternalMemory.LEDPWMDaylight_write(0);
Can someone help me fix this.
void setup()
{
ReefAngel.Init(); //Initialize controller
// Have PWM on from 11a to 11p, with gradual 60 minute ramp up and down starting at the given times
// From 12pm to 1pm, actinic and 1pm to 2pm daylightthe PWM will slowly ramp from 15% to 100%
// From 10 pm to 11pm, daylight and 11 to 12 actinic the PWM will slowly ramp from 100% to 15%
ReefAngel.PWM.SetActinic(PWMSlope(12,0,23,0,15,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(13,0,22,0,15,100,60,ReefAngel.PWM.GetDaylightValue()));
ReefAngel.FeedingModePorts = B10000000;
ReefAngel.WaterChangePorts = B10000000;
ReefAngel.OverheatShutoffPorts = B00000001;
ReefAngel.LightsOnPorts = B00000100;
InternalMemory.FeedingTimer_write(900);
InternalMemory.LCDTimer_write(600);
InternalMemory.LEDPWMActinic_write(0);
InternalMemory.LEDPWMDaylight_write(0);
Re: PWM ramp up and down
I just modified the code a bit to change the time. Just thought I would post it so you are looking at the correct code.
void setup()
{
ReefAngel.Init(); //Initialize controller
// Have PWM on from 12pm to 12am, with gradual 60 minute ramp up and down starting at the given times
// From 12pm to 1pm, actinic and 1pm to 2pm daylightthe PWM will slowly ramp from 20% to 100%
// From 9 pm to 10pm, daylight and 10 to 11 actinic the PWM will slowly ramp from 100% to 20%
ReefAngel.PWM.SetActinic(PWMSlope(12,0,22,0,15,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(13,0,21,0,15,100,60,ReefAngel.PWM.GetDaylightValue()));
ReefAngel.FeedingModePorts = B10000000;
ReefAngel.WaterChangePorts = B10000000;
ReefAngel.OverheatShutoffPorts = B00000001;
ReefAngel.LightsOnPorts = B00000100;
// Ports that are always on
ReefAngel.Relay.On(Port5);
ReefAngel.Relay.On(Port6);
ReefAngel.Relay.On(Port7);
ReefAngel.Relay.On(Port8);
}
void setup()
{
ReefAngel.Init(); //Initialize controller
// Have PWM on from 12pm to 12am, with gradual 60 minute ramp up and down starting at the given times
// From 12pm to 1pm, actinic and 1pm to 2pm daylightthe PWM will slowly ramp from 20% to 100%
// From 9 pm to 10pm, daylight and 10 to 11 actinic the PWM will slowly ramp from 100% to 20%
ReefAngel.PWM.SetActinic(PWMSlope(12,0,22,0,15,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(13,0,21,0,15,100,60,ReefAngel.PWM.GetDaylightValue()));
ReefAngel.FeedingModePorts = B10000000;
ReefAngel.WaterChangePorts = B10000000;
ReefAngel.OverheatShutoffPorts = B00000001;
ReefAngel.LightsOnPorts = B00000100;
// Ports that are always on
ReefAngel.Relay.On(Port5);
ReefAngel.Relay.On(Port6);
ReefAngel.Relay.On(Port7);
ReefAngel.Relay.On(Port8);
}
Re: PWM ramp up and down
Roberto 29.5 is correct for moonphase.
For a whole year we would have to stretch it out . Basically need it to subtract 1 minute from the sunrise ,and add 1 minute to sunset for 6months(177 days) pause for 1 week (5 days) then reverse the process. Add 1min to sunrise and subtract 1 from sunset. The week pauses are at the solstices. Dec 21st and Jun 21st. (182 x2=364) damn leap years!!
Can you reference the date when writing a .PDE. or just a time of day.
For a whole year we would have to stretch it out . Basically need it to subtract 1 minute from the sunrise ,and add 1 minute to sunset for 6months(177 days) pause for 1 week (5 days) then reverse the process. Add 1min to sunrise and subtract 1 from sunset. The week pauses are at the solstices. Dec 21st and Jun 21st. (182 x2=364) damn leap years!!
Can you reference the date when writing a .PDE. or just a time of day.
Re: PWM ramp up and down
Correct. The internal memory value should be at 0% or 15% (your starting value) in order for it to work properly. If there is any power outage, the controller starts up and sets the PWM values to be whatever is stored in the InternalMemory values. So if your InternalMemory is set to 100% and you have a power outage at midnight when the lights come back on they will be 100% until the next slope period.b_s_c1 wrote:I am still having a little problem with the ramp up and down. I changed the code so the blue lights will come on at 12am and ramp to 100% in an hour. Then the white will start the ramp at 1pm and ramp to 100% in an hour. I also found to get a true ramp the PWM must be set at 0% through RAGen. This works fine when I first down load it and goes through one cycle. Then the next day at 11am both blue and white come on at 100%. I am not sure if the ramp down is working correctly because I am never around to see it. I am thinking the code is holding the 100% value once it gets there and not returning to 0 after it times out.
As far as holding onto the values, it doesn't and shouldn't. Each time the function is called, the value is computed based on the current time. Are you watching the percentage values on the LCD screen?
I'm going to do some testing to see if I can determine what is going on. Maybe Roberto can shed some light on it since him and a few others worked on the function and what the "best" way would be to use the function.
curt
Re: PWM ramp up and down
It seems there's been a confusion on where to place the function.
The PWMSLope function has to be placed inside the loop() and not setup()
If you can attach the entire code, I can correct it for you.
The PWMSLope function has to be placed inside the loop() and not setup()
If you can attach the entire code, I can correct it for you.
Roberto.
Re: PWM ramp up and down
I should not have a problem moving it. I will give it a shot when I get home and watch the function of the ramp down tonight. I will not see the ramp up function until Friday unless I change the time. I will let you know if I have a problem moving the code or the function tomorrow.rimai wrote:It seems there's been a confusion on where to place the function.
The PWMSLope function has to be placed inside the loop() and not setup()
If you can attach the entire code, I can correct it for you.
Thanks for your help
Re: PWM ramp up and down
At 10:30pm both actinic and white PWM % on the RA head unit read 15%. With the code below I believe the white should be at 15 and the actinic should be close to 42%. Is my thinking correct? If so why did they step down the same? I have not taken any other PWM readings but during the step down it appeared both lights had the same intensity.
// Have PWM on from 12pm to 11pm, with gradual 60 minute ramp up and down starting at the given times
// From 12pm to 1pm, actinic and 1pm to 2pm daylightthe PWM will slowly ramp from 15% to 100%
// From 9 pm to 10pm, daylight and 10 to 11 actinic the PWM will slowly ramp from 100% to 15%
ReefAngel.PWM.SetActinic(PWMSlope(12,0,22,0,15,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(13,0,21,0,15,100,60,ReefAngel.PWM.GetDaylightValue()));
The power to the 4 drivers are plugged into a power strip which is plugged into the relay box. The relay box plug is set to come on at 11 am and off at 11pm and the PWM, through RAGen, is set for 15%.
// Have PWM on from 12pm to 11pm, with gradual 60 minute ramp up and down starting at the given times
// From 12pm to 1pm, actinic and 1pm to 2pm daylightthe PWM will slowly ramp from 15% to 100%
// From 9 pm to 10pm, daylight and 10 to 11 actinic the PWM will slowly ramp from 100% to 15%
ReefAngel.PWM.SetActinic(PWMSlope(12,0,22,0,15,100,60,ReefAngel.PWM.GetActinicValue()));
ReefAngel.PWM.SetDaylight(PWMSlope(13,0,21,0,15,100,60,ReefAngel.PWM.GetDaylightValue()));
The power to the 4 drivers are plugged into a power strip which is plugged into the relay box. The relay box plug is set to come on at 11 am and off at 11pm and the PWM, through RAGen, is set for 15%.
Re: PWM ramp up and down
Sorry for the confusion.
The times in the function are start and end of slope.
Actinic slope starts at 12pm and ends at 10pm, so it goes from 15% to 100% between 12pm and 1pm and from 100% to 15% from 9pm to 10pm.
The times in the function are start and end of slope.
Actinic slope starts at 12pm and ends at 10pm, so it goes from 15% to 100% between 12pm and 1pm and from 100% to 15% from 9pm to 10pm.
Roberto.
Re: PWM ramp up and down
You may want to rethink the way this is setup.b_s_c1 wrote:The power to the 4 drivers are plugged into a power strip which is plugged into the relay box. The relay box plug is set to come on at 11 am and off at 11pm and the PWM, through RAGen, is set for 15%.
http://groups.google.com/group/reefange ... ca0d9aa2c8
Roberto.
Re: PWM ramp up and down
rimai wrote:Sorry for the confusion.
The times in the function are start and end of slope.
Actinic slope starts at 12pm and ends at 10pm, so it goes from 15% to 100% between 12pm and 1pm and from 100% to 15% from 9pm to 10pm.
This is how I expected it to work but for the whites on there slope down between 10pm - 11pm it should do the same. Starting from 100%-15%. That means at 10:30 the PWM should have been around 42% but it was already 15%.
Once the ramp up is completed 100% is held until the ramp down starts. Correct?
Re: PWM ramp up and down
But your whites are set to 1pm to 9pm, which means at 9pm, it is supposed to be at 15%.
You are correct on the 100% between the slopes up and down.
You are correct on the 100% between the slopes up and down.
Roberto.
Re: PWM ramp up and down
Thanks for the heads up. If the post is true and the inrush current is around 30amps for the 48p drivers, one outlet will not be able to hold up to one driver.rimai wrote:You may want to rethink the way this is setup.b_s_c1 wrote:The power to the 4 drivers are plugged into a power strip which is plugged into the relay box. The relay box plug is set to come on at 11 am and off at 11pm and the PWM, through RAGen, is set for 15%.
http://groups.google.com/group/reefange ... ca0d9aa2c8
There is really not enough info on the spec sheet to draw a conclusion on the inrush current. All it says is max. I will send Meanwell an email to see if I can get a better idea of the inrush current and let you know what I come up with.
I do have a meter at work that will record and capture the smallest and fastest current surge so I will try to bring one home and do a little testing for my self. I do believe this info is a must for any controller used to power these drivers.
Re: PWM ramp up and down
This is correct, and I am sorry for the confussion. At 10:30 the whites were and should have been at 15%. The questions was about the actinics. At 10:30 they should have been at 42% since this is the half way point of the slope. On a side note when I got home today I looked at the RA display and it read 15% for both PWMs. This was at 6:00pm. Not really sure what is going on here but I assumed the display would show the actual value that is being sent to the drivers.rimai wrote:But your whites are set to 1pm to 9pm, which means at 9pm, it is supposed to be at 15%.
You are correct on the 100% between the slopes up and down.
I am sorry for all the questions and don't mean to be a pain in the rear but I would really like to get this correct. I have yet to see a true ramp up and down done by the controller. At 10pm the whites should be almost off if not completely then the blues start to decrease in brightness. When the lights come one they are the same and it seems they ramp up together then they do the same when they ramp down.