0
\$\begingroup\$

I have been using PIC18 micro-controller for generating reference signal and a charging signal at 100 Hz rate max. Now I have to generate this charging signal after sensing an external trigger pulse of width 15us with frequency in between 1 to 100 Hz. I am using 4 timers of PIC18 for different purposes and one timer is available. I am thinking of using external interrupt on rising edge but how to check 15uS pulse width. I mean what if the external pulse only rises to logic high and doesn't go to logic low. How would I know that? How to verify that the input pulses are in integer format only i.e. 1Hz, 2Hz and not 1.5Hz or any other values? How to mark limit for sensing up to 100 Hz only?

\$\endgroup\$
  • 1
    \$\begingroup\$ Setup a timer as a counter with a clk frequency of 1MHz. Start the counter once you have detected a rising edge and keep it running until you detect a falling edge. Then read the counter register. This will give you pulse width in microseconds. \$\endgroup\$ – Rohat Kılıç Feb 1 '17 at 4:17
  • \$\begingroup\$ Thanks for the reply. What about checking frequency value and its limit? \$\endgroup\$ – Maanas Feb 1 '17 at 5:52
  • \$\begingroup\$ Is it mandatory to check for the pulse width to be exactly 15us? If the signal was a square wave of, say, f=45hz, which is in the valid range, should your device react? \$\endgroup\$ – zakkos Feb 1 '17 at 8:41
  • \$\begingroup\$ No, not mandatory. But I just want to make it sure that this shouldn't be DC. As far as i know the pule width coming from the device is to make it sure no false triggering occurs. \$\endgroup\$ – Maanas Feb 1 '17 at 9:20
  • \$\begingroup\$ So...Have you tried? \$\endgroup\$ – zakkos Feb 4 '17 at 1:15
0
\$\begingroup\$

Since you're only checking if a signal of a specified frequency range is being received, and not its width/duty (as per your comment), you can setup the (E)CCP module to capture some rising (or falling) edges to get the period of your signal. From that you can calculate the signal frequency and act accordingly.

You can easily discriminate between a valid signal and DC because dc would simply not have a period while random noise can be filtered out.

If the ECCP module is not available (or it's not suitable to capture your frequencies, I don't honestly remember right now its usable range) you can setup a timer to emulate it in software by reading how much time passes between two or more rising or falling edges.

| improve this answer | |
\$\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.