user69011: After being introduced to this code on github, and exploring electronoobs tutorial I was compelled to try and recreate it with the Arduino Nano, and using the A0-A3 analog comparator inputs. Currently, I am just trying to get the rising edge of the receiver transducer to be recognized in the interrupt. Thus, I think my problem resides in ISR(ANALOG_COMP_vect)
Using an oscilloscope confirms that the ultrasonic transducer is firing every 100 ms, and I can detect the ping with the receiver as a small voltage above GND, which should trigger the ISR interrupt with DIO6 connected to GND... but that is not happening...
Here is my code:
#include  <avr/interrupt.h>

#include  <stdint.h>
#include  <stdlib.h>
#include  <stdio.h>
#include  <stdbool.h>

#include <Arduino.h>
#include  "fastio.h"


#define F_CPU 16000000UL

// pins for TX driver
#define PING0   PB1
#define PING1   PB2

#define LED     DIO13

#ifndef MASK
  #define MASK(m) (1UL << m)
#endif

#define DEBUG 0
#define INTERVAL 100
#define diff(a,b) (((a) >= (b))?((a)-(b)):((b)-(a)))

inline bool ge(uint32_t a, uint32_t b) {
  return ((a - b) & 0x80000000UL) == 0;
}

inline bool lt(uint32_t a, uint32_t b) {
  return ((a - b) & 0x80000000UL) != 0;
}

volatile uint32_t milliseconds = 0;

uint16_t starttime = 0;
volatile uint16_t envelopetime = 0;
volatile uint16_t phasetime = 0;

#define PULSECOUNT_X2 16
volatile uint8_t edges = 0;

void pins_init(void) {
  WRITE(PING0, 0);
  SET_OUTPUT(PING0);

  WRITE(PING1, 0);
  SET_OUTPUT(PING1);

  WRITE(LED, 0);
  SET_OUTPUT(LED);

}

void timer_init(void) {
  // init timers
  GTCCR = MASK(TSM) | MASK(PSRSYNC); // pause clocks

  PRR &= ~MASK(PRTIM1) & ~MASK(PRTIM0) & ~MASK(PRADC); // enable timers 0 and 1 and ADC

  // use timer1 for output waveform generation and analog comparator timing
  TCCR1A = 0;                       // normal mode, no match behaviour
  TCCR1B = MASK(CS10);              // maximum speed (no prescale)

  // use timer0 for our millisecond clock
  TCCR0A = MASK(WGM01);             // CTC mode
  TCCR0B = MASK(CS00) | MASK(CS01); // prescaler=64, ie clock is 250kHz
  OCR0A  = 250;                     // interrupt at 1kHz, ie every 1ms
  TIMSK0 = MASK(OCIE0A);            // interrupt on compare

  // set up analog comparator
  ADCSRA = (0 << ADEN);
  ADCSRB = (1 << ACME);
  ADMUX = 0;
  ACSR |= 0x03;
  
  GTCCR = 0; // re-enable clocks
}

void setup(){
  pins_init();
  Serial.begin(115200);
}

void loop() {
  timer_init();
  sei();
  Serial.println("Start");

  uint32_t pingtime = INTERVAL;

  for (;;) {
    if (ge(milliseconds, pingtime) && (edges == 0)) {
      // note when we should ping next
      pingtime += INTERVAL;

      // start in a millisecond from now to avoid race conditions
      starttime = TCNT1 + (F_CPU / 1000);
      OCR1A = OCR1B = starttime;

      // reset edge counter
      edges = PULSECOUNT_X2;

      // set A and clear B on match
      TCCR1A = MASK(COM1A0) | MASK(COM1A1) | MASK(COM1B1);

      // disable interrupt on comparator
      TIMSK1 &= ~MASK(ICIE1);

      // clear flag in case it triggered during startup
      TIFR1 = MASK(OCF1A);

      // enable interrupt
      TIMSK1 |= MASK(OCIE1A);
    }
    if (phasetime != 0) {
      uint16_t eoff = envelopetime - starttime; // time when Rx signal became loud enough to consider, ie start of envelope
      uint16_t poff = phasetime - starttime;    // time of first zero crossing after envelope, use for calculating phase offset

      //printf_P(PSTR("envelope +%u (%uus) phase +%u (%uus)\n"), eoff, eoff >> 4, poff, poff >> 4);

     Serial.println(eoff);
     //Serial.println(poff);

      // zero so we only print once, process data before this
      phasetime = 0;
    }
  }
}

ISR(TIMER1_COMPA_vect) {
  if (edges == PULSECOUNT_X2) {
    TCCR1B |= MASK(ICES1);   // listen for rising edge
    TIFR1 = MASK(ICF1);      // clear flags in case it triggered during startup
    TIMSK1 |= MASK(ICIE1);   // interrupt on comparator

    TCCR1A = MASK(COM1A0) | MASK(COM1B0); // toggle on match
    //Serial.println("PULSE");
    WRITE(LED, 1);
  }
  else if (edges == 1) {
    TCCR1A = MASK(COM1A1) | MASK(COM1B1); // clear both on match
  }
  else if (edges == 0) {
    //putc('>');

    TIMSK1 &= ~MASK(OCIE1A);   // disable interrupt

    return;
  }
  edges--;
  OCR1A = OCR1B += F_CPU / 80000; // set next timeout
}

ISR (ANALOG_COMP_vect)
  {
  phasetime = ICR1; 
  if((ACSR & B00100000)){
    envelopetime = ICR1;      // store timestamp
    WRITE(LED, 0);
    TIMSK1 &= ~MASK(ICIE1);   // disable interrupt on comparator
  }
}
  
ISR(TIMER0_COMPA_vect) {
  milliseconds++;
}


user84816: You have not enabled the comparator interrupt.
Just need to change the line where you set ACSR.
//Comparator interrupt on rising output edge.
ACSR |= (1 << ACIS0) | (1 << ACIS1);   

//Enable comparator interrupt
ACSR |= (1 << ACIE)

Can also be achieved with.
ACSR = 0x0B

If you want to change what triggers an interrupt.
Bits 0 and 1 control how an interrupt is fired (Toggle, falling or rising).
//Toggle (Default, only required if another interrupt mode is already selected)
ACSR &= ~(0b11)

//Falling
ACSR &= ~(1 << ACIS0); //Only required if ACIS0 is set
ACSR |= (1 << ACIS1);

//Rising
ACSR |= (1 << ACIS0) | (1 << ACIS1);
//Or
ACSR | = 0x03;

You will also need to enable global interrupts. (Which you have done)
Which can be done by calling...
interrupts(); //Arduino only
sei();        //AVR and Arduino

I see you are calling "sei" in the loop, it only needs to be called once (unless you have disabled them with "cli()," and I believe its not even required at all with Arduino as I think interrupts are already enabled.
The datasheet is your friend. Tutorials are a great way to learn, but if you really want to increase your skill set you should try to break free from tutorials as much as possible by reading the datasheet, and experimenting on your own.
The comparator starts on page 202, and would be a great place to start as its an easy peripheral to get going.

69011: <p>After being introduced to this code on <a href="https://github.com/triffid/ultrasonic-poc" rel="nofollow noreferrer">github</a>, and exploring <a href="https://electronoobs.io/tutorial/190#1" rel="nofollow noreferrer">electronoobs tutorial</a> I was compelled to try and recreate it with the Arduino Nano, and using the A0-A3 analog comparator inputs. Currently, I am just trying to get the rising edge of the receiver transducer to be recognized in the interrupt. Thus, I think my problem resides in <code>ISR(ANALOG_COMP_vect)</code></p>
<p>Using an oscilloscope confirms that the ultrasonic transducer is firing every 100 ms, and I can detect the ping with the receiver as a small voltage above GND, which should trigger the ISR interrupt with DIO6 connected to GND... but that is not happening...</p>
<p>Here is my code:</p>
<pre><code>#include  &lt;avr/interrupt.h&gt;

#include  &lt;stdint.h&gt;
#include  &lt;stdlib.h&gt;
#include  &lt;stdio.h&gt;
#include  &lt;stdbool.h&gt;

#include &lt;Arduino.h&gt;
#include  &quot;fastio.h&quot;


#define F_CPU 16000000UL

// pins for TX driver
#define PING0   PB1
#define PING1   PB2

#define LED     DIO13

#ifndef MASK
  #define MASK(m) (1UL &lt;&lt; m)
#endif

#define DEBUG 0
#define INTERVAL 100
#define diff(a,b) (((a) &gt;= (b))?((a)-(b)):((b)-(a)))

inline bool ge(uint32_t a, uint32_t b) {
  return ((a - b) &amp; 0x80000000UL) == 0;
}

inline bool lt(uint32_t a, uint32_t b) {
  return ((a - b) &amp; 0x80000000UL) != 0;
}

volatile uint32_t milliseconds = 0;

uint16_t starttime = 0;
volatile uint16_t envelopetime = 0;
volatile uint16_t phasetime = 0;

#define PULSECOUNT_X2 16
volatile uint8_t edges = 0;

void pins_init(void) {
  WRITE(PING0, 0);
  SET_OUTPUT(PING0);

  WRITE(PING1, 0);
  SET_OUTPUT(PING1);

  WRITE(LED, 0);
  SET_OUTPUT(LED);

}

void timer_init(void) {
  // init timers
  GTCCR = MASK(TSM) | MASK(PSRSYNC); // pause clocks

  PRR &amp;= ~MASK(PRTIM1) &amp; ~MASK(PRTIM0) &amp; ~MASK(PRADC); // enable timers 0 and 1 and ADC

  // use timer1 for output waveform generation and analog comparator timing
  TCCR1A = 0;                       // normal mode, no match behaviour
  TCCR1B = MASK(CS10);              // maximum speed (no prescale)

  // use timer0 for our millisecond clock
  TCCR0A = MASK(WGM01);             // CTC mode
  TCCR0B = MASK(CS00) | MASK(CS01); // prescaler=64, ie clock is 250kHz
  OCR0A  = 250;                     // interrupt at 1kHz, ie every 1ms
  TIMSK0 = MASK(OCIE0A);            // interrupt on compare

  // set up analog comparator
  ADCSRA = (0 &lt;&lt; ADEN);
  ADCSRB = (1 &lt;&lt; ACME);
  ADMUX = 0;
  ACSR |= 0x03;
  
  GTCCR = 0; // re-enable clocks
}

void setup(){
  pins_init();
  Serial.begin(115200);
}

void loop() {
  timer_init();
  sei();
  Serial.println(&quot;Start&quot;);

  uint32_t pingtime = INTERVAL;

  for (;;) {
    if (ge(milliseconds, pingtime) &amp;&amp; (edges == 0)) {
      // note when we should ping next
      pingtime += INTERVAL;

      // start in a millisecond from now to avoid race conditions
      starttime = TCNT1 + (F_CPU / 1000);
      OCR1A = OCR1B = starttime;

      // reset edge counter
      edges = PULSECOUNT_X2;

      // set A and clear B on match
      TCCR1A = MASK(COM1A0) | MASK(COM1A1) | MASK(COM1B1);

      // disable interrupt on comparator
      TIMSK1 &amp;= ~MASK(ICIE1);

      // clear flag in case it triggered during startup
      TIFR1 = MASK(OCF1A);

      // enable interrupt
      TIMSK1 |= MASK(OCIE1A);
    }
    if (phasetime != 0) {
      uint16_t eoff = envelopetime - starttime; // time when Rx signal became loud enough to consider, ie start of envelope
      uint16_t poff = phasetime - starttime;    // time of first zero crossing after envelope, use for calculating phase offset

      //printf_P(PSTR(&quot;envelope +%u (%uus) phase +%u (%uus)\n&quot;), eoff, eoff &gt;&gt; 4, poff, poff &gt;&gt; 4);

     Serial.println(eoff);
     //Serial.println(poff);

      // zero so we only print once, process data before this
      phasetime = 0;
    }
  }
}

ISR(TIMER1_COMPA_vect) {
  if (edges == PULSECOUNT_X2) {
    TCCR1B |= MASK(ICES1);   // listen for rising edge
    TIFR1 = MASK(ICF1);      // clear flags in case it triggered during startup
    TIMSK1 |= MASK(ICIE1);   // interrupt on comparator

    TCCR1A = MASK(COM1A0) | MASK(COM1B0); // toggle on match
    //Serial.println(&quot;PULSE&quot;);
    WRITE(LED, 1);
  }
  else if (edges == 1) {
    TCCR1A = MASK(COM1A1) | MASK(COM1B1); // clear both on match
  }
  else if (edges == 0) {
    //putc('&gt;');

    TIMSK1 &amp;= ~MASK(OCIE1A);   // disable interrupt

    return;
  }
  edges--;
  OCR1A = OCR1B += F_CPU / 80000; // set next timeout
}

ISR (ANALOG_COMP_vect)
  {
  phasetime = ICR1; 
  if((ACSR &amp; B00100000)){
    envelopetime = ICR1;      // store timestamp
    WRITE(LED, 0);
    TIMSK1 &amp;= ~MASK(ICIE1);   // disable interrupt on comparator
  }
}
  
ISR(TIMER0_COMPA_vect) {
  milliseconds++;
}
</code></pre>
 84816: <p>You have not enabled the comparator interrupt.</p>
<p>Just need to change the line where you set ACSR.</p>
<pre><code>//Comparator interrupt on rising output edge.
ACSR |= (1 &lt;&lt; ACIS0) | (1 &lt;&lt; ACIS1);   

//Enable comparator interrupt
ACSR |= (1 &lt;&lt; ACIE)
</code></pre>
<p>Can also be achieved with.</p>
<pre><code>ACSR = 0x0B
</code></pre>
<p>If you want to change what triggers an interrupt.
Bits 0 and 1 control how an interrupt is fired (Toggle, falling or rising).</p>
<pre><code>//Toggle (Default, only required if another interrupt mode is already selected)
ACSR &amp;= ~(0b11)

//Falling
ACSR &amp;= ~(1 &lt;&lt; ACIS0); //Only required if ACIS0 is set
ACSR |= (1 &lt;&lt; ACIS1);

//Rising
ACSR |= (1 &lt;&lt; ACIS0) | (1 &lt;&lt; ACIS1);
//Or
ACSR | = 0x03;
</code></pre>
<p>You will also need to enable global interrupts. (Which you have done)
Which can be done by calling...</p>
<pre><code>interrupts(); //Arduino only
sei();        //AVR and Arduino
</code></pre>
<p>I see you are calling &quot;sei&quot; in the loop, it only needs to be called once (unless you have disabled them with &quot;cli(),&quot; and I believe its not even required at all with Arduino as I think interrupts are already enabled.</p>
<p><a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf" rel="nofollow noreferrer">The datasheet is your friend.</a> Tutorials are a great way to learn, but if you really want to increase your skill set you should try to break free from tutorials as much as possible by reading the datasheet, and experimenting on your own.
The comparator starts on page 202, and would be a great place to start as its an easy peripheral to get going.</p>
