CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Frequency Meter with PIC18F87J10

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sizzurb



Joined: 13 Feb 2019
Posts: 1

View user's profile Send private message

Frequency Meter with PIC18F87J10
PostPosted: Wed Feb 13, 2019 6:54 pm     Reply with quote

I am looking for help creating a C program to measure the frequency of an incoming sound. The goal is to find the frequency of the sound and to determine if it falls into a range so I can output a sound when it falls within this range. The range is between 800 Hz and 1200 Hz. Any code to get me started would be appreciated. It will be used in a pair of headphones using 3.3 V.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Feb 13, 2019 9:19 pm     Reply with quote

Before cutting ANY code, get the hardware right !!
Audio (your 800 Hz to 1200 Hz) is probably a SINE wave, going + AND - from zero volts. The PIC's ADC will ONLY accept a POSITIVE voltage ! ( it's in the specs....way at the bck of the 400-500 pages no one reads...well, few read.
So for the ADC to NOT be destroyed, and to read the signal you need to 'offset' the incoming sine wave so that it's zero cross is 1/2 Vref. If Vref is VDD, then the 'offset' zero will now be 2.5 volts. You also have to calculate the correct gain of the amplifer so that you don't go over the Vref value. So the most positive level can't be above 5 volts in this case.
This can all be done with one opamp and a few resistors, a pot of coffee and some 'math'. Normally Vref will be from a very stable precision source not VDD. Remeber to measure VDD as it won't be 5.00, could be 4.97, 5.24,??

as for code,CCS supplies a basic program ex_freq.c I believe.

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group