![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Userrr Guest
|
Freq measure |
Posted: Wed Jun 23, 2004 10:11 am |
|
|
HELP me with link to freq meter by CCS. (with comments) |
|
![](templates/subSilver/images/spacer.gif) |
dvsoft
Joined: 28 Nov 2003 Posts: 46
|
|
Posted: Wed Jun 23, 2004 1:11 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Userrr Guest
|
Thanks |
Posted: Thu Jun 24, 2004 9:19 am |
|
|
Thanks dvsoft |
|
![](templates/subSilver/images/spacer.gif) |
Userrr Guest
|
max frequency |
Posted: Tue Jun 29, 2004 10:06 am |
|
|
tell me max frequency for using CCP and 40Mhz ?
How me measure 50Mhz using timer? |
|
![](templates/subSilver/images/spacer.gif) |
Simon Martineau
Joined: 28 Jun 2004 Posts: 10 Location: Montreal
|
|
Posted: Tue Jun 29, 2004 12:25 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
frequency counter |
Posted: Tue Jun 29, 2004 12:32 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Userrr Guest
|
But |
Posted: Tue Jun 29, 2004 2:25 pm |
|
|
But were I can found CCS example |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
Freq Counter |
Posted: Tue Jun 29, 2004 3:34 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
testing Guest
|
|
Posted: Wed Aug 18, 2004 12:43 pm |
|
|
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
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|