PWM Parabola - What's the calculation it performs?

Post Reply
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

PWM Parabola - What's the calculation it performs?

Post by TanksNStuff »

I was just curious as to what the actual calculation the parabola function performs to determine the intensity % at whatever time of day it is? Maybe I missed it, but I tried to peek at all the libraries and I didn't see it anywhere in there.

From what I understand, it uses the start time, start %, end time, end(max) % to calculate a "midday" for the max %... and then it gradually increases from start % up max % at midday, ramping back down in reverse to end time. That part I understand no problem. I don't know the exact code used to figure the midday, but I'm sure it just takes the length of time and divides by 2, than adds that to the start time (or something as simple as that.)

But I guess my question is, what's the formula used to calculate the incremental values along the way?

I would think it's not a linear equation since it's a parabola, right? So, if that's correct, then it's not a simple x% increase per/hour until the midday point (or minute, or second, or whatever interval period it uses). I'm also guessing that the time span between "start time" / "midday" / "end time" and the intensity difference between "start%" / "end%" will vary the interval increases too. But there has to be some simple formula that is computed using those values... what is it? :geek:
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: PWM Parabola - What's the calculation it performs?

Post by DrewPalmer04 »

It's in Globals.h :)
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: PWM Parabola - What's the calculation it performs?

Post by TanksNStuff »

Thank you for the reply Drew, but the only thing I saw in Globals.h was:

Code: Select all

byte PWMParabola(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte oldValue);
Globals.cpp has this however:

Code: Select all

byte PWMParabola(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte oldValue)
{
	int Now = NumMins(hour(), minute());
	int Start = NumMins(startHour, startMinute);
	int End = NumMins(endHour, endMinute);
	byte PWMDelta = endPWM-startPWM;
	byte ParabolaPhase=constrain(map(Now,Start,End,0,180),0,180);

   if ( Now <= Start || Now >= End)
		return oldValue;
	else
	{
		return startPWM+(PWMDelta*sin(radians(ParabolaPhase)));
	}
}
So could the formula be this part?:

Code: Select all

	return startPWM+(PWMDelta*sin(radians(ParabolaPhase)));
If so, can someone help explain the ParabolaPhase byte (I don't know what constrain and map mean) ?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: PWM Parabola - What's the calculation it performs?

Post by rimai »

Correct.
It calculates it by converting the phase into sinusoidal wave.
We are only interested on the positive side of the wave, so the phase goes from 0 to 180 degrees.
If you want total phase, you need to go from 0 to 360 degrees.
Another method is here:
http://forum.reefangel.com/viewtopic.ph ... ine#p18240
Roberto.
Post Reply