2
$\begingroup$

I need to count digital pulses with a width of 30 ns and display the updated count to the user every second. The pulses have already been through a comparator and a pulse shaper. Resolution isn't a concern, my only concern is the counting the number of 30 ns pulses while picking up minimal noise.

Is there an easy way to use a PIC microcontroller or a special circuit to execute the count? Could I use a PIC or circuit to execute the count and relay the count to a raspberry pi for further processing/display?

$\endgroup$
1
$\begingroup$

30ns is too fast for PIC microcontrollers that I know of. For example, the PIC16F77 requires a period of one instruction cycle plus 40ns, so at maximum clock frequency the period must be at least 200+40ns.

I would use a 4-bit counter IC (eg 74169, synchronous 4-bit binary up/down counter) which would divide by 16. It's output would be fed into the PIC's timer input pin (T0CKI for the 16F77). But this will only count multiples of 16. If you want a precise count while pulses are being received it will get tricky because not only would those 4 bits need to be latched, but they'd have to be synchronised with the PIC's timer/counter.

$\endgroup$
0
$\begingroup$

One way to count the pules is to use an interrupt trigger on positive or negative edge. You can use a the PIC or even you might be better of using the raspberry pi it self. With regard to minimizing noise I would suggesting placing an appropriate filter circuit to filter out the noise.

Another one to consider is Capture and Compare mode. I have not used this but I read about this briefly. I think PIC microcontroller support Capture and Compare.

Lastly with regard to noise, it is best that you understand the source of the noise and characteristic of the noise. Then filter out the any noise that affects your design.


References:

$\endgroup$
0
$\begingroup$

I don't know PICs, but they, like most microcontrollers have timer/counter registers which can be set up as input from a GPIO to up-count those digital pulses on a rising edge, falling edge, or both edges. You need to make sure your processor frequency is higher than your input frequency otherwise you can miss some counts. Also, depending on the size of the counter register, 8, 16, 32 bit, etc you could run into an overflow condition. In that case. You need to trigger an interrupt(ISR) when the counter overflows to maintain the overflow count. For example, In an 8 bit counter register, it will overflow and reset to 0 after 255 pulses have been counted. The counter can trigger an interrupt on an overflow condition and that interrupt routine can simply do something like overflowCount+=1

When you read your total pulse count to the user, you would need to do:totalPulses= counter register value+(255*overflowCount)

I don't know for how long this will count, but you could overflow your counter variable if you don't use a large enough variable type. Maybe use a 64bit Long type.

Read through your PIC's data sheet and you should find an example of a counter.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.