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

Freq measure

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







Freq measure
PostPosted: Wed Jun 23, 2004 10:11 am     Reply with quote

HELP me with link to freq meter by CCS. (with comments)
dvsoft



Joined: 28 Nov 2003
Posts: 46

View user's profile Send private message

PostPosted: Wed Jun 23, 2004 1:11 pm     Reply with quote

bonjour,

#include <18F452.h>
#device adc=8
#use delay(clock=40000000)
#fuses NOWDT,WDT128,H4, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, NOPUT, STVREN,NODEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)


//--------------------------------------------------------------------------
// CCP1 Data
//
int16 CCP1Value;
int16 CCP1OldValue;
BOOLEAN CCP1Captured;

//--------------------------------------------------------------------------
#int_CCP1
CCP1_isr()
{
CCP1Value = CCP_1 - CCP1OldValue;
CCP1OldValue = CCP_1;
CCP1Captured = TRUE;
}
//--------------------------------------------------------------------------
void HWInit(void)
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
//--- Setup de CCP1
setup_ccp1(CCP_CAPTURE_RE);
//--- Timer 1 for CCP1
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
//--- CCP1 Data
CCP1Value = 0;
CCP1OldValue = 0;
CCP1Captured = TRUE;
//--- CCP1 Interrupt
enable_interrupts(INT_CCP1);
//--- Global Interrupt
enable_interrupts(GLOBAL);
}
//--------------------------------------------------------------------------
void main()
{
float Freq;
HWInit();
printf("Frequence test:\r\n");
while (TRUE) {
//--- CCP1 Captured ?
if (CCP1Captured) {
//---
// F = 1/T
// Timer1 prescaler DIV_BY_8
// Pic18F452 at 40Mz -> 0.00000010 * 8
//
Freq = 1.0/((float)CCP1Value*8e-6);
printf("Freq:%f\r\n",Freq);
CCP1Captured = FALSE;
}// End IF
}// End While
}

Voila bon courrage

Alain
Userrr
Guest







Thanks
PostPosted: Thu Jun 24, 2004 9:19 am     Reply with quote

Thanks dvsoft
Userrr
Guest







max frequency
PostPosted: Tue Jun 29, 2004 10:06 am     Reply with quote

tell me max frequency for using CCP and 40Mhz ?
How me measure 50Mhz using timer?
Simon Martineau



Joined: 28 Jun 2004
Posts: 10
Location: Montreal

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 12:25 pm     Reply with quote

You must understand that you are not mesuring directly the frequency but calculating it from the period (f=1/T). The way you measure the period is by counting how many cycles at 40MHz will be completed in a complete period. This way, it is completely impossible to measure a 50 MHz frequency. You can only know the frequency is higher than 40 MHz because of the count (1 sometimes and 0 sometimes). The max frequency depends on the prcesion you need. As an example, a 7MHz frequency can read 6.6MHz or 8MHz. If it i acceptable for your application, nice. Otherwise, you will need to lower the max frequency to get an acceptable error margin.

I might be wrong but that's what I think about the subject. If you find a way to measure a frequency higher than your base clock, I'd be very interested to know it.

Simon Martineau
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

frequency counter
PostPosted: Tue Jun 29, 2004 12:32 pm     Reply with quote

The only way it can be done is to condition the signal then feed it to a prescaler (i.e divide by 2, 4 etc) then make the freq measurement and multiply the result.

There are numerous examples out there:

Here is one 50MHZ unit based on the PIC.

http://www.web-ee.com/Schematics/FrequencyCounter/frequency_counter.htm
Userrr
Guest







But
PostPosted: Tue Jun 29, 2004 2:25 pm     Reply with quote

But were I can found CCS example
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

Freq Counter
PostPosted: Tue Jun 29, 2004 3:34 pm     Reply with quote

The CCS example file (NOT an accurate 50MHZ freq counter) is EX_FREQC.C in the PICC/examples directory after you install the software.

If you dont have it and you have a licensed/registered copy of the compiler you will have to contact CCS via email and they will send it to you.

One word of caution, since this is for signals coming in on pin C0 it will not work will all types of signal waveforms and you cannot exceed the pin input maximum voltage or it will damage the chip! As I stated earlier you need some type of conditioning input circuit.
testing
Guest







PostPosted: Wed Aug 18, 2004 12:43 pm     Reply with quote

Code:
#include <18F452.h>
#device adc=8
#use delay(clock=40000000)
#fuses NOWDT,WDT128,H4, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, NOPUT, STVREN,NODEBUG, LVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)


//--------------------------------------------------------------------------
// CCP1 Data
//
int16 CCP1Value;
int16 CCP1OldValue;
BOOLEAN CCP1Captured;

//--------------------------------------------------------------------------
#int_CCP1
CCP1_isr()
{
CCP1Value = CCP_1 - CCP1OldValue;
CCP1OldValue = CCP_1;
CCP1Captured = TRUE;
}
//--------------------------------------------------------------------------
void HWInit(void)
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
//--- Setup de CCP1
setup_ccp1(CCP_CAPTURE_RE);
//--- Timer 1 for CCP1
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
//--- CCP1 Data
CCP1Value = 0;
CCP1OldValue = 0;
CCP1Captured = TRUE;
//--- CCP1 Interrupt
enable_interrupts(INT_CCP1);
//--- Global Interrupt
enable_interrupts(GLOBAL);
}
//--------------------------------------------------------------------------
void main()
{
float Freq;
HWInit();
printf("Frequence test:\r\n");
while (TRUE) {
//--- CCP1 Captured ?
if (CCP1Captured) {
//---
// F = 1/T
// Timer1 prescaler DIV_BY_8
// Pic18F452 at 40Mz -> 0.00000010 * 8
//
Freq = 1.0/((float)CCP1Value*8e-6);
printf("Freq:%f\r\n",Freq);
CCP1Captured = FALSE;
}// End IF
}// End While
}
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