So I've got a waveform that's high for 16ms and low for 2ms repeating forever. I need to recreate that and offsets of that waveform time exactly on a different pin. Right now, I've got an interrupt on the rising edge for the 16ms low/high transistion, and delayMicroseconds() that determines the offset and duration of the high and low pulses. Trouble is, I'm not sure the code I have is as fast and accurate as it could be. And the replicated waveform seems to shift through the full period of the original one. I need it to be locked in.Any suggestions? Here is the code:
//3 is interrupt for Timing
//4 through 11 are Time dependent receivers
//3-11 Pins 12-19
char incomingByte = 0;
int pins[9] =
{
3,4,5,6,7,8,9,10,11
};
void timing()
{
//Serial.println("This is a 0ms Event");
// if(Serial.available() > 0)
// {
incomingByte = Serial.read();
Serial.print("I received");
Serial.println(incomingByte);
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
delayMicroseconds(16000);
digitalWrite(10, LOW);
delayMicroseconds(2000);
digitalWrite(10, HIGH);
}
//}
void setup() {
// put your setup code here, to run once:
for(int i=0;i<8;i++)
{
pinMode(pins[i], INPUT);
}
pinMode(3,INPUT);
attachInterrupt(1,timing,RISING);
//Begins Serial
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
}
Here's the waveform I'm trying to duplicate:
Serial
inside a function that is called by a timer. Never.