PWM Slope

Related to the development libraries, released by Curt Binder
User avatar
Posts: 2739
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Thu Feb 09, 2012 6:25 am
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.

Posts: 188
Joined: Fri Dec 30, 2011 6:57 am
PostPosted: Mon Feb 27, 2012 9:33 pm
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.

Posts: 12242
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Mon Feb 27, 2012 10:55 pm
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.
Roberto.

Posts: 188
Joined: Fri Dec 30, 2011 6:57 am
PostPosted: Tue Feb 28, 2012 9:57 am
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.

Posts: 4
Joined: Thu Mar 01, 2012 11:48 am
PostPosted: Mon Apr 30, 2012 9:39 am
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?

Posts: 12242
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Mon Apr 30, 2012 9:42 am
It will use the same schedule as StandardLights()
Roberto.

Posts: 4
Joined: Thu Mar 01, 2012 11:48 am
PostPosted: Tue May 01, 2012 1:42 am
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?

Posts: 12242
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Tue May 01, 2012 7:18 am
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.
Roberto.
User avatar
Posts: 5349
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Dec 31, 2012 9:04 am
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()
User avatar
Posts: 5349
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Dec 31, 2012 9:16 am
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... :)
Next

Return to Development Libraries

Who is online

Users browsing this forum: No registered users and 3 guests