This way, smoothPhase varies from 2pi to pi over the final slope, the cosine of smoothPhase varies from 1 to -1 over the final slope,half the sum of smoothPhase and 1.0 varies from 1 to 0 over the final slope,and the return value varies from endPWMint to startPWMint over the final slope

Last edited by joshlawless on Fri Aug 28, 2015 3:19 pm, edited 1 time in total.

One thing I noticed when parsing the function -- it calculates the value based on the current time in seconds. With a 12-bit slope, though, you would need at least a 70 minute (linear) ramp to take full advantage of all 4095 levels available. I wonder if it isn't possible to increase the resolution to tenths (or even hundredths) of a second, e.g., by multiplying the start, end and current values by 10, and adding (current_millis()%1000 - current_millis()%100)/100 to the current value, as in this function (which also takes PWM start and end values as 12-bit values instead of percentages):

Looks awesome. I'm not sure how much sense it would make to change it to tenths but I'm intrigued by your approach. I've been thinking of that for a bit with my dosing pump code. Because I'm dosing by volume at the end of the day I'm dosing a little bit under maybe by a full ml because of the resolution there. Interested in helping to take a stab there?

lnevo wrote:Looks awesome. I'm not sure how much sense it would make to change it to tenths but I'm intrigued by your approach. I've been thinking of that for a bit with my dosing pump code. Because I'm dosing by volume at the end of the day I'm dosing a little bit under maybe by a full ml because of the resolution there. Interested in helping to take a stab there?

Sure thing.

For posterity, here's an updated/corrected version of the function above -- the one above had some typos (missing ";" and accidentally included "()" after current_mills.