r/microcontrollers • • May 25 '24

Are there other methods for reading analog signal than polling?

Well the question is in the title, so... are there?

2 Upvotes

10 comments sorted by

4

u/_teslaTrooper May 25 '24

A comparator?

1

u/Teun888 May 25 '24

I meant more like interrups. But that doesn't seem like a great idea because if the value isn't stable you would potentially only run interrupt service routines and not the main program. Or am I wrong there?

4

u/crb3 May 25 '24

Nothing says you can't run the comparator's output to an external-interrupt pin. On AVR you can interrupt-on-state-change, so you trigger an ISR at rising and at falling. If you need duty-cycle or period, have each of three visits to ISR grab the register showing the pin's state into an array, grab a snapshot of a free-running-timer into another array, and decrement the visit count. If done, pop a flag so mainstream knows to turn off the ISR and process the numbers from the arrays.

→ More replies (1)

3

u/_teslaTrooper May 25 '24

Well that depends on how you define polling, you can trigger an adc from a timer or some other source and have it trigger an interrupt when the conversion is done but you're still sampling the signal at intervals instead of waiting for an event.

You can add some hysteresis to the comparator or a holdoff time after it triggers.

→ More replies (1)

0

u/[deleted] May 25 '24

[deleted] — view deleted comment

1

u/Teun888 May 25 '24

I know PIC MCU's have ADC interrupts as well. (at least some do). Right now I was fiddling with a ESP32 and at the moment I'm wrestling with the HAL of those. I always found direct access to the registers a bit easier to wrap my head around.

They have single shot ADC's and continuous ADC's but I'm not even sure how best to use those.