PWM Slope

Related to the development libraries, released by Curt Binder
Post Reply
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

PWM Slope

Post 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.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: PWM Slope

Post 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.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post 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.
Roberto.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: PWM Slope

Post 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.
frostyballz
Posts: 4
Joined: Thu Mar 01, 2012 11:48 am

Re: PWM Slope

Post 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?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post by rimai »

It will use the same schedule as StandardLights()
Roberto.
frostyballz
Posts: 4
Joined: Thu Mar 01, 2012 11:48 am

Re: PWM Slope

Post 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?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post 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.
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: PWM Slope

Post 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()
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: PWM Slope

Post 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... :)
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post by rimai »

There is an overnight function available:
http://forum.reefangel.com/viewtopic.php?p=8905#p8905
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: PWM Slope

Post by lnevo »

Cool. Good to know. On my other question... will an inverse slope work ? Where we dim to dark and dim back up?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post by rimai »

I think so....
Never tried.
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: PWM Slope

Post by lnevo »

Guess I will give it a try and report back..
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

PWM Slope

Post by lnevo »

It did not seem to work. The portal shows no change between my darkness hours...no slope seen :(
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post by rimai »

Did you use the overnight version?
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

PWM Slope

Post 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.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: PWM Slope

Post 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());
    }
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post by rimai »

Oh no...
You need to do the opposite...
You need to overnight function and ramp up at 5am and down at 2am
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

PWM Slope

Post by lnevo »

Ahhh got it. Will try tomorrow.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

PWM Slope

Post 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?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post 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.
Roberto.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

PWM Slope

Post by lnevo »

Worked perfectly last night! Thanks Roberto!
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Slope

Post by rimai »

Awesome!!! :)
Roberto.
Post Reply