I would like to count a frequency coming off a Mesa THC A-D Card and convert that frequency back to the voltage that is being presented to that card. I've found a sample code/library that seems to work ok but I'm struggling to convert back to the original voltage. The THC A-D card has 10v = 926.5 kHz and 0v = 119.7 kHz and I can make the voltage match at 10v by taking the frequency by .0000107933 but that falls apart as the voltage drops. Is there a better way to count/convert the frequency?
With the math I have, at 10v it is correct but at as I go lower it starts getting further off. 3v at the power supply is reading as 2v for instance.
I'm multiplying by 128 because the THC A-D card is dividing the frequency by 128 on the output. Multiplying by 10 because of the gatetime.
Code:
#include <FreqCounter.h>
void setup() {
Serial.begin(57600); // connect to the serial port
Serial.println("Frequency Counter");
}
long int frq;
void loop() {
FreqCounter::f_comp= 8; // Set compensation to 8
FreqCounter::start(100); // Start counting with gatetime of 100ms
while (FreqCounter::f_ready == 0) // wait until counter ready
frq=FreqCounter::f_freq; // read result
Serial.println(frq*10*128); // print result
Serial.println(frq*10*128*10.0f/926500,2);
delay(20);
}