PIC32 Input

Thread Starter

DancinNancy

Joined Oct 1, 2008
24
Does anyone have any sort of sample code for measuring an input on a pic32 microcontroller. I am writing the code in C and i need to just count the pulses over a certain amount of time to get the frequency. I posted about this in the past and was told to use a comparator for the circuit to measure the frequency which i have already ordered. I already know which ports I will be using for the measurements(six pins off port b) but i didnt know the best way to measure the input. Also if i use the comparator to make a digital signal will the output be a logic "high" or will it be as high as the input voltage gets
 

beenthere

Joined Apr 20, 2004
15,819
The idea should be to use the comparator to square up the edges of input signals. If it has an open collector output, use the same Vcc as the PIC32, and the input will be valid.

Frequency counting amounts to accumulating a count for an accurately known period of time. Frequency counters use a crystal timebase running at some convenient frequency that can be divided down to a period such as 1 second or .1 second. Look up the basics of a frequency counter for more ideas.

If you are using an accurate clock oscillator for the PIC's clock, you may be able to buffer it and apply it as the timebase. That might get busy trying to use internal registers in the PIC. I might try to set up an external counter and interrupt the PIC every time the counting period was up.
 
Top