|
|
View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
why I have to connect to CLKO instead of CLKI |
Posted: Fri Feb 18, 2005 11:17 am |
|
|
I use a ECS-100A crystal 4Mhz, I connected it to 16f819 at CLKI pin, the system does not work, when I connected to CLKO pin it works, why? crystal output should go into CLKI right?
here is my testing program
Code: |
#if defined(__PCM__)
#include <16F819.h>
#device *=16
#include <stdio.h>
#include <stdlib.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT
//#device ADC=10
#use delay(clock=4000000)
#use rs232(baud=2400, parity=N, xmit=PIN_A0, rcv=PIN_A1)
int8 length,i, status;
char datar[20],datat[8][10],data;
void main()
{
SET_TRIS_b(0xff);
set_Tris_a(0x00);
SETUP_CCP1(CCP_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
disable_interrupts(INT_EXT);
disABLE_INTERRUPTS(GLOBAL);
status=0;
i=0;
while(1)
{
putc(85);
// delay_ms(100);
// puts("how strange it is!");
}
}
|
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Feb 18, 2005 11:24 am |
|
|
You should be using EC_IO instead of XT
EC stands for External Clock the IO stands for input/output which is what you gain since you are only using 1 pin instead of 2 |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Fri Feb 18, 2005 11:26 am |
|
|
I think for the fuse, I should use HS instead of XT! |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Fri Feb 18, 2005 11:30 am |
|
|
Thank you mark:
I tried both HS and EC_IO, they all doing good. maybe EC_IO is even more stable. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Fri Feb 18, 2005 11:40 am |
|
|
regarding to the code, I have another part of the code to test the signal stability using another chip
here is the code
Code: |
if defined(__PCM__)
#include <16F819.h>
#device *=16
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
//#device ADC=10
#use delay(clock=20000000)
#use rs232(baud=9600, parity=N, xmit=PIN_A0, rcv=PIN_A1)
int8 length,i, status;
char datar[20],datat[8][10],data;
int32 overflow_count;
unsigned int32 start_time, end_time;
unsigned int32 pulse_ticks;
#int_TIMER1
TIMER1_isr()
{
++overflow_count; //increment whenever an overflow occurs;
}
#int_CCP1
CCP1_isr()
{
end_time=CCP_1; //read captured timer ticks
pulse_ticks=(0x10000*overflow_count)-start_time+end_time;
start_time=end_time;
overflow_count=0; //clear overflow counts
}
void main()
{
SET_TRIS_b(0xff);
set_Tris_a(0x00);
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_CCP1(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1); //unmask timer1 overflow interrupt
enable_interrupts(INT_CCP1);
enable_interrupts(global);
status=0;
i=0;
while(1)
{
printf("Frequency reading: %lu\r\n",pulse_ticks);
delay_ms(200);
}
}
|
I keep getting gabarge print out like this,
Quote: |
\0AFrequenãy reading: 4170\0D
\0AFrequency reading: 4160\0D
\0AFrequency reading: 4170\0D
\0AFòequency reading: 4155\0D
\0AFòequency råading: 4170\0D
\0AFrequency reading: 4170\0D
\0AFreque
|
any idea what might be wrong? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Feb 18, 2005 11:41 am |
|
|
Look, if you are using an external clock the then EC_IO. Read the datasheet, it tells you in there. |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Fri Feb 18, 2005 12:04 pm |
|
|
Hi mark:
Thank you: I already tried that it was the same result. |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Fri Feb 18, 2005 5:22 pm |
|
|
Is it a crystal? Then connect it to both pins with capacitors, as shown in the datasheet.
Is it a complete oscillator (i.e. external clock)? Then connect its output to CLKI pin only. |
|
|
Guest
|
|
Posted: Mon Feb 21, 2005 7:23 am |
|
|
http://www.ecsxtal.com/pdf3/ECS_100.pdf said it is a Clock Oscillator
so which catagory it belongs to? I think it belongs to just a oscillator, is it right?
so I just need to connect to CLKI? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Feb 21, 2005 8:05 am |
|
|
It is a clock and goes to the CLKI pin and for the last time you should be using EC_IO! |
|
|
Guest
|
|
Posted: Thu Jul 07, 2005 3:19 pm |
|
|
young wrote: | regarding to the code, I have another part of the code to test the signal stability using another chip
here is the code
Code: |
if defined(__PCM__)
#include <16F819.h>
#device *=16
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
//#device ADC=10
#use delay(clock=20000000)
#use rs232(baud=9600, parity=N, xmit=PIN_A0, rcv=PIN_A1)
int8 length,i, status;
char datar[20],datat[8][10],data;
int32 overflow_count;
unsigned int32 start_time, end_time;
unsigned int32 pulse_ticks;
#int_TIMER1
TIMER1_isr()
{
++overflow_count; //increment whenever an overflow occurs;
}
#int_CCP1
CCP1_isr()
{
end_time=CCP_1; //read captured timer ticks
pulse_ticks=(0x10000*overflow_count)-start_time+end_time;
start_time=end_time;
overflow_count=0; //clear overflow counts
}
void main()
{
SET_TRIS_b(0xff);
set_Tris_a(0x00);
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_CCP1(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1); //unmask timer1 overflow interrupt
enable_interrupts(INT_CCP1);
enable_interrupts(global);
status=0;
i=0;
while(1)
{
printf("Frequency reading: %lu\r\n",pulse_ticks);
delay_ms(200);
}
}
|
I keep getting gabarge print out like this,
Quote: |
\0AFrequenãy reading: 4170\0D
\0AFrequency reading: 4160\0D
\0AFrequency reading: 4170\0D
\0AFòequency reading: 4155\0D
\0AFòequency råading: 4170\0D
\0AFrequency reading: 4170\0D
\0AFreque
|
any idea what might be wrong? |
|
|
|
Guest
|
|
Posted: Thu Jul 07, 2005 3:20 pm |
|
|
young wrote: | regarding to the code, I have another part of the code to test the signal stability using another chip
here is the code
Code: |
if defined(__PCM__)
#include <16F819.h>
#device *=16
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
//#device ADC=10
#use delay(clock=20000000)
#use rs232(baud=9600, parity=N, xmit=PIN_A0, rcv=PIN_A1)
int8 length,i, status;
char datar[20],datat[8][10],data;
int32 overflow_count;
unsigned int32 start_time, end_time;
unsigned int32 pulse_ticks;
#int_TIMER1
TIMER1_isr()
{
++overflow_count; //increment whenever an overflow occurs;
}
#int_CCP1
CCP1_isr()
{
end_time=CCP_1; //read captured timer ticks
pulse_ticks=(0x10000*overflow_count)-start_time+end_time;
start_time=end_time;
overflow_count=0; //clear overflow counts
}
void main()
{
SET_TRIS_b(0xff);
set_Tris_a(0x00);
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_CCP1(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1); //unmask timer1 overflow interrupt
enable_interrupts(INT_CCP1);
enable_interrupts(global);
status=0;
i=0;
while(1)
{
printf("Frequency reading: %lu\r\n",pulse_ticks);
delay_ms(200);
}
}
|
I keep getting gabarge print out like this,
Quote: |
\0AFrequenãy reading: 4170\0D
\0AFrequency reading: 4160\0D
\0AFrequency reading: 4170\0D
\0AFòequency reading: 4155\0D
\0AFòequency råading: 4170\0D
\0AFrequency reading: 4170\0D
\0AFreque
|
any idea what might be wrong? |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 07, 2005 3:34 pm |
|
|
You're using a software UART, which uses software delay loops to
set the length of the transmitted bits. Then, you have interrupt
routines which are interrupting those software delay loops.
The result is the bit times are made longer than normal, which
causes your transmitted data to be corrupted.
You could disable interrupts while you're transmitting RS232 characters
by adding the DISABLE_INTS parameter to your #use rs232() statement.
But this might add too much latency to your CCP interrupt. I don't
know what your input signal is, or what you are measuring.
My suggestion:
Use a PIC that has a hardware UART. Then you eliminate this problem. |
|
|
|
|
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
|