Go Down

Topic: Execution Time of Control Functions (Read 898 times) previous topic - next topic

Nick Gammon

Indeed. I did a short post about using the comparator:

http://www.gammon.com.au/forum/?id=11916
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Coding Badly


If I remember correctly, with the analog comparator, you do not need to actually generate an interrupt.  You can check for and reset the flag.  The advantages: all the issues with interrupts are eliminated; uses a bit less SRAM; possibly generates less code.

I think this modified version of Nick's example shows how...

Code: [Select]
ISR (ANALOG_COMP_vect)
  {
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Started.");
  ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  _BV (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | _BV (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
   }  // end of setup

void loop ()
  {
  if ( (ACSR & _BV (ACI)) != 0 )
    {
    Serial.println ("Triggered!");
    ACSR |=  _BV (ACI);     // (Clear) Analog Comparator Interrupt Flag
    }
 
  }  // end of loop

rickso234

Of course I'm currently using D6 as a PWM output so can't use the analog comparator?

May have to add my own comparator to the circuit and connect its output to a pin change interrupt.

Coding Badly

Of course I'm currently using D6 as a PWM output so can't use the analog comparator?


Correct.

Quote
May have to add my own comparator to the circuit and connect its output to a pin change interrupt.


Or, you could add an LED driver that supports PWM.

Nick Gammon

I did a comparator here:

http://www.gammon.com.au/forum/?id=11011

Not that they are complex. :)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy