Pages: 1 [2]   Go Down
Author Topic: Execution Time of Control Functions  (Read 653 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
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
Logged

Manchester, NH
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did a comparator here:

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

Not that they are complex. smiley
Logged

Pages: 1 [2]   Go Up
Jump to: