Pulse capture with Arduino Zero

Hi everyone,

I know there's been a lot of discussion lately about generating pulses with the Zero, but what about capturing them? I am looking to count the number of pulses over a time period so I can calculate the average number of pulses. These are random pulses so measuring the time between pulses won't work for my application.

Thanks

Hi dlabun,

To capture input pulses you can either simply use interrupts, or if the pulses are relatively closely spaced you could try timer pulse capture detailed here: Arduino Zero TCC Capture - Arduino Zero - Arduino Forum. Interrupts are probably the most flexible way.

Using either method you just need to increment a counter in your callback (handler) function everytime a pulse occurs.

Hi Martin,

Prior to this post I did quickly look at the post you linked and it seemed like it would not work for me. I am only interested in the number of pulses, not the width or timing. I will read it again as the code may be part of my solution. An ISR for every pulse is not feasible since I have other interrupts for user buttons and I want the count to be as accurate as possible.

Thanks,
Doug

When talking of pulses, the words "capture" and "count" usually mean very different things.

Fair point Paul, I truly only want a count of pulses and not capturing the specifics of the pulse. I'm dealing a photo multiplier so it's all about counting the number of events.

Hello Everyone.

I was working in a Project with Arduino Leonardo which main task was to count pulses. Code was as this

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  This function establishes initial configuration to work with T1 timer/counter
  module as pulse counter
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void Timer_INI(void)
{
  // Initilization of T1 timer/counter A register
  TCCR1A = 0;
  
  // Choose clock source to increment (work) T1 timer counter
  bitSet(TCCR1B, CS12);  // Clock source is external pin (pin 12)
  bitSet(TCCR1B, CS11);
  bitSet(TCCR1B, CS10);  // Counting in rising edge CS12 = 1, CS11 = 1, CS10 = 1
  
  TCNT1 = 0;  // Clear T1 counter register to begin count pulses
}


void loop()
{

  delay(500);          // wait for a half second


  /* -'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-
    T1 counter register value will be take every 0,5 sec
  -'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'-'o'- */
  NumPulsos += TCNT1;  // Take actual value and add to past value
  TCNT1 = 0;           // Clear T1 counter register to begin count pulses
  
  ...
  
  ...
  
}

Now, i need to perform same task with Arduino Zero board, but in others topic I've read I do not find anything simple as previous code.

Is there any way to configure TCCx from Arduino Zero just to count pulses without use interrupts?

Hello

After seeking in other forums and topics, I could implement a code to count pulses in Arduino M0; it is not so simple as Leonardo code but it works.

If someone is interested it can be found in next thread.
http://forum.arduino.cc/index.php?topic=396804.msg3078404#msg3078404

Vladimir Zúñiga