Use a PIC ADC like a fast interrupt comparator?


Closed Thread
Results 1 to 8 of 8
  1. #1

    Question Use a PIC ADC like a fast interrupt comparator?

    Hi everyone,

    It's possible to use a PIC ADC like a fast comparator?

    For example, on AN0, I got 4 volts, which corresponds approximately to 819. My trigger value is set to 800. 819>800, so the output equals 1, and this executes an "emergency" ISR. But this has to be as fast as an interrupt (few µs).

    How I can do that, for example with DT Interrupts system?
    Actually I use an "IF AN0>800 THEN goto Emergency_ISR:" in a very loaded loop.

    I'm using a PIC18F4431 running at 40MHz.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Use a PIC ADC like a fast interrupt comparator?

    Hi,
    As far as I know there are no such features in any PIC16 or 18.

    If the purpose is to stop the PWM-module (overcurrent for example) you can use the FAULT-inputs but unfortunately the 4431 doesn't have an internal comparator so you'll need an external one. Use a spare channel on the PWM module or a "standard" CCP-module to output a PWM, lowpass filter it and run it to the external comparator.

    The Fault input will stop the PWM thru hardware which gives you the fastest possible latency. You could then check the pin in your main loop to run any other code that needs to be run.

    /Henrik.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Use a PIC ADC like a fast interrupt comparator?

    Quote Originally Posted by pxidr84 View Post
    Hi everyone,

    It's possible to use a PIC ADC like a fast comparator?
    Interesting....to have a PIC ADC act as a fast sw comparator, would require the PIC to do nothing else but continually check ADC samples (samples sourced from the special event trigger).....else trapping the condition would be time dependent on how often you checked in your main program.

    I guess you could use a very basic PIC programmed to do this...and then raise an interrupt to the main pic via a logic level change/IOC pin (but then there's not much win then over using a std external hw comparator)

    I actually wish they did multi processor low end PICs! (something like an SOIC16 package but with two PIC MCUs inside!), where simple background tasks could run on one PIC, with it interrupting the other partner PIC when something of interest happened!
    Last edited by HankMcSpank; - 16th August 2011 at 23:47.

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Use a PIC ADC like a fast interrupt comparator?

    I think the first question is - what do you mean by *fast*? 1nSec? 100nSec? 1uSec? 10uSec? 100uSec?...
    Charles Linquist

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Use a PIC ADC like a fast interrupt comparator?

    Quote Originally Posted by Charles Linquis View Post
    I think the first question is - what do you mean by *fast*? 1nSec? 100nSec? 1uSec? 10uSec? 100uSec?...
    I mean the fastest latency.

    But the best way is to use an external comparator, like Henrik said, connected to an INT0/1/2 digital input.

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Use a PIC ADC like a fast interrupt comparator?

    Again... HOW MUCH LATENCY IS ACCEPTABLE?? Is 1nSec too much? is 1millisecond too much? Give us a number!
    Charles Linquist

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Use a PIC ADC like a fast interrupt comparator?

    Quote Originally Posted by Charles Linquis View Post
    Again... HOW MUCH LATENCY IS ACCEPTABLE?? Is 1nSec too much? is 1millisecond too much? Give us a number!
    Few µs (1-10µs.)

  8. #8
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Use a PIC ADC like a fast interrupt comparator?

    I haven't tried it (yet), but I believe that if you run an 18F chip at 40Mhz, and write an ISR in ASM, you can probably get the latency down to about 25uSec.
    Charles Linquist

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts