analog comparator(multiplexed mode)

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

i have to sense certain sensor values using the mega 16 comparator in round robin fashion and then based on all the values i take some action.

will the comparator value be immediately available after input ?

or should i use some delay between the successive
comparison?

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

The comparator has a propagation delay and the multiplexer also. Check the datasheet.

Embedded Dreams
One day, knowledge will replace money.

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

I'm a bit confused. Are you going to place an analog mux ahead of the field input to the analog comparator?

I cannot say I've ever done that. In my work, that job would be done with the A/D converter taking readings from different sources (e.g., temperature via thermistors; supply and output voltages; voltage-output current sensors) by reading one channel after the other and then using the set of readings to close the control loop.

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

Some chips, allow you to divert the ADC multiplexer output into an analog comparator input instead of the ADC input. I think it's actually a very neat feature and would love to see more of those. It allows you to be creative...
I have used it in a DC-DC converter where the AVR controls more than 1 converter loop, to check if the output voltage is above or below the desired value.

Embedded Dreams
One day, knowledge will replace money.

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

I have to agree with Lee on this one.

Unless the reference is the same for all the inputs, and the voltage applied comes from the same type of sources or is reduced through divider resistors, why not use a micro with multiple ADC inputs instead? Of course yo can use a multiplexer like the '4051, or cd4067 Again though, Why the comparator?

jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Quote:

Some chips, allow you to divert the ADC multiplexer output into an analog comparator input instead of the ADC input.

Yes, I knew about that--but didn't think that ACME was part of mega16 but rather only newer families. I was wrong!

Hmmm, I wouldn't know what the delay would be; it was never a concern before even when using ACME. Perhaps you can tell by experimentation; it certainly doesn't jump out at me from the datasheet.

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

theusch wrote:
Perhaps you can tell by experimentation; it certainly doesn't jump out at me from the datasheet.

It's on the DC electrical characteristics part of the datasheet.

Another reason to use the analog comparator on some applications where you could also use the ADC is speed.

Embedded Dreams
One day, knowledge will replace money.

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

Quote:

Another reason to use the analog comparator on some applications where you could also use the ADC is speed.

Good point but.............

The cost factor. The mega 16 has a multi channel ADC, the conversion time depending on the clock has to be faster than selecting an external chips channel, wait a few blips for it to settle, check the comparator and then react accordingly. Plus you now would need I/O pins to control the mux

the adc is a better choice.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

jgmdesign wrote:
Quote:

Another reason to use the analog comparator on some applications where you could also use the ADC is speed.

Good point but.............

The cost factor. The mega 16 has a multi channel ADC, the conversion time depending on the clock has to be faster than selecting an external chips channel


No, it probably isn't. But it doesn't matter, because the mega16 already has a multichannel analog comparator. See the posts above.

jgmdesign wrote:
, wait a few blips for it to settle, check the comparator and then react accordingly. Plus you now would need I/O pins to control the mux

the adc is a better choice.


Depends on your requirements.

Propagation delay on the analog comparator is 500ns @ 4V, while the ADC takes at least 65us to do a conversion (well, if you can live with less bits you can work at 1MHz ADC clock and so you have around 13us, but nevertheless it's still more than 20 times slower than the analog comparator).

Embedded Dreams
One day, knowledge will replace money.

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

Nuno,
THe mega 16 DOES NOT have a multi channel comparator, it has a multi channel A/D converter as I noted. Yes, the converter is a tad slower, but as I also noted, is the need for speed at the requirement to achieve this is additional components that will use time to work really a good design?

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

hummm... I have the atmega16 datasheet opened in front of me and I can see on the lower left corner of figure 97 that the output of the ADC multiplexer can be chosen to be the input to the negative analog comparator... that makes it a multichannel analog comparator for me, not a full one (only one of the 2 inputs), but definitely multi-channel. Unless you have a different definition of "multi-channel analog comparator" from what I do.

Embedded Dreams
One day, knowledge will replace money.

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

i was thinking ur way nuno.

the analog comparator of the atmega can make use of the adc multiplexer when adc is turned off.

set acme
reset aden in adcrsa
vref at ain0
then use the mux2..0 bits to select the signal to be sampled from adc mux.

the datasheet says 500ns delay with 4v vcc

is some delay reqd btw successive comparison?

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

According to the datasheet the analog comparator takes some time to react (for the output to correctly reflect the inputs), which is called the propagation delay time. This is 500ns at Vcc = 4V. The analog multiplexer takes 1 or 2 clocks to react, I think (it's also on the datasheet).
So, after you change the input selection you have to wait at least the 1-2 clocks because of the mux and another 500ns if your Vcc is 4V or more.
In practice, I would advise you to wait more time, let's say, 200us, until your application is working. Then try to reduce that delay to see where it starts to behave erratically and compare that to what the datasheet says about the times.

Embedded Dreams
One day, knowledge will replace money.

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

Nuno,
Yep, you got me on that one :oops:
I was only looking at the product overview. That'll teach me.

Ok, it has a two channel comparator. If two channels is all vicky3413 needs then the thread is solved. If more channels are needed then my view that the ADC may be a better choice. Is the speed really that big an issue? At what speed will the M16 be running? What is the application? The OP states sensors in a round robin fashion, are the sensors gated, or are they continuosly outputting and their output is to be routed? What kind of output? TTL, or variable voltage? If TTL, then the comparator makes sense(no pun intended), but if it is voltage the ADC would be a better choice because you then have real time data that could be sent to a pc through the usart for example.

Jim

P.S. Good catch Nuno!!

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Jim, you still didn't look correctly at the datasheet :)
The number of channels going to the analog comparator is the same as the ones going to the ADC, not only 2.
As for the rest, as I also said before, it depends on the application. By now the OP should know the available solutions, so it's up to him to choose the one that better suits his requirements.
Cheers!

Embedded Dreams
One day, knowledge will replace money.

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

i have 10 sensor inputs.
i am multiplexing 8 of them through the adc mux,and am also using a lm324 for other 2 sensors :D

i am more inclined towards using comparator than the adc.
any supports to my idea?

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

vicky3413 wrote:
i am more inclined towards using comparator than the adc.
any supports to my idea?

Depends on the application...

Embedded Dreams
One day, knowledge will replace money.

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

Quote:

any supports to my idea?

Not really, from me. With all this discussion, I can see where they could be "polled" in round-robin fashion faster than doing ADC conversions (a "fast" conversion of 13 ADC clocks @1MHz ADC clock rate, plus storage & setup time would yield about 50ksps), but you only get a yes/no answer and with the ADC you get hundreds of different levels to work with. You've mentioned "sensors" several times; if these are indeed bang-bang yes/no against a fixed threshold then turn them into digital inputs.

Before I can answer "any support", I'll need to know what you are doing with the stuff. In my industrial apps it is rare to close the loop faster than a few milliseconds. The "rare" fast trips can eisily be taken care of with interrupt pins. Most of the time when temperature, pressure, flow, current, voltage, and the like is involved I'll close the loop every 500ms or so, with a bunch of ADC readings averaged. This also allows me plenty of time to do "stuff" like display and communications.

So, I'd need to know what "stuff" you need to do, and why fast comparison against a fixed level is so important.

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

1)i am actually using the sensors to determine the position of my robot on the chess board.this board contains some defects.(white instead of black or the ohter way )
i need to find out the total number of defects in it.

2)can i use a ISR to switch the pin being sampled after a comparison? (using ANA_COMP_vect)

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

What kind of sensor do you have?

Embedded Dreams
One day, knowledge will replace money.

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

photo transistors and ir led pair

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

Then why not just turn them into a bank of 8 digital signals?

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

i have tried all the sensors independently using the analog comp,they all gave wonderful result!

i gave a voltage of 2.5 v at ain0(+ve of comparator).

how do i sense all together? i mean can i use interrupt service to switch the pin after one comparison?

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

i didn't get you lee.

Quote:
Then why not just turn them into a bank of 8 digital signals?

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

Route each of the sensors into a pin on a port of an AVR; say, PORTD. If you insist on interrupt immediately upon a change, then use a Mega164 with pin-change interrupts. Ensure that the AVR pins don't see voltages below Gnd or above Vcc.

But you probably don't need sub-microsecond response, anyway, and in fact treating them like pushbuttons and reading every few milliseconds and entering into a standard debounce routine will give some noise protection and produce the debounced current state along with the rising edges and falling edges.

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

i ll try that and get back to you lee,

thank you

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

Yes, I agree with Lee. What you have (or want) is a "digital sensor" - you just want to know if it's ON or OFF, so it's easier to just connect them to digital inputs. You just need to make sure the output of the sensor is enough to trigger the AVR's input; if it isn't, and since it's phototransistor, you can adjust it I think by just choosing an appropriate resistor.

Embedded Dreams
One day, knowledge will replace money.