I have this prodject "Working" just need some advice on how to approach a few issues.
Just sitting at idle from start up I am getting very erratic results in my display anywhere from 11 to 150 mph just at idle.
I am using pulseIn to measure the timing of the pulses then calculate the speed.
I am beginning to think pulseIn is to sensitive for what I am using it for?
It also appears that I need some form of averaging readings out but it is obvious I need to get stable readings first. I seem to be having a noise problem.
Is there some smarter way of pulling this off or any advice on how to to clean up my readings?
#include <WiseChipHUD.h>
// Notes
// built around a sparkfun redbord turbo
// vhicle is set to 4000 PPM square wave pulse 0-5v
// PPM = Pulses Per Mile
// mesuring the time between pulses in micro seconds
// vss input pin = 12
// maxamum display number is 199
//
WiseChipHUD myHUD; //sets up myHUD
unsigned long VSS; // vhucle speed sensor input
int MPH;
void setup() {
pinMode(12, INPUT);
myHUD.begin(); // sets up myHUD
SerialUSB.begin(9600);
delay(3000);// delay to get car started and running
myHUD.clearAll();// clears all segments
//while (!SerialUSB); //===================================================debug code requires moniter to be open before continung =======================
// cool start up sequince for display
for (int i = 0; i< 199; i += 5) {
//myHUD.setTirePressure(i, 1);
myHUD.setSpeedometer(i); }
delay(1000);
myHUD.clearAll(); //clears start up display
myHUD.setSpeedometer(0); // sets redings to zero
}
void loop() {
delay(1000);
VSS = pulseIn(12, HIGH, 10000000); // IF NO PULSES IN 10 SECONDS TIME OUT and return zero mesured in microseconds
//VSS = 12345;// ==========Testing Code will simulate VSS signal should be 72 mph COMMENT ME OUT!!!!!=======================
if (VSS != 0) // changed to VSS from MPH change back if nessary
{
MPH = 900000/VSS;// math for microsconds to mph
}
if (VSS == 0)
{
MPH = 0;
}
if (MPH > 199)
{
MPH = 0;
}
abs(MPH); // round down to the nerist whole number
//===================================================Serial====================================================
SerialUSB.println("VSS Times Microseconds");
SerialUSB.println(VSS, DEC); // send data over usb serial connection
SerialUSB.println("MPH");
SerialUSB.println(MPH, DEC);
//=================================================Dispay======================================================
myHUD.setSpeedometer(MPH);//sets display to calculated number
}// end of void loop
Small output of the serial monitor from idle
VSS Times Microseconds
12420
MPH
72
VSS Times Microseconds
3880
MPH
0
VSS Times Microseconds
71913
MPH
12
VSS Times Microseconds
29622
MPH
30
VSS Times Microseconds
37831
MPH
23
VSS Times Microseconds
76486
MPH
11
VSS Times Microseconds
57869
MPH
15
VSS Times Microseconds
79062
MPH
11
Thanks for having a look Hive mind of the interwebs
