Go Down

Topic: Syncing Problem with two singnals (Read 103 times) previous topic - next topic

Crameroni

Hello
Does anybody have an idea, why the two signals are starting at different points of time?
I want them to start at the same time, but stay on for seperate times.
I attached a screenshot from my oscilloscope.

It looks like the case of setting the pin low is synchron but I want them to start high synchronous.

Thanks for your answers.

Crameroni



Quote
int VVRPin =  22;      // the number of the VVR pin
int VDRPin = 23;       // the number of the VDR PIN

int VVRState = LOW;     // VVRState used to set the VVR
int VDRState = LOW;    // VDRState used to set the VDR

unsigned long previousVVRMillis = 0;        // will store last time VVR was updated
unsigned long previousVDRMillis = 0;       // will store last time VDR was updated


long VVROnTime = 25;          // milliseconds of on-time VVR
long VVROffTime = 1970;       // milliseconds of off-time VVR
long VDROnTime = 210;         // milliseconds of on-time VDR
long VDROffTime = 1785;       // milliseconds of off-time VDR

void setup()
{
  // set the digital pin as output:
  pinMode(VVRPin, OUTPUT);
  pinMode(VDRPin, OUTPUT);
}

void loop()
{
  unsigned long currentMillis = millis();

  if ((VVRState == HIGH) && (currentMillis - previousVVRMillis >= VVROnTime))
  {
    VVRState = LOW;  // Turn it off
    previousVVRMillis = currentMillis;  // Remember the time
    digitalWrite(VVRPin, VVRState);  // Update the actual VVR
  }
  else if ((VVRState == LOW) && (currentMillis - previousVVRMillis >= VVROffTime))
  {
    VVRState = HIGH;  // turn it on
    previousVVRMillis = currentMillis;   // Remember the time
    digitalWrite(VVRPin, VVRState);    // Update the actual VVR
  }



  if ((VDRState == HIGH) && (currentMillis - previousVDRMillis >= VDROnTime))
  {
    VDRState = LOW;  // Turn it off
    previousVDRMillis = currentMillis;  // Remember the time
    digitalWrite(VDRPin, VDRState);  // Update the actual VVR
  }
  else if ((VDRState == LOW) && (currentMillis - previousVDRMillis >= VDROffTime))
  {
    VDRState = HIGH;  // turn it on
    previousVDRMillis = currentMillis;   // Remember the time
    digitalWrite(VDRPin, VDRState);    // Update the actual VVR
  }
}

weird_dave

You are starting with both on states low, they are low for different lengths of time, so they go high at different times the first time round and continue from there. The reason they look synced on the falling edge is simply because your total times are the same, so they drop together.

Go Up