I have what I thought was a simple task, to insert a short time delay in a signal (in this case the output from a hall sensor (signal transition every 9ms)) via the use of an interrupt and a simple loop:
void HAInt()
{
for (unsigned long i = 0;i<5;i++);
digitalWrite(HAOut, digitalRead(HAInt3));
}
attachInterrupt(3, HAInt, CHANGE);
Interestingly, no matter what number I put in the for loop (5, 50, 500, 5000, 50000, 500000) it has no effect on when the digitalWrite event occurs. Could this be because the compiler sees that the for loop does nothing and optimizes it out?
Since I can't use delay() functions in interrupts what is the proper method of inserting a time delay?
Are you hoping to get a 9 millisecond delay in your ISR?
no, I really don't know but I'm guessing the range could be anywhere from 20uS to 2mS
I've got 3 signals I need to condition. I realize that putting delays in ISR's isn't good, but this is a proof of concept, not a final implementation. the final implementation will use a hardware delay - I am using Arduino to determine what that delay is.