Which technique is good to measure frequency, GPIO or ADC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Which technique is good to measure frequency, GPIO or ADC

860 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Sukruth on Thu Sep 12 04:30:15 MST 2013
Hi,
I need to measure input sine wave frequency (~ 200Hz),
could you kindly comment on the better technique in terms of speed, accuracy, pros and cons for,

1. use GPIO interrupt with  external schmitt trigger

OR

2.Directly use ADC to count the frequency.


Thanks
Labels (1)
0 Kudos
3 Replies

656 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arw on Sun Sep 15 19:48:58 MST 2013
Hello Sukruth,
Since 200Hz is a long time interval for using a capture input with dedicated timer, you might just use software in an interval timer, and use the edge interrupt to read your software counter.
Please look at the examples for RITimer and ExtINT in the MCB1700 example code bundle (http://www.lpcware.com/system/files/mcb1700.code_.bundle.lpc1769.lpcxpresso.zip)

Set the interval time of RITimer interrupt to be at least 10x faster than your input signal.  Increment a software counter in the interrupt service routine.
Configure the external interrupt to detect the rising/falling edge of the input waveform.  In the interrupt service routine, read your software counter and check it is in the desired range.

If the accuracy of this method is not enough, you can increase the interval time of RITimer or change to a real capture interrupt with hardware timer.

-allen
0 Kudos

656 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Sukruth on Thu Sep 12 21:25:44 MST 2013
Hello Allen,

Thanks for the info,
just one more small help,

could you kindly help/direct me with a sample code I can use to capture-compare register to capture the timer value on pin input edges.
sorry I'm new to this,


Regards,

Sukruth
0 Kudos

656 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arw on Thu Sep 12 10:26:56 MST 2013
Hello Sukruth,
The simplest method should be to use a timer input/capture, or digital input with edge-triggered interrupts and an internal timer.  At 200Hz you have plenty of CPU processing time to handle the interrupt and read+reset a counter.  You can have reasonable accuracy with this method if the input waveform is well-behaved and passes the schmitt trigger nicely.
Analog can be very accurate, but requires CPU processing since you will be frequently measuring the input voltage and performing signal processing to arrive at a frequency.  It's expensive in CPU time.

Allen
0 Kudos