How do I use the Timer block to measure duty cycle of a free-running signal?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
joeac_1591236
Level 2
Level 2

I am trying to measure the roughly 50% duty cycle of a 750kHz free running signal.  I am using the UDB implementation of the Timer block with a 24MHz input clock with a rising edge trigger mode and a software controlled capture mode (which I set to falling edge).  I would like to record the number of clock cycles ("time") between rising and falling edge of the signal and to take numerous measurements in order to average the result.

How do I do this?

0 Likes
1 Solution

Hi ScottA_91​,

Since I read that the UDB counter can only accept a count frequency less than or equal to half the clock frequency, I moved back to the timer block and worked this out as a solution.  The Capture_Out will set the SR latch to hold the Timer reset high, giving me all the time I need to record the value from the capture FIFO.  Then I manually reset the latch once I've finished recording the value and the timer will then start to trigger on the next rising edge of the signal and stop again on the captured falling edge. 

Thanks for your help.

pastedImage_0.png

View solution in original post

0 Likes
3 Replies
ScottA_91
Employee
Employee
10 solutions authored 100 replies posted 50 replies posted

Well if it was me, I'd setup things a little differently.

Create a 32-bit counter (UDB) and setup enable to be a hardware signal.  Connect the input signal to this enable.  Make it an up counter.  Run the 24MHz clock in, and set the pin to interrupt on falling edge.

When the interrupt is triggered, clear it and set a flag for your main loop.

In you main loop, if the flag is set, copy out the new 32 bit value, and reset the counter.  Then average your values.

0 Likes

I see the merits of that solution and was able to do a proof-of-concept with a slight variation from your suggestion.  However, I am now running into a timing issue.  Ideally, I want clock and count to be the same to achieve the highest resolution but I'm unable to capture data when running the 24MHz clock to both count and clock due to an asynchronous routing issue.  I am able to read data when I put an 8MHz clock on the count pin.

Do you have any recommendations for how to get the count and clock to run at 24MHz?  See my test project attached.

0 Likes

Hi ScottA_91​,

Since I read that the UDB counter can only accept a count frequency less than or equal to half the clock frequency, I moved back to the timer block and worked this out as a solution.  The Capture_Out will set the SR latch to hold the Timer reset high, giving me all the time I need to record the value from the capture FIFO.  Then I manually reset the latch once I've finished recording the value and the timer will then start to trigger on the next rising edge of the signal and stop again on the captured falling edge. 

Thanks for your help.

pastedImage_0.png

0 Likes