Author Topic: ESP32 ADC non-blocking library  (Read 3631 times)

0 Members and 1 Guest are viewing this topic.

Offline BootalitoTopic starter

  • Supporter
  • ****
  • Posts: 116
  • Country: us
    • EasyEda.com/TerryJMyers
ESP32 ADC non-blocking library
« on: February 27, 2018, 04:42:50 am »
I created an easy library for the ESP32 arduino toolchain to read the ADC, average up to 1,000,000 samples, linearize it (because the integral non-linearity is horrible), all with non-blocking code.  The pieces to make a fully functional non-blocking analogRead were already a part of the ESP32 arduino toolchain, I just put the puzzle together, added averaging, and a means to calibrate it (linearize), and packaged it.

The code arbitrates the ADC in a round-robin or token fashion, so you can instantiate the library for however many GPIO pins you need as ADCs, and a Global token takes care of who gets to use the ADC

https://github.com/terryjmyers/analogReadNonBlocking
 
The following users thanked this post: hamster_nz

Online thm_w

  • Super Contributor
  • ***
  • Posts: 6373
  • Country: ca
  • Non-expert
Re: ESP32 ADC non-blocking library
« Reply #1 on: February 27, 2018, 09:05:47 pm »
Your code doesn't prevent taking more than 1,000,000 averages and overflowing the average summing variable >:D

Nice work.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Geoff_S

  • Regular Contributor
  • *
  • Posts: 88
  • Country: au
Re: ESP32 ADC non-blocking library
« Reply #2 on: February 28, 2018, 11:09:39 am »
Isn't there a possibility of a race condition ?  I've only briefly looked at your code, but it looks like it:
1. checks to see if a token is available,
2. if it is, it starts an ADC conversion
3. AND THEN increments the token counter.

What's to stop another instance also starting during step 2 ??
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf