DavidAntliff/esp32-freqcount

Library?

chmorgan opened this issue · 7 comments

Hi David.

Looking to use this code to measure fan rpm and it looks like a lot of it could be made more modular and even turned into a library maybe. I’m ending up just copying chunks inline which doesn’t seem ideal. Thoughts?

I did notice that the pcnt setup was outside of the task and was wondering why that was the case. It didn’t look necessary to do it there but clearly it was being done after the task was started so the order seemed important. Is it?

Hi Chris, I put this code up in a bit of a hurry some months ago, it's not really "good enough" as a component. However I did tidy up a version of it here:

https://github.com/DavidAntliff/esp32-poolmon/blob/master/main/sensor_flow.c

As you say it's probably worth turning it into a reusable component. Can you have a look at the code I linked to and see if it's a better candidate for reuse from your perspective? If so I can port that back here and make it a proper component.

Also, I'm not sure if the order is important - in the newer version I init both in the same task.

Hi @DavidAntliff.

I'm back working on this now that I have some hardware that can make use of it. I had a few questions.

It looks as if the rmt and the pcnt_ctrl share a gpio, but this is a separate gpio than the frequency measurement. Is this the case? Does this mean that a user would have to dedicate an unused gpio line for this pcnt/rmt connection?

Hi Chris, yes, the RMT is generating a precisely timed sampling window for the PCNT, and as such it uses the routing matrix to do so, currently via a dedicated GPIO. However, separately, I did find a way to internally route an input signal into an output (such as making the onboard LED on a GPIO follow another input pin) so there may be a way to use this technique and avoid a dedicated GPIO.

Take a look at the code in _display_page_changed here - this makes the onboard LED mirror the frequency input signal when the LCD display is showing the current frequency measurement. You might be able to use a very similar technique to route the RMT output to the PCNT control input. I'm not 100% sure it can be done, but it's worth a look.

Closing this for now - please reopen if you feel it's incomplete.