Analog Comparator

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Will this work in principle - I could prototype it, but it's not trivial and hopefully 'Freaks will come good (yet) again...

ATMega 168, if it matters....

1) Set the analaog comparator reference to the bandgap

2) Replace AIN1 with a normal ADC port (say ADC0) by using the the ADC multiplexer (so that I can use the AIN0 pin as a normal digital I/O)

3) Use a potential divider on the raw side of my supply that gives 1.1v at ADC0

...and I should get a analog comparator interrupt when the raw supply goes sufficiently low.

That's hopefully the straightforward part.

But now I want to use ADC1 in my app to read some other analog signal.

So I change the ADC multiplexer to use ADC1 at the appropriate time...
...does the AVR remember that the analog comparator is always on ADC0 so that you get a comparator interrupt on low supply even though you might be in code that is dealing with ADC1 when the supply fails?

TIA, Martin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you change ADC multiplexer to ADC1 you will also select ADC1 as input of your comperator.

/Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess that's bad news for my design then :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For "early warning" on power loss, measuring the raw side as you mentioned is usually preferred so I agree with that part.

Turn your raw supply voltage level into a digital signal. Resistor divider to get it down to logic levels, and then maybe a schmitt trigger buffer or inverter to get a clean logic signal on the output? (Others would need to comment on the "best" way.) Then run this into an AVR pin INTx or just about any on the '168 with a pin-change interrupt.

If you are going to add this circuitry, then also consider doing it "right" with a supply monitor chip such as Panasonic MN1382 series and a logic-level out.

One can also just do repetitive A/D conversions on the divided raw supply, average, and "trip" when the average dips below a certain level. In practice this works fine and few external components are needed. Even with a conversion only every 1ms a 12V or 24V or 9V or whatever raw supply will usually take several/many 10's of ms before the Vcc will start dropping--plenty of early warning.

The Vcc-side can be monitored with a similar method to your analog comparator. Use AVcc as the reference, and do a conversion on the bandgap.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Lee - back to the drawing board....

The problem with the potential divider is that a raw supply going down through 8v is considered as 'failed', but a steady 10v is OK - a bit tricky to (simply) turn this into logic '0' or '1' without increasing component count too much

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A bit of experimentation should show where the buffer/inverter "trips", and I expect it would be consistent enough not to worry about it once "calibrated". Select the resistors accordingly.

If you are going to add components, then the Panasonic series that I mentioned is US$1 in qty 1 and half that in moderate quantities. We divide down to Vcc range first then pick the appropriate trip value. It will only cost a few cents more to do it right.

And the A/D converion approach costs only the resistor divider to bring the signal into Vref range.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One solution might be to pass the signal from ADCx to AINx and configure the comperator to use AINx permanently.
Other possible solution would be to add one cap that ensures, that the voltage drop from 10V to 8V will be slower than the ADC-conversion (which is quite fast) and disable the comperator during ADC-convertion, after convertion change the MUX and reenable the comperator.

/Martin.