Analog Comparator Constantly Interrupting

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

I am trying to use the analog comparator to turn the output of an mp3 player into logic levels to feed into the input capture. From there, I'll measure the time it takes for two peaks to pass in order to figure out the frequency. That's the big picture.

When every I try something new, I try some prototype code. Unfortunately, it isn't doing what I expect. What I am expecting is the LEDs connected to PORTA to count the number of times I raise AIN1 to VCC. Both AIN0 and AON1 are tied to ground with a 1M resistor.

#include 
#include 

volatile unsigned int i;

int main (void)
{
    DDRB = 0x00;
    PORTB = 0x00;
    DDRA = 0xff;
    PORTA = 0xff;

    ACSR |= (1 << ACI); // Analog Comparator Interrupt Flag
    ACSR |= (1 << ACIE); // Analog Comparator Interrupt Enable
    //ACSR |= (1 << ACIC); // Analog Comparator Input Capture Enable

    sei();

    for (;;)
    {   
        // Watch the daisies
    }   
}

ISR (ANA_COMP_vect)
{
    i++;

    PORTA = i;
}

What I am seeing is the LEDs flickering so fast that my eyes can barely pick up the flicker but when I take either AIN0 or AIN1 to VCC the flickering stops. So far, I have an 8-bit die roller as I have yet been able to time my button presses to generate the same number twice.

If I feed a 500-1500Hz sweep from the mp3 player, I get a much slower count that is definatly affected by the frequency. I have the headphone common going to ground with the other lead going to AIN1. The 1M resistors are still there.

Any ideas what I am screwing up? If it is how I am wiring this thing up, I am more than willing to move this over to General Electronics.

You can have my mac when you pry my cold dead fingers off of it.

Kevin McEnhill -- mcenhillk@gmail.com

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

Quote:
Both AIN0 and AON1 are tied to ground with a 1M resistor.
Then they are both at he same potential and therefor you have a compare. Try and tie the negative input to 1/5vcc see if things improve. ie you should only get an interrupt when the positive input becomes higher that the negative input.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

@John Samperi: Would that work for my wife, do you think?

Four legs good, two legs bad, three legs stable.

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

Quote:
Would that work for my wife
NOPE!! Husbands NEVER reach a potential value above their wifes', therefore husbands never get an interrupt from nagging. :lol:

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly