Programming PIC32 Microcontroller Inputs

Thread Starter

DancinNancy

Joined Oct 1, 2008
24
I am working on a project for college and I hit a snag in my programming. This is my first time to ever deal with programming microcontrollers and I'm not sure how to measure frequency. It has 16 analog inputs and I need to measure the frequency of 6 guitar strings. They output about 1 Volt rms and vary in frequencies from 90 to 630 hz. If anyone could help with this I would appreciate it. I am programming this in MPLAB using C.
 

leftyretro

Joined Nov 25, 2008
395
I am working on a project for college and I hit a snag in my programming. This is my first time to ever deal with programming microcontrollers and I'm not sure how to measure frequency. It has 16 analog inputs and I need to measure the frequency of 6 guitar strings. They output about 1 Volt rms and vary in frequencies from 90 to 630 hz. If anyone could help with this I would appreciate it. I am programming this in MPLAB using C.

One normally wouldn't use analog input pins to measure the frequency of a signal. While it's not impossible, it is computationally complex and not efficient at all. A more typical method would be to run those signals to a comparator circuit (some micros have built in comparator functions) to turn the signal into a square wave of full amplitude. Then the signal can be read as a simple digital input signal and the frequency can be calculated by measuring the pulse repetition rate.

Lefty
 

jnvarsha

Joined Jan 21, 2009
3
I would like to give u one more information that If u r using PIc microcontroller, u can use PIC16F876A. It has got inbuilt analog to digital converter as well as analog to digital comparator. So if u want u can use analog inputs pins too & get it converted to digital pulse to measure the frequency as said by other buddy in reply to this quote.
 

beenthere

Joined Apr 20, 2004
15,819
That could lead to problems due to aliasing. A little external circuitry to buffer and rectify the analog input into a voltage comparator will produce the logic level square wave. All you need to do then is to see how many pulses come in in a period of time to be able to calculate the frequency. Much simpler.
 

Thread Starter

DancinNancy

Joined Oct 1, 2008
24
Thanks everyone i didn't even think to use a digitial input. Do i even need to convert it to a square wave since the input will alternate between true and not true at half of the actual frequency? Also what would be the easiest way to count the pulses coming in?
 

beenthere

Joined Apr 20, 2004
15,819
Your audio is going to be AC in nature, so rectifying it makes sense to prevent excursions below ground. Applying the resulting waveform to a comparator will result in a "squarer" waveform with more abrupt transitions. Logic is usually happier with fast transitions.
 
Top