4-ch frequency capture

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm reading the datasheet of xmega au to understand how to use the frequency capture to measure 4 signals.

They might go down to 0 Hz, but I'm fine to measure them only when the frequency rise a bit.

 

What I don't understand from the ds:

 

  1. "any events from the event system can trigger a capture operation", but looking at the ChnMUX register all pins of a port share the same event. Hence, to have 4 independent events I need to wire each channel to a different port. Is it correct?
  2. "since all capture channels use the same counter (CNT), only one capture channel must be enabled at a time." - in the same way I need to use 4 different Timers 0/1, right?
  3. I need to set the timer in normal mode, selecting prescaler and period according to the frequency range I'm interested to capture. Then set the FRQ group in EVACT, the event channel in EVSEL, finally I can read the measured value in the CCx registers. Am I correct?
     
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For frequency capture you can just use the timers, and have an interrupt trigger on capture, or poll, or use events to trigger DMA.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the hint. I still don't understand. When you say "you can just use the timers" are you meaning I can use just one? 
As first try I setup a freerun timer and on each interrupt I read the current value and calculate the difference between the last (manually) captured one.

 

This method has some drawbacks:

 

  • it works with few lines at quite low frequencies: going up the interrupts will continuously breaks any other activity. If you have also some high-speed serials you will likely lose bytes
  • there isn't (as far as I know) a FAST way to check which pin has triggered the interrupt. You have to store the last state and check the new one. With many signals they might toggle very close each other and you can lose some changes

 

For this reasons I was looking for a way that uses the peripheral of the MCU - avoiding any fw issue.

By the way, now I need to capture 6 signals...

 

Of course if I didn't understand your answer, please try to explain it again - I apologize for that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"but looking at the ChnMUX register all pins of a port share the same event."

No, we select the port AND a bit (pin) on that port. 
Using four event channels, you can pick four pins from the same port.

"only one capture channel must be enabled at a time." - in the same way I need to use 4 different Timers 0/1, right?"

Yes, it sure sounds like it.  Or, you could just use the plain capture mode for the four capture channels on one timer and compute the period yourself. It sounds like that's what you've already tried.

 

As for the interrupt rate, wouldn't you have the same problem with frequency measurement in hardware - an interrupt for each line for each period?

 

Attachment(s): 

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mha11 wrote:
As for the interrupt rate, wouldn't you have the same problem with frequency measurement in hardware - an interrupt for each line for each period?

 

No, I hope. If I will end up with 6 different ISR, each one will be executed in very few lines of code (just compute the period). Instead, in my current code I have only ONE interrupt routine, and I have to check among all pins to find out which has changed. 

Anyway, I'm open to any other suggestion how to route the signals to the MCU peripherals to easily measure the frequency.