Interrupt to Detect analog voltage change

Thread Starter

Kenny

Joined Oct 11, 2004
55
I want to connect a "voltage" with a POT to one microcontroller input and do something at every change of the voltage level.
Can it be done with an interrupt or it has to use polling?
 

JohnInTX

Joined Jun 26, 2012
4,787
Pretty much polling (on a PIC anyway) but you could interrupt on completion of each ADC conversion, examine the value and process from there. The PIC 16F1784/7 does up to 75Ksps 12 bits and runs at up to 32MHz clock speed so things are pretty zippy.
 

Thread Starter

Kenny

Joined Oct 11, 2004
55
The thing is that I want to act (do something) just when there is a change on the voltage on the POT.
How can I do it?
I have the following doubt: Given the voltage is analog, will the value read change -even a little- on every cycle of a loop without moving the POT?
 

John P

Joined Oct 14, 2008
2,051
I don't know all the features of every processor, but I'm pretty sure you can get a PIC processor with a D-A converter that would generate a voltage that you could feed into a comparator, and get your interrupt when the pot voltage changes. But most likely you'd be wanting a pair of voltage levels each with a comparator, so you could get an interrupt when the pot input crosses either an upper or a lower bound. That may be harder to find.
 

ErnieM

Joined Apr 24, 2011
8,415
It is quite possible, even expected, that the reading will change even a little on every reading of the pot.

You could take multiple reading and make an average that changes a lesser amount, or make some sort of minimum change to be observed before taking any action.
 

John P

Joined Oct 14, 2008
2,051
That's what I meant about a "window comparator" setup with 2 comparators with slightly different reference inputs. But that's the problem with analog stuff in general--nothing is ever exactly equal to anything else. Whereas when it's digital, 1+1=10.
 

JWHassler

Joined Sep 25, 2013
308
If you can dedicate an ADC to the task:
Initialize:
Read ADC and note value as 'OldADC'
Re-start ADC
Start a timer-interrupt at 1 mSec rate
On every interrupt:
Get ADC-result as 'NewADC'
Re-start ADC
if abs( NewADC - OldADC)> a-few-counts, then do something.

... this should take 10-20 uSec every millisecond.
Except for the dedicated-ADC thing, it's very low impact
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,415
I once worked on a circuit (production build to print job) where a change of an unknown analog input was detected by a single comparator: one input had a simple RC network to capture the long term value, the other input thru a resistor divider to see a small offset. When the input changed by a small amount the comparator output would toggle. Thus it was an analog in, digital out change sensor. Two such circuits with the inputs inverted could detect a change in either the + or - direction.
 

dannyf

Joined Sep 13, 2015
2,197
"
have the following doubt: Given the voltage is analog, will the value read change -even a little- on every cycle of a loop without moving the POT? "

even if you could hold the voltage constant, its adv results will fluctuate. A great way to generate random numbers
 

Thread Starter

Kenny

Joined Oct 11, 2004
55
Many thanks for your dissertations...

...Your answers seem to confirm what I have been thinking of: the usual way to read the change of the POT is by polling and there is no way with interrupt that detect the change in the way digital pin does.
Am I understand you well?
 

dannyf

Joined Sep 13, 2015
2,197
Not as great, or as random, as you might think...
That's because you are not generating the random number correctly.

I have some 18 bit or so A2D converters on a perf board no ground plane prototype reading voltages and currents set by pots that never change a single bit.
Either you are God or the adc designer is God. No other possibilities.

PS: what exactly are those godly "A2D converters"?

the usual way to read the change of the POT is by polling and there is no way with interrupt that detect the change in the way digital pin does.
Not really sure how you got that impression from this thread -> people have been providing you with examples of how you can use interrupts to trigger adc + process data. Are you sure you are reading this thread?
 
Last edited:

Thread Starter

Kenny

Joined Oct 11, 2004
55
dannyf:
Of course I read all the arguing! Even yours

And it seems to me the answers reassure my initial assumptions. In summary:
Some say: Compare the input with a(pair) of generated (D-A) voltages, however the comparator will trigger with any minimal change. And, given the nature of analog, this change can occur simply without moving the POT.
Other say: Poll using a timer interrupt.

So, what I want to do is act at the moment I detect a significant change in the POT. And, based into the answers, I understand the best achievable way is by polling.
 

ErnieM

Joined Apr 24, 2011
8,415
And it seems to me the answers reassure my initial assumptions. In summary:
Some say: Compare the input with a(pair) of generated (D-A) voltages, however the comparator will trigger with any minimal change. And, given the nature of analog, this change can occur simply without moving the POT.
Other say: Poll using a timer interrupt.

So, what I want to do is act at the moment I detect a significant change in the POT. And, based into the answers, I understand the best achievable way is by polling.
Meh. I described an analog method using an RC low pass for the moving reference that does not require a D2A converter.

Either you are God or the adc designer is God. No other possibilities.

PS: what exactly are those godly "A2D converters"?
Probably a combination of both.

Microchip MCP3422/3/4 18-Bit, Multi-Channel ΔΣ Analog-to-Digital Converter with
I2C Interface and On-Board Reference.
 

dannyf

Joined Sep 13, 2015
2,197
Probably a combination of both."

Probably none of the above.

Microchip is more like a jv team in this space. So their being able to afford god to design this godly chip is nill.

Typically, a chip from a reputable vendor will have enob or noise free code or effective resolution bits. They usually are 2-3 digits lower than the chips resolution, thanks to the inherent adc noise.

You can take a look at your chip and I'm sure you can quickly calculate those numbers to realize that microchip ain't god.

Nor are you. Sadly to break that to you, :)
 
Top