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

PIC16F84 as frequency comparator

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







PIC16F84 as frequency comparator
PostPosted: Thu Nov 12, 2009 11:52 am     Reply with quote

Hello guys,

Surfing on the web I found this excellent forum about C language.

I´m really new on this area and I have a big problem with one step of my college graduation project.

I have a external clock from 7200hz to 6210Hz depending of sensor reading and I´m using EWB to simulate that clock generator and PIC16F84 to do this logic. The idea is when system have frequency = or less 6400hz, the PIC active a external port. It´s a eternal loop and for cost reduction i´m using PIC internal oscillator (RC)

So, I confess that I´m not expert about this and actually I have a lot of difficult to do that :(

Can anyone take a look on this draft code and help me to solve my issue?

Code:
#include <16F877.h>          
#fuses RC,NOWDT,NOPROTECT    
#use delay(clock=500000)
#use FAST_IO(B)

void main()
{
int timer0;
set_tris_b(0x00);
setup_timer_0(RTCC_INTERNAL);       
timer0 = get_timer_0();            
if( timer0 <= 800 )   output_high(B);         // 6400hz / 8Bits
else

Loop? here?

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 12, 2009 1:27 pm     Reply with quote

Post the manufacturer and part number of the sensor, and post a link
to the webpage for it.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Thu Nov 12, 2009 3:08 pm     Reply with quote

Sounds easy enough. Provided that the sensor really delivers an output in the range you say, you can use it to trigger an interrupt (wire the signal to port B.0). Every time the interrupt happens, compare the value of a timer to a threshold (I think you will find that 156 is the relevant number, but you might have to fudge that to allow for time taken between reading and setting the timer), and set that timer back to zero. Based on the comparison with the threshold, set or clear the output.

For extra credit, set up a second interrupt that occurs when the timer wraps around from 255 to 0. That indicates that the timer never got reset by the sensor input, and so it tells you that the sensor isn't connected, or has failed. You can have another output to show this.
Psico



Joined: 12 Nov 2009
Posts: 1

View user's profile Send private message

PostPosted: Fri Nov 13, 2009 5:39 am     Reply with quote

All right, here you are:

The sensor is HS1101LF from Humirel: http://www.ic-on-line.cn/IOL/viewpdf/HS1101LF_4369522.htm

Here is my first block simulated with RH 85% = 188.6pF =~ 6300Hz

http://img188.imageshack.us/img188/1556/capturecc.jpg

Could you help me please? I have big trouble about that Sad

Best Regards,
Psico
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 13, 2009 2:02 pm     Reply with quote

Read these threads on measuring frequency with the PIC, by using
the CCP module. These threads have several pages:
http://www.ccsinfo.com/forum/viewtopic.php?t=33153
http://www.ccsinfo.com/forum/viewtopic.php?t=29963
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