nodemand
Member
I'm trying to generate a precise low frequency short pulsed signal of 500Hz.
This works perfectly with delayMicroseconds, but as soon as I swap it out with delayNanoseconds and adjust the delay accordingly, to me unexplainable things start to happen. I would think the following code should generate a 500Hz signal, but my scope says different. 8.06kHz.
What is going on?
Thanx for any help!
This works perfectly with delayMicroseconds, but as soon as I swap it out with delayNanoseconds and adjust the delay accordingly, to me unexplainable things start to happen. I would think the following code should generate a 500Hz signal, but my scope says different. 8.06kHz.
What is going on?
Thanx for any help!
Code:
const uint8_t pin = 5;
const uint32_t d = 1995000;
void setup() {
pinMode(pin, OUTPUT);
}
void loop() {
digitalWriteFast(pin, HIGH);
delayNanoseconds(5000);
digitalWriteFast(pin, LOW);
delayNanoseconds(d);
}