Interrupt too slow to count 21Hz? #1629
-
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
For I2S we have run 1000s of interrupts per seconds doing a lot more work than just incrementing a variable. I suggest making a simple MCVE sketch that just counts that edge and posting it so we can offer some advice. |
Beta Was this translation helpful? Give feedback.
-
No problem:
|
Beta Was this translation helpful? Give feedback.
-
Yes, I already used uint32, no changes. So you want me to probe the output signal with the sketch? |
Beta Was this translation helpful? Give feedback.
-
Jupp, its the 25kHz PWM what screwed it up:
counts to 100-101 - but the 25kHz are needed for the fan-PWM. So what should I do? |
Beta Was this translation helpful? Give feedback.
-
@pcfreak1201 It looks like you're calling analogWrite() too often. Each time you do that it may start the PWM cycle again; I'm not sure. Either way, there's no benefit to updating more often than once in every several cycles of its output. Have you checked it's producing what you think it is from the PWM pin? If you're aiming to produce a 20Hz PWM signal, you probably shouldn't try updating the PWM value more than a few times a second. If you want to time how many counts there were in a certain time interval, you should probably set that quite a bit slower than the update period, otherwise you won't be getting much precision in the answer - the count will always be very small, so difficult to compare differences. Also bear in mind that the ADCs are quite noisy, and non-linear. The value will keep changing even though you're not moving the pot, and a small movement won't necessarily always result in a small change in the output - there can be big jumps in it because the ADCs have quite serious design flaws. |
Beta Was this translation helpful? Give feedback.
-
Ahh, OK. I'll try to calculate as mich as possible in the loop and wait min time before wrting the new value. That could work. Otherwise I'll could use a state-machine to slow down. Thanks, I'll report ... |
Beta Was this translation helpful? Give feedback.
@pcfreak1201 It looks like you're calling analogWrite() too often. Each time you do that it may start the PWM cycle again; I'm not sure. Either way, there's no benefit to updating more often than once in every several cycles of its output. Have you checked it's producing what you think it is from the PWM pin?
If you're aiming to produce a 20Hz PWM signal, you probably shouldn't try updating the PWM value more than a few times a second. If you want to time how many counts there were in a certain time interval, you should probably set that quite a bit slower than the update period, otherwise you won't be getting much precision in the answer - the count will always be very small, so difficul…