Call function independent on off switch and repeat for loop

Status
Not open for further replies.

Bastiaan

Well-known member
Code:
Int independent_On_Off()
{

    if ((ON_VNH5019 == HIGH) && (ElapsedOFF >= OFFTime1)) //OFFTime first
        {
          ON_VNH5019 = LOW;
          // ElapsedOFF=ElapsedOFF-OFFTime1;
          //switch off the VNH5019
          digitalWrite(INA,LOW); digitalWrite(INB,LOW);//break mode

          ElapsedOFF = 0; ElapsedON = 0;
          //      tft.setRotation(4);
          tft.fillRect(110, 145, 10, 10, C_RED);
        }
        else if ((ON_VNH5019 == LOW) && (ElapsedON >= ON_Time1))    //ONTime Second
        {
          ON_VNH5019 = HIGH;
          ElapsedOFF = 0; ElapsedON = 0;
          INA==HIGH,INB==HIGH;
         Switch_UtoBipolar();

        }
        if (ON_VNH5019 == LOW) tft.fillRect(110, 145, 10, 10, C_YELLOW); 
      }




}


Int Switch_UtoBipolar()
{

if(myButton.held() == true) //Bipolar
{
for(int i=0;i<repeats;i++)
{
if((INA==HIGH&&INB==HIGH)&&(INA==LOW&&INB==LOW)) //start condition.

INA==LOW, INB==HIGH;
digitalWrite(INA,Pin1);digitalWrite(INB,Pin2);

}
else //holdbutton is pressed for the second time
{
INA==HIGH, INB==LOW;
digitalWrite(INA,Pin1);digitalWrite(INB,Pin2);
}// i dont think this is going to work....
}
else //unipolar
{
for(int i=0;i<repeats;i++)
{
if((INA==HIGH&&INB==HIGH)&&(INA==LOW&&INB==LOW))
{
INA==LOW, INB==HIGH;
digitalWrite(INA,Pin1);digitalWrite(INB,Pin2);
}
else
{
INA==HIGH, INB==HIGH;
digitalWrite(INA,Pin1);digitalWrite(INB,Pin2);
}
}

}


I’d expect the code will run this as fast as possible and toggle the digitalWrite
INA,INB during the ON time of the independent On_Off function.
Is there a way to check that there is a delay time between INA and INB.
The reason for this is that I don’t know if the VNH5019 does this automatically see datasheet on page 9 Tdel

Many thanks for reading!

Best regards

Bastiaan
 
I guess I don't fully understand, but I'm assuming you mean check that when you do something like this, that it happens simultaneously?
Code:
 digitalWrite(INA,LOW); digitalWrite(INB,LOW);

I don't know of a way to check the delay between digital writes without affecting the timing, maybe could be done but may also just be a rabbit hole where you actually change the outcome.

The biggest thing I would do is if it's timing critical use digitalWriteFast() - it's a library that directly manipulates the ports for speed. The documentation says digitalWrite() in Arduino Uno core (16MHz) takes about 6280nS while digitalWriteFast() port manipulation takes 125nS. Maybe not as big a difference with our higher teensy clock speeds, but something to look into.
 
Status
Not open for further replies.
Back
Top