Go Down

Topic: Is this too big for ISR ? (Read 1 time) previous topic - next topic

FardinB

I need to send these data every millisecond to the PC.

Any help is appreciated

Thanks

Nick Gammon

Just set a flag, test it in loop, and do your readings and displays there.

Nick Gammon

It's nothing to do with processing power. Don't do Serial.print inside an ISR.

http://www.gammon.com.au/interrupts

FardinB

#1
Oct 11, 2012, 12:24 am Last Edit: Oct 11, 2012, 12:27 am by FardinB Reason: 1
Hi, I was wondering if this ISR is too much for processing power of Arduino?

The interrupt is set at 1kHz
Code: [Select]

ISR(TIMER1_COMPA_vect) {  //Interrupt at freq of 1kHz
 distance = getDistance(Lsensor);
 pressure = getPressure(Psensor);
 prSwitch = getPswitch(Pswitch);
 temp = getTemperature(tmp);
 Fldtemp = getTemperature(Fluidtmp);
 
 Serial.print(drive);
 Serial.print(" ");
 Serial.print(distance);
 Serial.print(" ");
 Serial.print(pressure);
 Serial.print(" ");
 Serial.print(prSwitch);
 Serial.print(" ");
 Serial.print(temp);
 Serial.print(" ");
 Serial.println(Fldtemp);
}

And here are the function calls in the ISR:
Code: [Select]

int getPressure(const int pin) {
 float ADCpressure = analogRead(pin);
 ADCpressure = (ADCpressure/1023)*25;
 return (int) ADCpressure;
}

int getPswitch(const int pin) {
 if(digitalRead(pin) == HIGH)
 {
   return 1;
 }
 if(digitalRead(pin) == LOW)
 {
   return 0;
 }
}

int getTemperature(const int pin) {
  float ADCtemperature = analogRead(pin);
  ADCtemperature = ADCtemperature/1.023;
  return (int) ADCtemperature;
}

int getDistance(const int pin) {
  return analogRead(pin);
}


Any ideas on how to make this work?

Go Up