Speed Loging

Hello everybody,

My plan is to serial send with an interrupt timer, the analog values which i want, the numbers of revolutions of a skate wheel and the time. The frequency of the analog send must be about 125Hz.

I'm trying to log speed using a hall detector with pin interrupt and two (or four) analog val with a Uno and a processing code on the computer, but i have some troubles.

When the wheel is turnig too fast => about 15 Hz, the interrupt send back variable compt of revolution during my wheel is turning constantly.

here my code :wink:

//----------------------------------------------- 

volatile byte revolutions;

volatile boolean flag;

unsigned long realtime;

unsigned int tension1;

unsigned int tension2;

void setup()
 {

  noInterrupts(); // désactiver toutes les interruptions
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;

  OCR1A = 500; // (500)16MHz/256/125Hz (fréquence d'écriture serie (echantillonage?))
  TCCR1B |= (1 << WGM12); // CTC mode
  TCCR1B |= (1 << CS12); // 256 prescaler
  TIMSK1 |= (1 << OCIE1A); // Activer le mode de comparaison
  interrupts(); // activer toutes les interruptions

 //Liaison serie 
   Serial.begin(250000);

  //gestion des interruptions
   //interruption du capteur à effet hall
   attachInterrupt(0, rpm_fun, FALLING);

 }


void loop() {

  if (flag){
    //lecture des données
    tension1=analogRead(A0);
    tension2=analogRead(A1);
    realtime=millis();
  
    // ecriture des données
    Serial.print(revolutions);
    revolutions=0;
    Serial.print(',');
    Serial.print(tension1);
    Serial.print(',');
    Serial.print(tension2);
    Serial.print(',');
    Serial.print(realtime);
    Serial.println();
    flag=false;
  }
}

ISR(TIMER1_COMPA_vect){ // fonction périodique d'interruption pour ecriture sur la voie serie
  flag=true; 
}


//Interruption qui à lieu à chaque front montant sur le capteur 
void rpm_fun(){
   revolutions++;
}

Does someone have an idea?

Sorry for the French commentary and my bad English, but i'm trying to improve it ;-).

Thank you.

Why not try posting in the French forum? Be easier not to lose things in translation.

Neatly tucked away here if you want to give it a try:
https://forum.arduino.cc/index.php?board=33.0