Timing a signal using a Counter

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

cross mob
lock attach
Attachments are accessible only for community members.
HuEl_264296
Level 5
Level 5
First like given 25 sign-ins First solution authored

 Hi,

   

I just cannot seem to understand how the Counter component works. It seems simple, and yet my design doesn't work.

   

I have an input pin connected to a signal which is low most of the time, but occasionally sees high pulses lasting a few tens of milliseconds. These occur at random intervals.

   

What I would like is to keep a count of the total high time of this signal, and generate an interrupt when it passes some threshold.

   

I have attached an image of my schematic. The counter is configured as a UDB down counter, period 200, interrupt on TC.

   

Please set me straight.

   

Hugo

0 Likes
3 Replies
HuEl_264296
Level 5
Level 5
First like given 25 sign-ins First solution authored

 Sorry, I forgot that the input signal is actually inverted, which is why I needed to put that not gate in there.

0 Likes
Anonymous
Not applicable

Are you trying to count how many high pulses?

   

or

   

How long is the input stay high?

0 Likes
Anonymous
Not applicable

Hi Rocketmagnet,

   

 

   

What I understand from your requirement is that you need to use a counter to count the high period of every pulse and also issue an interrupt when the High period exceeds a threshold, is that right?

   

 

   

If that is the case, then one way to implement it is to use the Capture feature to determine the High period. The Compare value has to be set according to your threshold requirement. Upon compare match, an interrupt is generated if "Interrupt on Compare" is enabled or the "comp" terminal on the component also gives a pulse. ISR can be connected to this terminal to execute your code on interrupt.

0 Likes