I'm having a current problem with printing out my frequency in decimals, it compiles but its now giving me the values im not expecting, for example, when i lower my frequency to 500 mHZ or (.5 Hz), it will show 0.50 mHZ or 1 Hz and not anything like .678 or .456 considering i noticed that there was a consisent 13% error difference in my code. also another that i have is i tried to change the delay the frequency was read from every 1 second to every 10 seconds, it did delay by 10 seconds but it also ended up multiplying my frequnecy output by 10 as well this the code i used:
void signalChanged_ISR(){counterSet++;}
const float frequencyPin = A5;//A5 will be declared as an input pin
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);// set transfer speed to 9600 bits per second
attachInterrupt(0, signalChanged_ISR, CHANGE);
counterSet = 0;
pinMode(frequencyPin, INPUT);//Declared A5 as an input pin
}
void loop() {
// put your main code here, to run repeatedly:
long min = 1000000; //making sure that the voltage never goes above this limit
long max = -1000000;//making sure that the voltage never goes below this point
for(int i = 1; i<1000; i++)
{
long voltage = (long) (((float)analogRead(frequencyPin))/1024.0f * 5.0f * 1000.0f);
if(voltage > max) max = voltage; if( voltage < min) min = voltage;
delayMicroseconds(10000);//this will delay the reading by 1 second
}
Serial.print(float(counterSet/2)); Serial.print(" Hz at "); Serial.print(min); Serial.print("..."); Serial.print(max); Serial.println("mV");// this will print out the wording of the frequency that this many millvolts
counterSet = 0;
}
are there any simple solutions or tips that i can do to fix this.