KrisKasprzak
Well-known member
All,
I have a telemetry system that measures wheel rotations where the sensor generates a pulse for every revolution. When displaying the speed I'm computing rpm using the example in <FreqMeasure.h> and displaying the data along with graphics and such. Input pin is pin 22, I have several units based on T3.2 and T4.0. My test stand my wheel is generating a 25 hz pulse and very square as my scope shows. I was using #include <FreqMeasureMulti.h> and results were... [EDIT] Results were very bad, hence why I moved to FreqMeasure.h
Moving my code to FreqMeasure.h breaks when drawing graphics. When drawing only speed to an ILI9341 (2.8"), results are 27.0 +/- 0.1 (which is correct by the math). When I start drawing graphics, FreqMeasure jumps around 60 to 120.
I'm guessing it's a clock timing issue, but I'm not sure. Can anyone help?
I have a telemetry system that measures wheel rotations where the sensor generates a pulse for every revolution. When displaying the speed I'm computing rpm using the example in <FreqMeasure.h> and displaying the data along with graphics and such. Input pin is pin 22, I have several units based on T3.2 and T4.0. My test stand my wheel is generating a 25 hz pulse and very square as my scope shows. I was using #include <FreqMeasureMulti.h> and results were... [EDIT] Results were very bad, hence why I moved to FreqMeasure.h
Moving my code to FreqMeasure.h breaks when drawing graphics. When drawing only speed to an ILI9341 (2.8"), results are 27.0 +/- 0.1 (which is correct by the math). When I start drawing graphics, FreqMeasure jumps around 60 to 120.
I'm guessing it's a clock timing issue, but I'm not sure. Can anyone help?
Code:
#include <FreqMeasure.h>
#include <TimeLib.h>
#include <ILI9341_t3.h>
ILI9341_t3 Display(9, 2);
elapsedMillis UpdateDiaplay = 0;
void setup() {
Serial.begin(115200);
FreqMeasure.begin();
Serial.println("Starting");
Display.begin();
Display.setTextWrap(false);
Display.setRotation(1);
Display.fillScreen(0);
}
double sum = 0.0, WRPM = 0.0;
float CarSpeed = 0.0;
int count = 0;
void loop() {
delay(5);
if (FreqMeasure.available()) {
sum = sum + FreqMeasure.read();
count = count + 1;
if (UpdateDiaplay > 200) {
UpdateDiaplay = 0;
ComputeSpeed();
DisplaySpeed();
}
}
}
void ComputeSpeed() {
WRPM = 15.0 * FreqMeasure.countToFrequency(sum / count);
CarSpeed = (WRPM * 9.125 * 2.0f * 3.14159f * 60.0f / (12.0f * 5280.0f));
sum = 0;
count = 0;
}
void DisplaySpeed() {
// I need to draw graphics--small stuff will not break the FreqMeasure code
// Display.fillRect(0,0,300,50, 2000);
// larger will
Display.fillRect(0, 0, 300, 150, 2000);
Display.setTextSize(4);
Display.setCursor(5, 200);
Display.setTextColor(65535, 0);
Display.println(CarSpeed, 1);
Serial.println(CarSpeed);
// if I restart FreqMeasure, results are less irratic, but incorrect
FreqMeasure.begin();
}
Last edited: