Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Call function independent on off switch and repeat for loop

  1. #1
    Senior Member
    Join Date
    Sep 2016
    Posts
    174

    Call function independent on off switch and repeat for loop

    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

  2. #2
    Member pilotplater's Avatar
    Join Date
    Dec 2017
    Location
    Ontario, Canada
    Posts
    31
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •