Interrupt to Detect analog voltage change

Discussion in 'Embedded Systems and Microcontrollers' started by Kenny, Sep 30, 2015.

  1. Kenny

    Thread Starter AAC Fanatic!

    Oct 11, 2004
    55
    0
    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?
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    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.
     
  3. Kenny

    Thread Starter AAC Fanatic!

    Oct 11, 2004
    55
    0
    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?
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    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.
     
  5. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,763
    But, voltage changes all the time...if even just a little bit.
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    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.
     
  7. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    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.
     
  8. JWHassler

    Member

    Sep 25, 2013
    201
    33
    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: Oct 1, 2015
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    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.
     
  10. dannyf

    Well-Known Member

    Sep 13, 2015
    1,835
    367
    "How can I do it?"

    restart the adv in the isr.
     
  11. dannyf

    Well-Known Member

    Sep 13, 2015
    1,835
    367
    "
    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
     
  12. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,763
    Not as great, or as random, as you might think...
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    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.

    How random is zero?
     
  14. Kenny

    Thread Starter AAC Fanatic!

    Oct 11, 2004
    55
    0
    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?
     
  15. dannyf

    Well-Known Member

    Sep 13, 2015
    1,835
    367
    That's because you are not generating the random number correctly.

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

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

    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: Oct 1, 2015
  16. Kenny

    Thread Starter AAC Fanatic!

    Oct 11, 2004
    55
    0
    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.
     
  17. dannyf

    Well-Known Member

    Sep 13, 2015
    1,835
    367
    Wow! That's just crazy, :)
     
  18. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Meh. I described an analog method using an RC low pass for the moving reference that does not require a D2A converter.

    Probably a combination of both.

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

    Well-Known Member

    Sep 13, 2015
    1,835
    367
    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, :)
     
  20. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,763
    Funny how I'm currently getting 16 solid bits out of the 12 bit converter of an 18f65k90, in spite of the errata.
     
Loading...