You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*
This is a demo of the FreqMeasure library
On an Uno, jumpering pin 3 to pin 8 reports the PWM frequency of 490.20Hz
490.20
490.20
490.20
490.20
490.20
...
With the pin floating with a loose jumper it reports 60Hz hum.
It does not report with pin 8 grounded.
On Wokwi this doesn't appear to work.
I reported this as https://github.com/wokwi/wokwi-features/issues/352
Code: https://wokwi.com/projects/330562550517203540
This is a modificaton of the https://www.pjrc.com/teensy/td_libs_FreqMeasure.html demo code
to add a PWM output on pin 3.
It adds some code to track pin 8;
With the jumper to pin 13 and the switch, you can see the pwm output on the built-in LED and toggle
the connection.
*/
#include <FreqMeasure.h> // https://www.pjrc.com/teensy/td_libs_FreqMeasure.html
void setup() {
Serial.begin(115200);
FreqMeasure.begin();
pinMode(3,OUTPUT); analogWrite(3,127); // 50% duty cycle on pin 3
}
double sum=0;
int count=0;
static uint32_t count8=0;
void loop() {
if (FreqMeasure.available()) {
// average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
float frequency = FreqMeasure.countToFrequency(sum / count);
Serial.println(frequency);
sum = 0;
count = 0;
}
}
count8 += digitalRead(8)==LOW;
report();
}
void report(){
static uint32_t last = -1000;
if(millis() - last >= 1000){
last+=1000;
Serial.print("count8: ");
Serial.println(count8);
}
}
Expected behavior
The same sketch on a silicon Uno with a jumper from 3 to 8 produces this output:
Describe the bug
The ICP1/ICR1 feature doesn't appear to work with the FreqMeasure library on a Simulated Uno while it does on silicon.
Here is a sketch demonstrating it:
https://wokwi.com/projects/330562550517203540
For an Uno, FreqMeasure monitors Timer1 per:
https://github.com/PaulStoffregen/FreqMeasure/blob/8d4485f7f439267f0a9236999bff4f232d8a83dd/util/FreqMeasureCapture.h#L29
The register code that FreqMeasure uses on an Uno is:
https://github.com/PaulStoffregen/FreqMeasure/blob/8d4485f7f439267f0a9236999bff4f232d8a83dd/util/FreqMeasureCapture.h#L393-L435
To Reproduce
Steps to reproduce the behavior, including link to a simulation project where we can see the problem.
Use the demo sketch from https://www.pjrc.com/teensy/td_libs_FreqMeasure.html
I added an
analogOut(3,127);
to make the Uno self-testing. Here's a sketch and code:https://wokwi.com/projects/330562550517203540
Expected behavior
The same sketch on a silicon Uno with a jumper from 3 to 8 produces this output:
I would expect the simulation to behave similarly.
Environment (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: