I know the ISR must run quickly and have tried to make them small. I have some code running, currently, and do not have consistent run times. My guess is I am trying to do too much in the ISR. Can someone give be some guidance on dos and dont's in the ISR? Paul's example shows this
I notice he uses digitalWrite in the ISR. I thought this may be 'too long'. Also, the 'microseconds' argument for the timer, is it an unsigned long? Not clear form the page, but I am guessing it is.
I am cascading 2 timers in my ISRs. When one elapses, I start another one. Is this too much to do in the ISR? Also, I am writing pins, stopping timers starting timers and such. Is this too much? What this code does is shove a solenoid to one side then reverses. I trigger the coil form the main code and start a timer to time the pulse (stopPulse). When this elapses, I start another timer (drainTimer). when it elapses, I run the first timer again. What I have noticed is that the times when we watch the solenoid with high speed video are not consistent. Sometimes it is close to what we have set as variables in code, other times it is slow.
Mine are:
Thanks for the help.
Keith
Code:
void blinkLED(void) {
if (ledState == LOW) {
ledState = HIGH;
blinkCount = blinkCount + 1; // increase when LED turns on
} else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
I am cascading 2 timers in my ISRs. When one elapses, I start another one. Is this too much to do in the ISR? Also, I am writing pins, stopping timers starting timers and such. Is this too much? What this code does is shove a solenoid to one side then reverses. I trigger the coil form the main code and start a timer to time the pulse (stopPulse). When this elapses, I start another timer (drainTimer). when it elapses, I run the first timer again. What I have noticed is that the times when we watch the solenoid with high speed video are not consistent. Sometimes it is close to what we have set as variables in code, other times it is slow.
Mine are:
Code:
int32_t drainTime = 10; // ms
int32_t actuationTime = 50; // ms
void stopPulse(void) { // when this pulse timer expires, stop pulse
pulseTimer.end(); // turn timer off
digitalWriteFast(motInA, LOW); // turn off drive pins
digitalWriteFast(motInB, LOW);
if (runFlag && solFlag){ // if we are running and the solenoid is open start a timer
drainTimer.begin(drainer, (unsigned long) drainTime*1000);
}
}
void drainer(void) {
drainTimer.end();
digitalWriteFast(motInB, HIGH);
solFlag = LOW;
pulseTimer.begin(stopPulse, (unsigned long) actuationTime*1000); // start timer to run in microseconds
startTime = millis(); // variable for use in the code
}
Thanks for the help.
Keith