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

why I have to connect to CLKO instead of CLKI

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



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

why I have to connect to CLKO instead of CLKI
PostPosted: Fri Feb 18, 2005 11:17 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 18, 2005 11:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 11:26 am     Reply with quote

I think for the fuse, I should use HS instead of XT!
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 11:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 11:40 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 18, 2005 11:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 12:04 pm     Reply with quote

Hi mark:

Thank you: I already tried that it was the same result.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Fri Feb 18, 2005 5:22 pm     Reply with quote

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








PostPosted: Mon Feb 21, 2005 7:23 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 21, 2005 8:05 am     Reply with quote

It is a clock and goes to the CLKI pin and for the last time you should be using EC_IO!
Guest








PostPosted: Thu Jul 07, 2005 3:19 pm     Reply with quote

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








PostPosted: Thu Jul 07, 2005 3:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 07, 2005 3:34 pm     Reply with quote

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.
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