Jiggy-Ninja:
Woot!
Hollah!
What?Were you able to control the pulse height before? Because looking over you code it looks like it was malfunctioning from the start. It appears that your intention is to ramp up to pwmmax, reverse direction, then ramp down to pwmmin, then pause for the dead-time. But the scope traces you are posting show the ramp going all the way to Vcc then straight back down to 0. I think the problem's here:
//////////////////////////////////////////////////////////
void loop()
{
int Dir=2;
////// Increment/decrement PWM on ledPin with a period of 'x RampLength' in us. /////
Why do you set Dir on every pass through loop() here on line 99? Why do you set it to 2 here when every other place uses 1? How about you just do `enum ramp_direction {FALLING=-1, PAUSED=0, RISING=1};` and use those values? You probably also intended Dir to be `[b]static[/b]`.StartUs=micros();
Minor point here on line 136, this is not the recommended way of advancing the interval. Use `StartUs += rampLength;` instead. That is because I told you to **replace** the delay statement with the do-while loop, not supplement it.if(Pwm==pwmMin)
//if PWM reaches the minimum:
{
digitalWrite(outPin, LOW);
delay(INTERVAL); <-- PITCH IT. Throw it out the door.
Dir=+1; //delay INTERVAL & change direction
delayStartTime = micros();
do
{
INTERVAL = map(analogRead(intervalPin),0,1023,800,50000);
pwmMax = map(analogRead(pwmMaxPin),0,1023,55,255);
ramplength = map(analogRead(ramplengthPin),0,1023,2,11800);
}
while(micros()-delayStartTime<=INTERVAL);
}
Hello Again Jiggy-Ninja
Thanks for taking the time to review this again.
Yes, I did run the code without the 'delay(INTERVAL)' and the simultaneous boxed squarewave never goes low, ie the output on 'outPin' ---blue trace on scopeshots stays HIGH. So the squarewave never happens.
This is because I am using this as control for the square wave and not related to the pwm ramp wave.
(there are two waveforms being generated at the same time. please see my scopeshots).
Yes, I will change or delete the 'Dir=2' tomorrow and run it again after work.
When I originally put 'Dir=2' in the loop it made the rampwave duty cycle shorter, go figure.....
Will recheck tomorrow.
I will also change the code to: StartUs += rampLength, did have that on one of my versions of this code, don't remember why I changed it back??????
How about you just do enum ramp_direction {FALLING=-1, PAUSED=0, RISING=1}; and use those values?
Can this be implemented with the map AnalogRead input?
The 'PAUSED=0' is the ramp deadtime? correct?
I will rewrite this tomorrow and run it and then post back.
Thanks again.
take care, peace
lost_bro