good morning,
i played a bit with the ElapsedMillis();
so far i got two signals that are shifted please see pictures:
View attachment 24520
View attachment 24521
View attachment 24522
but the pulse train stops after a period of time of 1 second and doesnt repeat.
i removed the functionRepetition_Polarity_Change_Emag()
and used if else statements after the independent on off.
could someone elaborate the ElapsedMillis why it doesnt work inside a nested if statement as in the CODE3?
it just defies logic for me, but it has to do with the global variable i think of ElapsedTimeIndependent and is overwritten?
this code works and creates a pulsetrain for 1 second with 12ms period. 2ms of this period is the pulse HIGH the other signal for unknown reason stays low.
any advice?
i played a bit with the ElapsedMillis();
so far i got two signals that are shifted please see pictures:
View attachment 24520
View attachment 24521
View attachment 24522
but the pulse train stops after a period of time of 1 second and doesnt repeat.
i removed the functionRepetition_Polarity_Change_Emag()
and used if else statements after the independent on off.
could someone elaborate the ElapsedMillis why it doesnt work inside a nested if statement as in the CODE3?
it just defies logic for me, but it has to do with the global variable i think of ElapsedTimeIndependent and is overwritten?
this code works and creates a pulsetrain for 1 second with 12ms period. 2ms of this period is the pulse HIGH the other signal for unknown reason stays low.
any advice?
Code:
//Defining the pins
const int INB_AntiClockwise = 2;
const int INA_Clockwise = 3;
unsigned long previousMillis = 0;
unsigned long Timestamp = 10; //10ms per division
unsigned long PulseWidth = 2; //variable for setting the pulse
unsigned long timer;
unsigned long timer2;
bool VNH5019 = LOW; //it has not effect changing this from int to byte
unsigned int ON_Time1 = 1000; //ON Time
unsigned int OFFTime1 = 1000; //OFF Time
elapsedMillis ElapsedTime; //ElapsedMillis for pulses and period
elapsedMillis ElapsedTimeIndependent;
elapsedMillis pulse; //ElapsedMicros
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT); digitalWrite(13, LOW);
pinMode(INB_AntiClockwise, OUTPUT); digitalwrite(INB_AntiClockwise, LOW);
pinMode(INA_Clockwise, OUTPUT); digitalWrite(INA_Clockwise, LOW);
}
void loop()
{
if ((VNH5019 == HIGH) && (ElapsedTimeIndependent >= OFFTime1)) //OFFTime first
{
VNH5019 = LOW;
digitalWrite(INA_Clockwise, LOW); digitalWrite(INB_AntiClockwise, LOW); //doesnt matter high or low both need to be HIGH or LOW.
ElapsedTimeIndependent = 0;//[COLOR="#FF0000"]this resets the elapsedTime[/COLOR]
}
else if ((VNH5019 == LOW) && (ElapsedTimeIndependent >= ON_Time1)) //ONTime 1 second
{
//Serial.println("On Time");//so that i know i am in this part of the else if statement
VNH5019 = HIGH;
// Repetition_Polarity_Change_Emag(); //this functions sets the PulseWidth and the Period //here I call the function
}
else if (ElapsedTimeIndependent >= (timer + Timestamp))
{
digitalWrite(INA_Clockwise, HIGH);
digitalWrite(INB_AntiClockwise, LOW);
timer = ElapsedTime + 2; //pulse is shifted with 2ms
timer2 = ElapsedTime;
//duration of the Pulse is set here.
Serial.println("TimeStamp");
} // Sets the Output Low for the pulse
else if ((pulse) > (timer + Timestamp))
{
digitalWrite(INA_Clockwise, HIGH);
// Turn the output back to High
}
else if ((pulse) > (timer2 + Timestamp)) //create a shift between the INA and the INB
{
digitalWrite(INB_AntiClockwise, HIGH);
// Turn the output back to High
}
}