wingsy
March 25, 2024, 11:40am
1
digitalWrite(LED_BUILTIN, HIGH);
ET = micros();
t1 = pulseIn(inPulse, LOW,1000000);
t2 = micros()-ET;
Serial.print(t1);
Serial.print(" ");
Serial.println(t2);
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
Monitor:
0 691612
0 691612
0 691604
etc.
Whatever I specify for the pulseIn timeout is set to 69% of that. Using Uno. Just me or do you see this too?
(Sorry - left this out:
unsigned long ET = micros(); //
unsigned long t1; //
unsigned long t2;
const long outPulse = 8;
const long inPulse = 7;
void setup() {
Serial.begin(115200);
pinMode(inPulse, INPUT_PULLUP);
pinMode(outPulse,OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
blh64
March 25, 2024, 11:44am
2
Since it is only a snippet of code and not a complete sketch, nobody can see what you see since nobody can compile the code and test it.
Also,what is connected to inPulse?
wingsy
March 25, 2024, 11:47am
3
Posted the rest of the code while you were typing. Nothing connected to inPulse, configured with pullup.
blh64
March 25, 2024, 11:56am
4
You do get that behavior in simulation as well: relays - Wokwi ESP32, STM32, Arduino Simulator
If you look at the documentation, it does say this: "The timing of this function has been determined empirically and will probably show errors in longer pulses." so it doesn't sound too exact.
Try using pulseInLong() instead of pulseIn() .
wingsy
March 25, 2024, 12:28pm
6
That did the trick. Thanks John.
system
Closed
September 21, 2024, 12:29pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.