Interrupt on ADC change for Pic?

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Oct 26, 2012.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011
    I have a Pic 18F14K22. I know there is an interrupt for change on a Port and I have been using it.

    But is there a way to interrupt of an ADC input change? I can see an interrupt for when the analog to digital conversion is down but I see no other interrupts for the ADC.

    Is there some other way I can interrupt on ADC change?
     
  2. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    This would not make too much sense since the LSB often isn't stable.
    To my knowledge no such interrupt exists.
    You'd have to use two PICs to implement that, if you want to reduce the MCU workload. So, PIC one is sampling as fast as possible, if the value is changing, it changes an I/O bit. You don't even need any kind of SPI or USART.
     
  3. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011
    That is what I kind of figured. But could a range somehow be used? If the voltage drops below a set amount or goes above a set amount?

    Perhaps an external circuit hooked to a port? Port interrupts then the ADC is read.
     
  4. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011
    Or could the comparator be somehow used?
     
  5. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    There is no digital adjustment of such a voltage. Some PICs have low-resolution DAC, which you can of course connect to the comperator. As I say, simply use a secondary PIC, maybe 8 pin only.

    Why do you want an interrupt for that? So you don't need to sample all the time? Or why don't you want to sample continously? Not enough MCU cycles available?

    I think are used for things exactly like that, but actually this is programmed in software. And I have skipped through many different PIC datasheets.
     
  6. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011
    It's for a project that monitors the voltage from a solar panel and battery. I wanted to be able to "do something" whenever the voltages change by a half volt.

    I wanted to make use of sleep and have the pic wake up on voltage change.

    What I do right now is to have a timer that checks once a second. It is this often to update an LCD display. But I was thinking that if the display is not on (it is turned off automatically to save power) then I could check less often.

    If I use sleep then I suppose I could use the timer interrupt to wake up the pic.

    But I wonder if I am over thinking the whole thing since relative to the light the battery is powering, the pic draws next to noting.
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Maybe, yes. So lack of MCU time is not the problem.
    Even to check every 30 seconds is very generous for solar application.

    So you mean if there are PICs which include hardware which can work while in sleep mode, and can which can be programmed to detect an ADC result delta? I would say, definitively not.

    Microchip has some application notes for ultra low power applications. They may contain interesting additional information.
     
  8. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    The adc conversion is still active during sleep (if the ADC internal RC source clock is used) so you could have it start when the sleep cycle begins then read the value when the timer wakes-up the processor and compare the value to see wither to go back to sleep or perform a function. What is your controllers power budget for a day? If it's much less than 1% of the solar daily total power then the solar panel/battery wire resistance loss might swamp any PIC power savings from complex sleep modes.
     
    Last edited: Oct 26, 2012
  9. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011
    It is controlling a light that consumes less then 600ma when on. Right now the light uses 100 individual LEDs. I plan to replace that with 2-3 of those 12V LED spotlights so that might go up to 800ma or so but I should get a much brighter light out of it too and I could always incorporate PWM to help conserve power.
     
  10. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    If the PIC chip mainly sleeps (XLP uses > 1ua with timers operating) and uses a few milliamps internal when running the lighting power budget for solar/battery power is far more important.
     
  11. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011

    Not exactly sure what you are saying. Are you saying it is probably not worth the hassle of incorporating sleep in my project?
     
  12. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You don't write why you use 18F chip, and if you need to do additional computations. For the tasks you described, maybe try a 500 KHz resonator. Current will be much lower than using a crystal. This chip should have internal oscillator anyway.

    If you need crystal precision, use a 32KHz secondary crystal for the timebase.
     
  13. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,169
    I'm saying the energy efficiency gained from a simple timer based sleep routine is really all you need because the energy losses from battery charge efficiency and simple IR losses from driving the lamps will be much higher in the overall project energy budget (to completely recharge the battery every day or so) requirements.
     
  14. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Provided that you want a continuous monitoring of the voltage, and not a wake and test scheme, I'd go with the fixed voltage reference that is on the pic, running to the comparator module which would be setup to interrupt on change. This way, you are only using one chip. The only catch is that you'd need to ensure proper conditioning of your monitored voltage (within range of pic), and you're good!
     
  15. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011
    I'm using the internal osc, at it's lowest or near lowest for now but if memory serves I designed the PCB to be able to add xtal and caps at a later time.

    I just chose the chip because it seemed to fit my needs. Maybe a little overkill on memory but it was my first project.

    Also it was 5V capable. The off the shelf puck buck that drives the lights has a 5V output to drive pics.

    That will probably go away and I'll use those flood light leds that have their own current protection. I will then either design a 5v buck regulator or a 3v but then I would have to replace the display.

    So a future question would be is there any benefits of stepping down to 3 v.
     
  16. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,886
    1,011
    That was my thought was to use the comparator. I have not used them before so I am not sure exactly how they work. . So I can set it up to interrupt when the input voltage changes using the comparator? Can a range be used? Say if it strays .5V from it's current voltage?
     
  17. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Not unless you can set the voltage reference to reflect the new desired voltage.as far as a 0.5V deviation, no.the comparator tells you only if the voltage is above our below some other voltage, think of an open loop op amp.

    I have to agree with these other posts, your power savings here are factors of hundreds less than the LEDs, making this simply a test to see how to operate your uC. Your power is wasted on running the LEDs, not from running the pic at 32MHz, if you were to...
     
Loading...