I want to count 4 speed channels of rpm
each sensor has 360 pulses
if anyone is interested the code below will update 100 times a second and seems pretty accurate
So far i have only been able to count on one channel - i will program another teensy to pulse 4 channels
the code works up to approx 270 khz plenty fast enough for me
is this a good strategy for counting 4 speed channels ?
each sensor has 360 pulses
if anyone is interested the code below will update 100 times a second and seems pretty accurate
So far i have only been able to count on one channel - i will program another teensy to pulse 4 channels
the code works up to approx 270 khz plenty fast enough for me
is this a good strategy for counting 4 speed channels ?
Code:
uint8_t pulse_pin1 = 11;
uint8_t pulse_pin2 = 12;
unsigned long NoOfPulses1=360;
unsigned long NoOfPulses2=360;
unsigned long pulseCount1=0;
unsigned long pulseCount2=0;
unsigned long Period1=0;
unsigned long Period2=0;
unsigned long Freq1=0;
unsigned long Freq2=0;
unsigned long RPM1=0.000;
unsigned long RPM2=0.000;
unsigned int DataStamp = 0;
unsigned int NowStamp = 0;
void setup() {
pinMode(pulse_pin1, INPUT_PULLUP);
pinMode(pulse_pin2, INPUT_PULLUP);
Serial.begin(115200);
delay(2000);
DataStamp = micros();
attachInterrupt(digitalPinToInterrupt(pulse_pin1), pulseCounting1, RISING);
attachInterrupt(digitalPinToInterrupt(pulse_pin2), pulseCounting2, RISING);
}
void pulseCounting1()
{
pulseCount1++;
}
void pulseCounting2()
{
pulseCount2++;
}
void loop() {
if (millis() > (DataStamp/1000 + 99)) { // 100 samples per second
NowStamp = micros();
if (pulseCount1 > 0) {
Period1 = ( (NowStamp - DataStamp) ) ;
Freq1 = ((pulseCount1 * Period1)/10000) ;
RPM1 = (Freq1 * 60) / NoOfPulses1 ;
Serial.print("Freq 1: ");Serial.println(Freq1);
Serial.print("RPM 1: ");Serial.println(RPM1);
pulseCount1=0;
}
if (pulseCount2 > 0) {
Period2 = ( (NowStamp - DataStamp) ) ;
Freq2 = ((pulseCount2 * Period2)/10000) ;
RPM2 = (Freq2 * 60) / NoOfPulses2 ;
Serial.print("Freq 2: ");Serial.println(Freq2);
Serial.print("RPM 2: ");Serial.println(RPM2);
pulseCount2=0;
}
DataStamp = micros();
}
}