Skip to main content
added 2 characters in body
Source Link
chrisl
  • 16.6k
  • 2
  • 18
  • 27

I'm messing about with an Arduino Mega2560r3 and failing to get timer 4 to trigger on the rising edge of an external clock. It only ever triggers on the falling edge.

I've tried

     TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);

and

     TCCR4B = (1 << CS42) | (1 << CS41);

... one of which should do the trick, but now I've pulled all my hair out and I'm turning to the wider community to see what I'm not seeing!

void setup() {
  DDRE = (1 << PE5);   //Dig pin 3 as output

  noInterrupts();
// Configure Timer 4 (only ICP4 (pin 49) and ICP5 (pin 48) are connected with Arduino MEGA2560 r3)
  TCCR4A = 0;
  TCCR4B = 0;
  TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);    // CTC mode does not reset when using force
  TIMSK4 = (1 << ICIE4);    // enable capture interrupt
  interrupts();
}

ISR(TIMER4_CAPT_vect)
{
  PORTE ^= (1 << PE5);  // Toggle PE5
}```

Scope output below - blue is external clock (yes I know it's a sine wave!) and magenta is pin 3 output

[![falling edge trigger output][1]][1]


  [1]: https://i.sstatic.net/glqvM.png

Scope output below - blue is external clock (yes I know it's a sine wave!) and magenta is pin 3 output

falling edge trigger output

I'm messing about with an Arduino Mega2560r3 and failing to get timer 4 to trigger on the rising edge of an external clock. It only ever triggers on the falling edge.

I've tried

     TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);

and

     TCCR4B = (1 << CS42) | (1 << CS41);

... one of which should do the trick, but now I've pulled all my hair out and I'm turning to the wider community to see what I'm not seeing!

void setup() {
  DDRE = (1 << PE5);   //Dig pin 3 as output

  noInterrupts();
// Configure Timer 4 (only ICP4 (pin 49) and ICP5 (pin 48) are connected with Arduino MEGA2560 r3)
  TCCR4A = 0;
  TCCR4B = 0;
  TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);    // CTC mode does not reset when using force
  TIMSK4 = (1 << ICIE4);    // enable capture interrupt
  interrupts();
}

ISR(TIMER4_CAPT_vect)
{
  PORTE ^= (1 << PE5);  // Toggle PE5
}```

Scope output below - blue is external clock (yes I know it's a sine wave!) and magenta is pin 3 output

[![falling edge trigger output][1]][1]


  [1]: https://i.sstatic.net/glqvM.png

I'm messing about with an Arduino Mega2560r3 and failing to get timer 4 to trigger on the rising edge of an external clock. It only ever triggers on the falling edge.

I've tried

     TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);

and

     TCCR4B = (1 << CS42) | (1 << CS41);

... one of which should do the trick, but now I've pulled all my hair out and I'm turning to the wider community to see what I'm not seeing!

void setup() {
  DDRE = (1 << PE5);   //Dig pin 3 as output

  noInterrupts();
// Configure Timer 4 (only ICP4 (pin 49) and ICP5 (pin 48) are connected with Arduino MEGA2560 r3)
  TCCR4A = 0;
  TCCR4B = 0;
  TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);    // CTC mode does not reset when using force
  TIMSK4 = (1 << ICIE4);    // enable capture interrupt
  interrupts();
}

ISR(TIMER4_CAPT_vect)
{
  PORTE ^= (1 << PE5);  // Toggle PE5
}

Scope output below - blue is external clock (yes I know it's a sine wave!) and magenta is pin 3 output

falling edge trigger output

Source Link

Unable to use rising edge interrupt for external clock Arduino 2650

I'm messing about with an Arduino Mega2560r3 and failing to get timer 4 to trigger on the rising edge of an external clock. It only ever triggers on the falling edge.

I've tried

     TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);

and

     TCCR4B = (1 << CS42) | (1 << CS41);

... one of which should do the trick, but now I've pulled all my hair out and I'm turning to the wider community to see what I'm not seeing!

void setup() {
  DDRE = (1 << PE5);   //Dig pin 3 as output

  noInterrupts();
// Configure Timer 4 (only ICP4 (pin 49) and ICP5 (pin 48) are connected with Arduino MEGA2560 r3)
  TCCR4A = 0;
  TCCR4B = 0;
  TCCR4B = (1 << CS42) | (1 << CS41) | (1 << CS40);    // CTC mode does not reset when using force
  TIMSK4 = (1 << ICIE4);    // enable capture interrupt
  interrupts();
}

ISR(TIMER4_CAPT_vect)
{
  PORTE ^= (1 << PE5);  // Toggle PE5
}```

Scope output below - blue is external clock (yes I know it's a sine wave!) and magenta is pin 3 output

[![falling edge trigger output][1]][1]


  [1]: https://i.sstatic.net/glqvM.png