# Change default D8 input pin of Input Capture Unit program for AVR Atm 328?

**URL:** <https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061>\
**Category:** Programming\
**Created:** [March 23, 2020, 8:54pm UTC](https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061 "2020-03-23T20:54:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomsz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomsz/32/277729_2.png) [@tomsz](https://forum.arduino.cc/u/tomsz)\
**Post date:** [March 23, 2020, 8:54pm UTC](https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061/1 "2020-03-23T20:54:26Z")

</div>

I have a Timer1 frequency measurement program using the Input Capture Unit function from Nick Gammon's blog. it uses uses the D8 pin **(ICP1)** in the code as the input. How can I change the input pin to another digital pin like D7(AIN1?) or D5(T1?), or D2(INT0?), D3(INT1?), etc? Would that affect the Timer1 function? The Adafruit Feather 328 module I have does not have a D8 or is used for some other function.

> **[Gammon Forum : Electronics : Microprocessors : Timers and counters](http://www.gammon.com.au/forum/?id=11504)**
>
> Gammon Forum : Electronics : Microprocessors : Timers and counters

Thank you!

```cpp
// Duty cycle calculation using input capture unit
// Author: Nick Gammon
// Date: 5 November 2013

// Input: Pin D8

volatile boolean first;
volatile boolean triggered;
volatile unsigned long overflowCount;
volatile unsigned long startTime;
volatile unsigned long finishTime;

// timer overflows (every 65536 counts)
ISR (TIMER1_OVF_vect)
{
  overflowCount++;
}  // end of TIMER1_OVF_vect

ISR (TIMER1_CAPT_vect)
  {
  // grab counter value before it changes any more
  unsigned int timer1CounterValue;
  timer1CounterValue = ICR1;  // see datasheet, page 117 (accessing 16-bit registers)
  unsigned long overflowCopy = overflowCount;
 
  // if just missed an overflow
  if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 0x7FFF)
    overflowCopy++;
 
  // wait until we noticed last one
  if (triggered)
    return;

  if (first)
    {
    startTime = (overflowCopy << 16) + timer1CounterValue;
    TIFR1 |= bit (ICF1);    // clear Timer/Counter1, Input Capture Flag
    TCCR1B =  bit (CS10);    // No prescaling, Input Capture Edge Select (falling on D8)
    first = false;
    return; 
    }
   
  finishTime = (overflowCopy << 16) + timer1CounterValue;
  triggered = true;
  TIMSK1 = 0;    // no more interrupts for now
  }  // end of TIMER1_CAPT_vect
 
void prepareForInterrupts ()
  {
  noInterrupts ();  // protected code
  first = true;
  triggered = false;  // re-arm for next time
  // reset Timer 1
  TCCR1A = 0;
  TCCR1B = 0;
 
  TIFR1 = bit (ICF1) | bit (TOV1);  // clear flags so we don't get a bogus interrupt
  TCNT1 = 0;          // Counter to zero
  overflowCount = 0;  // Therefore no overflows yet
 
  // Timer 1 - counts clock pulses
  TIMSK1 = bit (TOIE1) | bit (ICIE1);  // interrupt on Timer 1 overflow and input capture
  // start Timer 1, no prescaler
  TCCR1B =  bit (CS10) | bit (ICES1);  // plus Input Capture Edge Select (rising on D8)
  interrupts ();
  }  // end of prepareForInterrupts
 

void setup ()
  {
  Serial.begin(115200);       
  Serial.println("Duty cycle width calculator");
  // set up for interrupts
  prepareForInterrupts ();   
  } // end of setup

void loop ()
  {
  // wait till we have a reading
  if (!triggered)
    return;
 
  // period is elapsed time
  unsigned long elapsedTime = finishTime - startTime;
 
  Serial.print ("Took: ");
  Serial.print (float (elapsedTime) * 62.5e-9 * 1e6);  // convert to microseconds
  Serial.println (" uS. ");

  // so we can read it 
  delay (500);

  prepareForInterrupts ();   
}  // end of loop

```

 ![ATMega328P-Arduino-Uno-Pin-Mapping.png](https://europe1.discourse-cdn.com/arduino/original/4X/8/8/5/8857d9015e2080205d0a454d9ce9e90260d65550.png)

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [March 23, 2020, 8:57pm UTC](https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061/2 "2020-03-23T20:57:15Z")

</div>

You can't. There is only one ICP capable pin on the 328. What is the "Adafruit Feather 328 module"? I thought the Feather used a different processor...

---

<div class="post-metadata">

**Author:** ![tomsz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomsz/32/277729_2.png) [@tomsz](https://forum.arduino.cc/u/tomsz)\
**Post date:** [March 23, 2020, 9:01pm UTC](https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061/3 "2020-03-23T21:01:55Z")

</div>

> **[Adafruit Feather 328P](https://learn.adafruit.com/adafruit-feather-328p-atmega328-atmega328p/pinouts)**
>
> With this Feather we're getting a little nostalgic for the ATmega328P - the classic 'Arduino' chip - with this Adafruit Feather 328P running a 3.3V and 8 MHz. Feather is the new development board from Adafruit, and like it's namesake it is thin,...

Thank you for the quick reply. This the actual module. It does not have D8 showing anywhere. Maybe its mapped to another function like TX or RX, etc.

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [March 23, 2020, 9:15pm UTC](https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061/4 "2020-03-23T21:15:57Z")

</div>

The input capture can also come from the analog comparator output. Perhaps you could use that somehow, instead.

---

<div class="post-metadata">

**Author:** ![tomsz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomsz/32/277729_2.png) [@tomsz](https://forum.arduino.cc/u/tomsz)\
**Post date:** [March 23, 2020, 9:32pm UTC](https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061/5 "2020-03-23T21:32:11Z")

</div>

Thank you. I am going to research using the Analog Comparator.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:24am UTC](https://forum.arduino.cc/t/change-default-d8-input-pin-of-input-capture-unit-program-for-avr-atm-328/644061/6 "2021-05-06T00:24:01Z")

</div>


