Hi All-
So just starting out with simple mods of my PWM Slope ouput to get lights to shut off after PWM slope ramps them down to just above the flicker point (fixing this high value this week with new power supply for the whites)
ANyhow, I wrote a few lines of basically an if then statememnt where what I want it to do, is output PWMSlope output during "daylight" hours to allow program to run, but during evening (NW=OFF) I want the NW to have zero power from the PWM controller... so I am kinda unsure if the variables I am using are actually in minutes total for the day etc.. and if my lines are correct... this should set PWM channel 0,2 to 0 output when the lights are "out" (but are never off because I dim only to flicker point with PWM slope calc). And when the lights should be on, it allows PWM slope of CLoud to control them.
// Calculate your regular sunrise/sunset PWM value
PWMChannel[LEDPWM0]=PWMSlope(9,00,19,30,23,50,40,PWMChannel[LEDPWM0]);
PWMChannel[LEDPWM1]=PWMSlope(7,30,22,30,10,50,120,PWMChannel[LEDPWM1]);
PWMChannel[LEDPWM2]=PWMSlope(9,00,19,30,23,50,40,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]=PWMSlope(7,30,22,30,10,50,120,PWMChannel[LEDPWM3]);
CheckCloud();
int Now = NumMins(hour(), minute());
int NWStart=540;
int NWEnd=1170;
if ( Now >= NWEnd && Now <= NWStart ) PWMExpansion(LEDPWM0,0), PWMExpansion(LEDPWM2,0);
else PWMExpansion(LEDPWM0,int(2.55*PWMChannel[LEDPWM0])), PWMExpansion(LEDPWM2,int(2.55*PWMChannel[LEDPWM2]));;
PWMExpansion(LEDPWM1,int(2.55*PWMChannel[LEDPWM1]));
PWMExpansion(LEDPWM3,int(2.55*PWMChannel[LEDPWM3]));
Is this correct
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Is this correct
Just use this instead:
Code: Select all
PWMChannel[LEDPWM0]=PWMSlope(9,00,19,30,23,50,40,0);
PWMChannel[LEDPWM1]=PWMSlope(7,30,22,30,10,50,120,0);
PWMChannel[LEDPWM2]=PWMSlope(9,00,19,30,23,50,40,0);
PWMChannel[LEDPWM3]=PWMSlope(7,30,22,30,10,50,120,0);
CheckCloud();
Roberto.
-
rufessor
- Posts: 291
- Joined: Tue Oct 25, 2011 7:39 am
Re: Is this correct
Ok, but then can you explain what the reason behind having PWMChannel[LEDPWM0] etc as the final PWMSlope "oldValue" value in the PWMSlope input line within the cloud program otherwise serves, because I need to remove that and insert a Zero.... or do what I started out which is an if loop. I am not sure why thats there or what its doing as its only evaluated when the PWM slope calc hits the endpoint for the day and that- PWMChannel[LEDPWM0] - is as far as I understand, language used to set the PWM expansion box channel to a specific value so its weird its even in that statement to me, so I am obviously not understanding, what you posted makes the most sense as PWM slope is designed to do this, but I am at a loss for why the cloud function has it the way it does...
So I didn't want to mess with something I didn't understand so I went with an If statement, but would really like to do it as you suggested if I can just get why its structured like it is below (this is from the cloud.pde posted on a thread) and is obviously part of mine now too..
PWMChannel[LEDPWM0]=PWMSlope(9,00,19,30,23,50,40,PWMChannel[LEDPWM0]);
PWMChannel[LEDPWM1]=PWMSlope(7,30,22,30,10,50,120,PWMChannel[LEDPWM1]);
PWMChannel[LEDPWM2]=PWMSlope(9,00,19,30,23,50,40,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]=PWMSlope(7,30,22,30,10,50,120,PWMChannel[LEDPWM3]);
So I didn't want to mess with something I didn't understand so I went with an If statement, but would really like to do it as you suggested if I can just get why its structured like it is below (this is from the cloud.pde posted on a thread) and is obviously part of mine now too..
PWMChannel[LEDPWM0]=PWMSlope(9,00,19,30,23,50,40,PWMChannel[LEDPWM0]);
PWMChannel[LEDPWM1]=PWMSlope(7,30,22,30,10,50,120,PWMChannel[LEDPWM1]);
PWMChannel[LEDPWM2]=PWMSlope(9,00,19,30,23,50,40,PWMChannel[LEDPWM2]);
PWMChannel[LEDPWM3]=PWMSlope(7,30,22,30,10,50,120,PWMChannel[LEDPWM3]);
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Is this correct
This is the PWMSlope function which you can find on ReefAngel_Globals.cpp:
The last value is not PWMEnd value, but the value it is returned when it is not within the timeframe of the slope.
Assume you had some other calculation like Moonphase prior to slope and prior to clouds and you were using the same actinic channel for you moonlights (Some drivers do go all the way down to 1% and could be used as moonlights).
In this case, you don't want to force a PWMEnd value as a returned value of the PWMSlope, otherwise your moonlights would always be forced to the PWMEnd.
Returning the original value would make the moonlight % go through the PWMSlope and CheckClouds and still be the same when it is out of the range of the slope calculation.
In your case, you can always return 0, cause you don't care about what value is being carried out and you always want it to be 0.
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;
}
Assume you had some other calculation like Moonphase prior to slope and prior to clouds and you were using the same actinic channel for you moonlights (Some drivers do go all the way down to 1% and could be used as moonlights).
In this case, you don't want to force a PWMEnd value as a returned value of the PWMSlope, otherwise your moonlights would always be forced to the PWMEnd.
Returning the original value would make the moonlight % go through the PWMSlope and CheckClouds and still be the same when it is out of the range of the slope calculation.
In your case, you can always return 0, cause you don't care about what value is being carried out and you always want it to be 0.
Roberto.
-
rufessor
- Posts: 291
- Joined: Tue Oct 25, 2011 7:39 am
Re: Is this correct
Yeah... I was looking at the slope function which is how I came up with the language "oldValue" in my question as that seems to be the name you gave to that position in the array that is set up for PWM slope. I think I get it... at the moment you declare PWMSlope the PWMchannel[LEDPWM0] has a real value that may have been set somewhere else in the program, and thus using it as the final member of the array (if thats ok to call it this) when declaring PWMSlope just means that it returns to that value outside of the start and end times specified. So... technically speaking, since I initialize PWM channels to zero in the header of my code, if I loaded the program outside of the PMWslope time frame, it would intialize with this value as zero and would appear to work, but if I loaded it during PWMslope period that had a non zero PWMCHannel[PMWLED0] value, it would return to that... so just set it to zero and then It matters not when I load the program or anything else... just checking to see if I got this really understood, which I think I now do.
I was going to try to use me LEDs as moonlights, and I may still be able too do so but anyhow, which LED powersupplies dim to 1% I want to buy those... but I just finished buying a ton of other ones ... darn.
I was going to try to use me LEDs as moonlights, and I may still be able too do so but anyhow, which LED powersupplies dim to 1% I want to buy those... but I just finished buying a ton of other ones ... darn.
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Is this correct
Yeah, you got it now 
I've heard buckpucks do, but my favorite is my DIY driver that really dims to 1%. It's awesome
But I never end up using it. It's looks too ugly and requires a huge DC power supply.
If you are into DIY the driver, I can send you the eagle files.
I've heard buckpucks do, but my favorite is my DIY driver that really dims to 1%. It's awesome
But I never end up using it. It's looks too ugly and requires a huge DC power supply.
If you are into DIY the driver, I can send you the eagle files.
Roberto.
-
rufessor
- Posts: 291
- Joined: Tue Oct 25, 2011 7:39 am
Re: Is this correct
Nah.... I like my setup and will be happy with 8-10% dimming with the new power supplies I have on order...
I wonder whats up with that anyhow, its digital... why should it drop... dont answer but seriously, I knew this going in, but I still am sorta in disbelief that its really that hard to do correctly and wonder why the Meanwells "suck" at dimming in that they do limit out in the 9-15% range or so it seems even with optimized LED string design...
Thanks... its a first step but I do get it... yeah!
I wonder whats up with that anyhow, its digital... why should it drop... dont answer but seriously, I knew this going in, but I still am sorta in disbelief that its really that hard to do correctly and wonder why the Meanwells "suck" at dimming in that they do limit out in the 9-15% range or so it seems even with optimized LED string design...
Thanks... its a first step but I do get it... yeah!