AVR comparator

Nov 05, 2007 3 Replies

Hi



So if I go with the AVR's internal comparator for reading in a sine wave is there a common way to handle hysteresis for this module?



As for hooking up the circuit on an Atmega88 does the following sound right?



Pins: AIN0 - 0 to 5 volt (dc offset sine wave) AIN1 - GND



Registers: ASCR Bit4 ACI: - this is the flag set when the comparator event occurs. Bit 3 ACIE: interrupt enable for the module Bits 1, 0 ? ACIS1, ACIS0: set to 11 for rising edge triggering



DIDR1 Bit 1, 0 ? AIN1D, AIN0D: AIN1, AIN0 Digital Input Disable so the digital inputs dont interfere with the comparator



Now I would just handle the timer interrupt and take the inverse of the elapsed time to recover frequency.



Scott


Unfortunately, no. The output of the comparator is not connected to the outside of the chip, therefore you can't make a hysteresis using a resistor. What you have to do is suppressing the transition ripples in the software. I.e. ignore a state of the input if it lasts for less then X microseconds.

Vladimir Vassilevsky DSP and Mixed Signal Consultant

formatting link

What if he uses an output pin that replicates the state of the comparator? Can't he tie a resistor network to that pin? There would be a delay but I don't think it matters for his speed, I believe it was a 50Hz sine wave.

It certainly can be done in that way, however it is not going to help much. The internal comparator is connected to the input capture hardware directly, so the input capture register will be updated several times by triggering on the noise during the transition. There is some noise reduction circuitry on the chip, however it is not going to help if the incoming signal is dirty.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required