Page 1 of 1

PWM Slope

Posted: Thu Feb 09, 2012 6:25 am
by binder
PWMSlope is a function that ramps the LED channel from a starting percentage to a stop percentage over a specified amount of time (minutes).

This post is meant to be a starting point and will be added to.

You need to specify a start hour and minute and an end hour and minute along with a start and end percentage and a duration of the slope.

When the start time is encountered, the PWMSlope function will start to ramp up the LED intensity over the specified duration. Then it will display the end intensity until the end time minus the duration is encountered. Then it will ramp down the LED intensity to the starting intensity finishing at the end time and maintain that intensity until the start time is encountered again.

The memory locations that are involved:
Actinic / Daylight PWM % - If not using PWMSlope, this value sets the values (percentage) of the PWM channels (0-100%). If using PWMSlope, set to 0.

PWM Slope Actinic/Daylight:
Start % - The % you want to start with when the PWM Slope function starts (when the lights are coming on). It's from 0-100%.
Stop % - The % you want to have as all on at the peak of the slope. It's from 0-100%.
Duration - The amount of time in minutes you want the slope to take to complete from start % to stop %.

The reason for the variation in start / stop % is due to different drivers. Some drivers cannot go all the way down to 0%.

The PWMSlope function simply ramps the LEDs up / down from the starting % to the stop % over the specified duration in minutes. The % can only take 0 - 100 and the duration can be from 0-255 minutes.

Re: PWM Slope

Posted: Mon Feb 27, 2012 9:33 pm
by TanksNStuff
Couple quick questions regarding the PWM slopes:

1. Are the following lines only applicable to the A & D channels on the main relay box (as in they aren't needed if using only the PWM expansion module channels?)

Code: Select all

    ReefAngel.PWM.ActinicPWMSlope();
    ReefAngel.PWM.DaylightPWMSlope();
The reason I'm guessing this is the case is because when having those lines included in my loop before the following lines.... my PWM % shows crazy numbers like 167%... which is obviously not possible.

Code: Select all

PWMChannel[LEDPWM0]=PWMSlope(8,0,22,00,10,50,60,PWMChannel[LEDPWM0]);
PWMChannel[LEDPWM1]=PWMSlope(8,0,22,00,10,50,60,PWMChannel[LEDPWM1]);
PWMChannel[LEDPWM2]=PWMSlope(10,0,20,30,10,50,75,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]=PWMSlope(10,0,20,30,10,50,75,PWMChannel[LEDPWM3]);


Hoping that's the case because removing those two lines saves me 392 bytes and also displays my DP/AP at 50%, which seems more realistic.... but leads me to my next question.

2. When using the standard code below for displaying params and PWM values... does it display the current percent of the PWM slope even if using the PMW module channels (ie. shouldn't it show 10% for AP at 8 AM based on my code above or 0% when the current time is after the StdLights Off Hour/Minute)?

Code: Select all

#if defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor(15, 30, ReefAngel.Params,
    ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor(15, 30, ReefAngel.Params);
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
    pingSerial();
Could I change any part of it so that it displays the 4 PWM channels that I'm using instead of the DP and AP? I was able to create a custom main to show just the % of each channel... but the extra coding made my .ino too large to compile.

Re: PWM Slope

Posted: Mon Feb 27, 2012 10:55 pm
by rimai
1. Yes. only to the ports in the main relay box.
You can remove it if not being used to save space.
2. It will show the AP and DP on the code you posted. You need custom main to display the % of the expansion modules.

Re: PWM Slope

Posted: Tue Feb 28, 2012 9:57 am
by TanksNStuff
Thanks Roberto. I actually opened up the "CustomMainScreen_PWMExpansion" example, copy/pasted that in instead of the standard screen (that I showed in Question #2) and that gave me all the %'s for each channel. It used up 100 or so bytes that I made up by removing those other two lines... but it's showing all the info I want to see.

Re: PWM Slope

Posted: Mon Apr 30, 2012 9:39 am
by frostyballz
this may be an obvious answer that i can't seem to find, but where do i set the start and end time for the LED's to come on? I got the duration and everything but can't figure out where to do the start time, or do i have to do that manually in the code on not on RAGen?

Re: PWM Slope

Posted: Mon Apr 30, 2012 9:42 am
by rimai
It will use the same schedule as StandardLights()

Re: PWM Slope

Posted: Tue May 01, 2012 1:42 am
by frostyballz
what if i planned on not having my LED's plugged into the box, and just having the slope shut them down? or can that be done?

Re: PWM Slope

Posted: Tue May 01, 2012 7:18 am
by rimai
You can do that :)
Your function would look like this:

Code: Select all

PWMSlope(8,0,22,00,10,50,60,0);
Note the last 0.
It will output 0 whenever it falls outside of the slope timeframe.

Re: PWM Slope

Posted: Mon Dec 31, 2012 9:04 am
by lnevo
If I understand correctly... the current functions do not allow the slope to cross midnight. Would it be possible to seperate the ramp up and ramp down functions, so that one can be run from x to midnight and then a ramp down function from midnight to y?

The other feature of this would be if you wanted to ramp down or up only... For my case this is what I'd like to do...

At sunset, my actinics turn off. I would like to put on the moonlights at MoonPhase() percent.
I would like them to stay on until 3am, but ramping down until complete darkness. Then I'd like to ramp them back to MoonPhase()% starting at 5am. Then they would stay on until my actinics come back on.

How does that sound?

Functions could be something like PWMSlopeUp(), PWMSlopeDown()

Re: PWM Slope

Posted: Mon Dec 31, 2012 9:16 am
by lnevo
I guess for my example, I could do an inverse slope for my darkness period.
Would there be any issue doing something like this the way it's written?

PWMSlope(2,30,5,30,MoonPhase(),0,30,0);

Still think there might be some value to the seperate functions... :)

Re: PWM Slope

Posted: Mon Dec 31, 2012 9:26 am
by rimai
There is an overnight function available:
http://forum.reefangel.com/viewtopic.php?p=8905#p8905

Re: PWM Slope

Posted: Mon Dec 31, 2012 10:21 am
by lnevo
Cool. Good to know. On my other question... will an inverse slope work ? Where we dim to dark and dim back up?

Re: PWM Slope

Posted: Mon Dec 31, 2012 10:23 am
by rimai
I think so....
Never tried.

Re: PWM Slope

Posted: Mon Dec 31, 2012 10:33 am
by lnevo
Guess I will give it a try and report back..

PWM Slope

Posted: Tue Jan 01, 2013 3:00 pm
by lnevo
It did not seem to work. The portal shows no change between my darkness hours...no slope seen :(

Re: PWM Slope

Posted: Tue Jan 01, 2013 4:48 pm
by rimai
Did you use the overnight version?

PWM Slope

Posted: Tue Jan 01, 2013 4:54 pm
by lnevo
Didnt need the overnight..i'll paste my code later tonight. The overnight was to support people doing a ramp up separate from ramp down.

Re: PWM Slope

Posted: Tue Jan 01, 2013 6:36 pm
by lnevo
Here's the block of code I tested last night. From the portal data, it seems to have dropped to 0 from 2am-5am.

Code: Select all

   if ((hour()>=2) && (hour()<5)) { // 2:00am-4:59am
      // Some complete darkness. Ramp down to 0 and back up to MoonPhase().
      ReefAngel.PWM.SetDaylight(PWMSlope(2,0,5,0,MoonPhase(),0,30,0));
      ReefAngel.PWM.SetActinic(PWMSlope(2,0,5,0,MoonPhase(),0,30,0));
    } else {
      // Set moonlights to the MoonPhase
      ReefAngel.PWM.SetDaylight(MoonPhase());
      ReefAngel.PWM.SetActinic(MoonPhase());
    }

Re: PWM Slope

Posted: Tue Jan 01, 2013 9:22 pm
by rimai
Oh no...
You need to do the opposite...
You need to overnight function and ramp up at 5am and down at 2am

PWM Slope

Posted: Tue Jan 01, 2013 9:26 pm
by lnevo
Ahhh got it. Will try tomorrow.

PWM Slope

Posted: Wed Jan 02, 2013 4:21 pm
by lnevo
I noticed the overnight function is not in the libraries?

Also, i noticed a function ReversePWM that was used in the cloud program...would that be more direct to use for what I am trying to do?

Re: PWM Slope

Posted: Wed Jan 02, 2013 4:29 pm
by rimai
Correct, the overnight never made to the libraries.
The reverse version is on seconds and not minutes, but it will also not cross over to next day.

PWM Slope

Posted: Fri Jan 04, 2013 5:46 am
by lnevo
Worked perfectly last night! Thanks Roberto!

Re: PWM Slope

Posted: Fri Jan 04, 2013 8:58 am
by rimai
Awesome!!! :)