Hi to all,
I have made and engine RPM sensor with Teensy 4.1 board. It is reading alternators rpm and write it to Dwin HMI. I have used LJ12A3-4-z/AY PNP inductive sensor. It trigers once per revolotion. My problem is this : It reads normally until the 3600 rpm. But it can not read more than this value although it has 500 Hz switching capacity. (it should read 30.000 PRM for 1 trigger per revolotion) What can be the problem? Could you investigate my code and circuit below please?
Code:
#include <TeensyThreads.h>
#include <Arduino.h>
int rpm =0; //Engine RPM value
const int rpmsensorPin = 40; // Engine RPM Proximity Sensor Input Pin
volatile int rpmpulseCount = 0;
unsigned long rpmlastTime = 0;
//**************** Dwin HMI Communication Parameters **************
#define mySerial Serial1 //UART communication for Dwin HMI
elapsedMillis tRPM;
unsigned char rpmdeger[8] = {0x5a, 0xa5, 0x05, 0x82, 0x52 , 0x00, 0x00, 0x00};
//==================================== ISR ===========================================================
void rpmpulseISR() { rpmpulseCount++;}
//*********************** Engine RPM Calculation & Write to Dwin *************************************
void taskRPM()
{
while (1)
{
if (tRPM >= 1000)
{
noInterrupts();
rpm = (rpmpulseCount*60/3); //Alternator/engine speed ratio is 3
rpmpulseCount = 0;
rpmdeger[6] = highByte(rpm);
rpmdeger[7] = lowByte(rpm);
mySerial.write(rpmdeger, 8);
tRPM = 0;
}
threads.delay(10);
interrupts();
}
}
void setup()
{
Serial.begin(115200);
mySerial.begin(115200);
threads.addThread(taskRPM);
}
void loop()
{
// No need to add code here
}
Circuit: Attached.
I have made and engine RPM sensor with Teensy 4.1 board. It is reading alternators rpm and write it to Dwin HMI. I have used LJ12A3-4-z/AY PNP inductive sensor. It trigers once per revolotion. My problem is this : It reads normally until the 3600 rpm. But it can not read more than this value although it has 500 Hz switching capacity. (it should read 30.000 PRM for 1 trigger per revolotion) What can be the problem? Could you investigate my code and circuit below please?
Code:
#include <TeensyThreads.h>
#include <Arduino.h>
int rpm =0; //Engine RPM value
const int rpmsensorPin = 40; // Engine RPM Proximity Sensor Input Pin
volatile int rpmpulseCount = 0;
unsigned long rpmlastTime = 0;
//**************** Dwin HMI Communication Parameters **************
#define mySerial Serial1 //UART communication for Dwin HMI
elapsedMillis tRPM;
unsigned char rpmdeger[8] = {0x5a, 0xa5, 0x05, 0x82, 0x52 , 0x00, 0x00, 0x00};
//==================================== ISR ===========================================================
void rpmpulseISR() { rpmpulseCount++;}
//*********************** Engine RPM Calculation & Write to Dwin *************************************
void taskRPM()
{
while (1)
{
if (tRPM >= 1000)
{
noInterrupts();
rpm = (rpmpulseCount*60/3); //Alternator/engine speed ratio is 3
rpmpulseCount = 0;
rpmdeger[6] = highByte(rpm);
rpmdeger[7] = lowByte(rpm);
mySerial.write(rpmdeger, 8);
tRPM = 0;
}
threads.delay(10);
interrupts();
}
}
void setup()
{
Serial.begin(115200);
mySerial.begin(115200);
threads.addThread(taskRPM);
}
void loop()
{
// No need to add code here
}
Circuit: Attached.