I am totally new to the Arduino world (and programming) buying my first UNO a few weeks back with the thought I could easily repair a Fuel flow gage when the sending transducer died and learn about Arduino along the way.
I had found a better flow transducer but its output (i.e. pulses/Gal) is not the same as the OEM flow transducer. (And they stopped making the OEM due to quality issues.)
My thought was to simply read the frequency of the transducer, apply a correction factor and then out put the new frequency to the Fuel Flow Display. The frequency needed is quite low 1~500Hz.
I have tried two “period” measuring libraries both of which can read the pulses from the NEW flow transducer. The first one was from Martin Nawrath, “FreqPeriod” http://interface.khm.de/index.php/lab/experiments/frequency-measurement-library/ and the second was from PJRC, “FreqMeasure” https://www.pjrc.com/teensy/td_libs_FreqMeasure.html. My problem comes in trying to send the corrected frequency from the UNO. I thought I had the answer with a library called PWM http://forum.arduino.cc/index.php/topic,117425.0.html . This function can set the PWM frequency to any value from 1Hz to 2MHz. It also worked great “independently”! When I try to run the two functions together the PWM does not work.
I think the problem is I need to be able to STOP the “FreqMeasure” function before running the PWM function. I thought the “FreqMeasure.end” was supposed to do that, but it does not and the “FreqPeriod” does not have such a command. When I comment out either function the remaining works as expected. I just cut & pasted the example sketches into the following: Can someone please show me where I’m going wrong. Thanks!
#include <FreqMeasure.h>
#include <PWM.h>
int32_t LCDout;
float frequency;
int LCD=9;
float sum;
//=====================
void setup() {
InitTimersSafe();
FreqMeasure.begin();
Serial.begin(115200);
}
//==========================
void loop() {
sum = FreqMeasure.read();
frequency = FreqMeasure.countToFrequency(sum);
Serial.print("\t input: ");
Serial.print(frequency);
Int32_t LCDout = 2.5635 * frequency +9.8263;
Serial.print("\t output ");
Serial.println(LCDout);
FreqMeasure.end;
//set the PWM frequency to the new
SetPinFrequencySafe(LCD,LCDout);
delay(50);
sendFREQ();
}
//============================
void sendFREQ(){
//set dutycycle for PWM and send frequency
pwmWrite(LCD,125);
delay(50);
return;
}