Jiggy-Ninja:
Your latest snippet does not havedigitalWrite(outPin,HIGH);. If it's the same as the first sketch you posted, you moved it to the wrong spot. Now you're setting it high on each pass through loop, not just each increment up the ramp. That's the opposite of what you need to do. You need to write the pin less often, not more. Once per pulse, not once per loop.if(Pwm==pwmMax)
{
digitalWrite(outPin,LOW);
delay(ramplength);
}
**Why are you delaying here?** This is what is causing the triangle to turn into a trapezoid. You have the right idea writing the pin LOW here, just ditch the delay.do
{
digitalWrite(outPin, LOW);
} while((Dir==-1) && (Dir != +1));**Why did you try a do-while loop here?** Since you don't change any of the variables in the condition inside the loop, it will either exit after one run or never exit. The second half of the && expression is also redundant; It is logically impossible for Dir to be equal to both -1 and +1, so the result is determined completely by the first half of the expression. You are close. Home stretch.
Hello Jiggy-Ninja
Yes, the digitalWrite(outPin,HIGH); is in the same, wrong place. Actually I tried about every possible place in the program to place that statement to no avail. I've spent more than 20 hours in front of the oscope trying different combinations of code. ![]()
Why are you delaying here? I put the delay there because without delay the offtime is about 800us only, the code does respond, but the offtime is NOT sufficient.
Why did you try a do-while loop here? The do-while attempt was to make the offtime delay without using a delay....... I was trying to keep the squarewave low during the while time of the statement, so no delay would be necessary. I thought the delay would bog the loop down.
I don't really understand where you are suggesting to place the digitalWrite(outPin,HIGH); statement. It looks to be going high in the correct spot on the waveform ( ie. at the start of and concurrent with the rising edge of the triangle wave.).
The part I cannot figure out is how to make the square wave turn off exactly at the apex of the triangle wave and make it STAY off. So far I can make it go into a fast cycling PWM which terminates at the end of the falling edge of the triangle wave, or have two separate squarewaves, one for the rising edge and one for the falling edge.
The problem I am having is that I don't know which parameter should be used in the code to signal the turning off of the squarewave: the attiny is generating a fast variable pwm, which when integrated by means of a low pass filter shows the ramp in my scope shots.
The attiny85 does not see a ramp, it only knows the fast variable pwm which is composed of a rather large number of smaller squarewaves in rapid succession. pwmMax is the only parameter in the code that I see that could be used to trigger at the apex. And it does trigger:
if(Pwm==pwmMax)
{
digitalWrite(outPin,LOW);
delay(ramplength);
}
When I run this code, the squarewave does go low at the apex
but only stays low for the duration of the delay. Without the delay, it goes low for about 800us. This appears as a momentary negative going pulse at the apex. So............ the code does respond, but without some mechanism to hold the squarewave low it will not work as planned.
What am I missing?
If you could be a bit more specific as to any pointer you can give me, with pleasure I will test it.
I will try again tomorrow after work.......... ![]()
take care, peace
lost_bro
P.S. thanks, and just attached the ino. file
Rising_Falling_edge_control.ino (6.03 KB)