According to the documentation this library repurposes TIMER1 for counting the frequency. However PWM for pins 9 and 10 requires TIMER1 with the default setup.
Arduino frequency counter Issue
Question
I am successfully using this great Arduino frequency library: Arduino frequency counter.
But there is one issue with my LEDs. They are working if I give them the value "HIGH" or "255". But however they are not working with a lower value. I have tested the LEDs in another sketch. So they are correctly wired and are working fine, also the Arduino. It seems to be a problem with the "FreqCounter::start(100);" line. If I remove it, the lower values are working, but of course the frequency counter is not...
How can I fix this problem?
Here's the code:
#include <FreqCounter.h>
unsigned long frq;
/*** OUTPUT LED ***/
int ledGreen = 9;
int ledYellow = 10;
int ledRed = 11;
void setup() {
pinMode(ledGreen, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledRed, OUTPUT);
Serial.begin(115200);
Serial.println("Frequency Counter");
}
void loop() {
/*** WRITE ***/
analogWrite(ledGreen, 255);
analogWrite(ledYellow, 100);
analogWrite(ledRed, 10);
/*** FREQUENCY COUNTER ***/
FreqCounter::f_comp = 10; // Calibration value / calibrate with a professional frequency counter
FreqCounter::start(100); // 100 ms gate time
while (FreqCounter::f_ready == 0){
frq = FreqCounter::f_freq;
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow