PDA

View Full Version : Use a PIC ADC like a fast interrupt comparator?



pxidr84
- 16th August 2011, 18:01
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.

HenrikOlsson
- 16th August 2011, 18:36
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.

HankMcSpank
- 16th August 2011, 23:42
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!

Charles Linquis
- 17th August 2011, 02:19
I think the first question is - what do you mean by *fast*? 1nSec? 100nSec? 1uSec? 10uSec? 100uSec?...

pxidr84
- 17th August 2011, 13:10
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.

Charles Linquis
- 17th August 2011, 15:03
Again... HOW MUCH LATENCY IS ACCEPTABLE?? Is 1nSec too much? is 1millisecond too much? Give us a number!

pxidr84
- 18th August 2011, 10:40
Again... HOW MUCH LATENCY IS ACCEPTABLE?? Is 1nSec too much? is 1millisecond too much? Give us a number!

Few µs (1-10µs.)

Charles Linquis
- 19th August 2011, 05:33
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.