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

Can�t get 20MHz crystal to work!!!

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



Joined: 04 May 2006
Posts: 17
Location: Sweden

View user's profile Send private message

Can�t get 20MHz crystal to work!!!
PostPosted: Mon May 29, 2006 9:34 am     Reply with quote

Hi there!

I trying to connect a 20 MHz crystal (http://www.elfa.se/elfa-bin/dyndok.pl?lang=se&vat=0&dok=2013473.htm) to a PIC16F877A-processor, but I can�t get it to start. Both the processor and the crystal are stone-dead. Each pin of the crystal is connected to ground via a 22pF-cap and to pin 13 & 14 of the PIC. I�ve also tried changing to 33pF-caps, but it doesn�t help...

What could be wrong? Crying or Very sad

Cheers!
/David
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

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

PostPosted: Mon May 29, 2006 10:17 am     Reply with quote

1) Are you certain you have a parallel resonant crystal? The page you reference shows you can order either a parallel or series crystal.

2) Are you using the HS fuse?

3) You don't describe your construction method. Breadboard (white, push in wire kind)? Point-to-pont? PCB? etc.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 29, 2006 10:23 am     Reply with quote

I have some questions:
1) Are you sure that the PIC you are using is capable to run at 20Mhz ?
2) What about the Reset pin voltage ?
3) What about the Configuration Fuses ?
4) Can you change one of them ? (PIC or crystal)


Humberto
Ttelmah
Guest







PostPosted: Mon May 29, 2006 10:30 am     Reply with quote

You don't say whether you have the first crystal or the second. Both should oscillate, but the first is the one designed to run in the normal PIC oscillator configuration.
Obvious first thing, have you got HS mode selected in the fuses?. If not there will probably not be enought drive to run the crystal.
Second thing is to look at the other connections round the chip. For example, the oscillator will not start, if MCLR is not held high.
Third thing is, have you tried more than one chip/crystal. Anything can be faulty.

Best Wishes
davey



Joined: 04 May 2006
Posts: 17
Location: Sweden

View user's profile Send private message

...
PostPosted: Mon May 29, 2006 10:34 am     Reply with quote

Yes I have a parallel resonant crystal.
I tried setting the HS-fuse but it doesn�t help.
All components are placed on a contact-deck and connected to each other with cables.
The PIC is capable of running a 20MHz.
The reset-pin is connected to 5V - ok
I can change the fuses. Here�s my current pre-processor commands:

Code:

#fuses NOWDT
#use delay(clock=20000000)


Any other suggestions...please? Crying or Very sad

/David
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 29, 2006 10:39 am     Reply with quote

Quote:

Any other suggestions...please?


#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT

Humberto
davey



Joined: 04 May 2006
Posts: 17
Location: Sweden

View user's profile Send private message

...ok, but I�ve already tried setting the HS-fuse...
PostPosted: Mon May 29, 2006 11:02 am     Reply with quote

...and it doesn�t make any difference.
Please continue to share your thoughts!

Cheers!
/David
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 29, 2006 11:52 am     Reply with quote

So that this does not seem a game of successes and errors, please post:

1) The complete code you are using to test.
2) A complete hardware description.
3) Compiler version.


Humberto
davey



Joined: 04 May 2006
Posts: 17
Location: Sweden

View user's profile Send private message

ok...here it goes...
PostPosted: Mon May 29, 2006 12:35 pm     Reply with quote

HARDWARE:
Nothing special, just a PIC16F877A with four (five with reset) user-buttons attached to B0,B1,B2 & B4. I also have an i2c-connection with another PIC...but that shouldn�t have anything to do with my problem.
Earlier, I�ve connected the osc-inputs on my PIC to the oscillator on a development-board (microEngineering Labs - LAB-X1). And that works perfectly. That oscillator is connected to a multiplier and is sort of running by itself, so that�s a bit different I guess...

CODE:

Code:
#include <puls.H>
#include <math.h>
#fuses HS,NOWDT
#use i2c(slave,sda=PIN_C4,scl=PIN_C3,address=0x6C,force_hw)


int16 freq=20;    //aktuell frekvens f�r denna slav
int16 freq_tmp=20;


byte tmp3;     //anv av timer1_isr()
byte received; //mottagen byte via i2c

typedef enum {FIRST_READ, LAST_READ} I2C_STATE;
I2C_STATE i2c_status=FIRST_READ; //anv f�r att skilja p� mottagen adress/data

//Timer 1
int16 t1sv=3160; //Start-v�rde (65535-3160=62375) f�r Timer1 (ger 20Hz)
int16 t1svmod;
int16 temp;


//(((((((((((((((((((((((( INTERRUPTS ))))))))))))))))))))))))))))

#int_timer1    //KANAL 1
timer1_isr()
{
   tmp3=TIMER1_CTRL;
   TIMER1_CTRL=0x00;
   t1svmod=t1sv;
   TIMER_1_LOW=t1svmod&0x00FF; //laddar med den f�rsta byten av t1sv
   t1svmod >>= 8; //shiftar 8 bitar till h�ger
   TIMER_1_HIGH=t1svmod&0x00FF;//laddar med den andra byten av t1sv
   port_c ^= 1;   //0->1 el. 1->0
   TIMER1_CTRL=tmp3;
}

#int_ssp
receive_isr()
{
   //ladda freq med mottaget v�rde
   if(i2c_poll())
   {
      if(!bit_test(i2c_stat,5))
      {
         //ta hand om adress-byte
         received=i2c_read();
      }
      else if(i2c_status==FIRST_READ && bit_test(i2c_stat,5))
      {
         //ta hand om f�rsta data-byten
         received=i2c_read();
         freq_tmp=received;
         i2c_status=LAST_READ;
      }
      else if(i2c_status==LAST_READ && bit_test(i2c_stat,5))
      {
         //ta hand om andra data-byten, sl� samman med f�rsta f�r �nskad freq
         received=i2c_read();
         freq_tmp=(freq_tmp<<8)&0xFF00;
         freq_tmp=freq_tmp+received;
         i2c_status=FIRST_READ;

         //r�kna ut start-v�rde f�r timer1
         freq=freq_tmp;
         if(freq>40) TIMER1_CTRL=0x01;
         else TIMER1_CTRL=0x11;
         temp=2*freq;
         if(TIMER1_CTRL==0x11) temp=2495000/temp;
         else temp=4990000/temp;
         t1sv=65535-temp;
      }
   }
}


//������������������������������������������������������������������������������
//������������������������������������ MAIN ������������������������������������
//������������������������������������������������������������������������������

main()
{
   setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
   setup_port_a(NO_ANALOGS);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);

//====================== I/O ============================

   set_tris_d(0x00);  // PORT-D: alla utg�ngar
   set_tris_c(0xFE);  // PORT-C: alla ing�ngar, utom C0(puls-ut)

//=======================================================

//================== SETUP - Timer1 =====================

   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   TIMER1_CTRL=0x11;

//=======================================================

//========================I2C============================
   enable_interrupts(INT_SSP);   //s�tter ig�ng i2c-avbrott
//=======================================================

   while(1)
   {
      if(bit_test(i2c_ctrl2,6))  //nollst�lla SSPOV-biten (overflow)
      {
         bit_clear(i2c_ctrl2,6);
         i2c_read();
      }
   }
}
//������������������������������������������������������������������������������


H-file

Code:
#device PIC16F877
#use delay(clock=20000000)

#nolist
/////////////////////////////// I/O definitions for INPUT() and OUTPUT_xxx()
#define PIN_A0  40
#define PIN_A1  41
#define PIN_A2  42
#define PIN_A3  43
#define PIN_A4  44
#define PIN_A5  45
#use fixed_io(A_OUTPUTS=)
#byte port_A=5

#define PIN_B0  48
#define PIN_B1  49
#define PIN_B2  50
#define PIN_B3  51
#define PIN_B4  52
#define PIN_B5  53
#define PIN_B6  54
#define PIN_B7  55
#use fixed_io(B_OUTPUTS=)
#byte port_B=6

#define PIN_C0  56
#define PIN_C1  57
#define PIN_C2  58
#define PIN_C3  59
#define PIN_C4  60
#define PIN_C5  61
#define PIN_C6  62
#define PIN_C7  63
#use fixed_io(C_OUTPUTS=PIN_C6)
#byte port_C=7

#define PIN_D0  64
#define PIN_D1  65
#define PIN_D2  66
#define PIN_D3  67
#define PIN_D4  68
#define PIN_D5  69
#define PIN_D6  70
#define PIN_D7  71
#use fixed_io(D_OUTPUTS=)
#byte port_D=8

#define PIN_E0  72
#define PIN_E1  73
#define PIN_E2  74
#use fixed_io(E_OUTPUTS=)
#byte port_E=9

/////////////////////////////// Useful defines
#define FALSE 0
#define TRUE 1

#define BYTE int
#define BOOLEAN short int

#define getc getch
#define getchar getch
#define puts(s) {printf(s); putchar(13); putchar(10);}
#define putc putchar

/////////////////////////////// Constants used for RESTART_CAUSE()
#define WDT_FROM_SLEEP  0
#define WDT_TIMEOUT     8
#define MCLR_FROM_SLEEP 16
#define NORMAL_POWER_UP 24
/////////////////////////////// Constants used for SETUP_COUNTERS()
#define RTCC_INTERNAL   0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48
#define RTCC_DIV_2      0
#define RTCC_DIV_4      1
#define RTCC_DIV_8      2
#define RTCC_DIV_16     3
#define RTCC_DIV_32     4
#define RTCC_DIV_64     5
#define RTCC_DIV_128    6
#define RTCC_DIV_256    7
#define WDT_18MS        8
#define WDT_36MS        9
#define WDT_72MS       10
#define WDT_144MS      11
#define WDT_288MS      12
#define WDT_576MS      13
#define WDT_1152MS     14
#define WDT_2304MS     15
#define L_TO_H              0x40
#define H_TO_L                 0

#define RTCC_ZERO           0x0B20    // Used for ENABLE/DISABLE INTERRUPTS
#define RB_CHANGE           0x0B08    // Used for ENABLE/DISABLE INTERRUPTS
#define EXT_INT             0x0B10    // Used for ENABLE/DISABLE INTERRUPTS

#define GLOBAL              0x0BC0    // Used for ENABLE/DISABLE INTERRUPTS
///////////////////////////////////// Constants used for Timer1 and Timer2
#define T1_DISABLED         0
#define T1_INTERNAL         5
#define T1_EXTERNAL         7
#define T1_EXTERNAL_SYNC    3
#define T1_CLK_OUT          8
#define T1_DIV_BY_1         0
#define T1_DIV_BY_2         0x10
#define T1_DIV_BY_4         0x20
#define T1_DIV_BY_8         0x30
#byte   TIMER_1_LOW=        0x0e
#byte   TIMER_1_HIGH=       0x0f
#byte   TIMER1_CTRL=        0x10
#define T2_DISABLED         0
#define T2_DIV_BY_1         4
#define T2_DIV_BY_4         5
#define T2_DIV_BY_16        6
#byte   TIMER_2=            0x11
#byte   TIMER2_CTRL=        0x12
#byte   TIMER2_PERIOD=      0x92
#byte   TIMER0_OPT=         0x81
#byte   TIMER0_CTRL=        0x8B
#byte   TIMER_0=            0x01


#define INT_TIMER1          0x8C01    // Used for ENABLE/DISABLE INTERRUPTS
#define INT_TIMER2          0x8C02    // Used for ENABLE/DISABLE INTERRUPTS
#define INT_TIMER0          0x8B20    // Used for ENABLE/DISABLE INTERRUPTS

//////////////////////////////////// Constants used for SETUP_CCP1()
#define CCP_OFF                         0
#define CCP_CAPTURE_FE                  4
#define CCP_CAPTURE_RE                  5
#define CCP_CAPTURE_DIV_4               6
#define CCP_CAPTURE_DIV_16              7
#define CCP_COMPARE_SET_ON_MATCH        8
#define CCP_COMPARE_CLR_ON_MATCH        9
#define CCP_COMPARE_INT                 0xA
#define CCP_COMPARE_RESET_TIMER         0xB
#define CCP_PWM                         0xC
#define CCP_PWM_PLUS_1                  0x1c
#define CCP_PWM_PLUS_2                  0x2c
#define CCP_PWM_PLUS_3                  0x3c
#byte   CCP_1_LOW=                      0x15
#byte   CCP_1_HIGH=                     0x16
#byte   CCP_1_CTRL=                     0x17
#define INT_CCP1            0x8C04    // Used for ENABLE/DISABLE INTERRUPTS

//////////////////////////////////// Constants used for SETUP_CCP2()
#byte   CCP_2_LOW=                      0x1B
#byte   CCP_2_HIGH=                     0x1C
#define INT_CCP2            0x8D01    // Used for ENABLE/DISABLE INTERRUPTS

//////////////////////////////////// Constants used for SETUP_PSP()
#define PSP_ENABLED                     0x10
#define PSP_DISABLED                    0
#byte   PSP_DATA=                       8
#define INT_PSP             0x8C80    // Used for ENABLE/DISABLE INTERRUPTS

//////////////////////////////////// Constants used in SETUP_SSP()
#define SPI_MASTER       0x20
#define SPI_SLAVE        0x24
#define SPI_L_TO_H       0
#define SPI_H_TO_L       0x10
#define SPI_CLK_DIV_4    0
#define SPI_CLK_DIV_16   1
#define SPI_CLK_DIV_64   2
#define SPI_CLK_T2       3
#define SPI_SS_DISABLED  1
#define INT_SSP             0x8C08    // Used for ENABLE/DISABLE INTERRUPTS

#byte i2c_buff=   0x13
#byte i2c_stat=   0x94
#byte i2c_ctrl=   0x0C
#byte i2c_ctrl2=  0x14

#define INT_RDA             0x8C20    // Used for ENABLE/DISABLE INTERRUPTS
#define INT_TBE             0x8C10    // Used for ENABLE/DISABLE INTERRUPTS

///////////////////////////////////// Constants used for SETUP_ADC()
#define ALL_ANALOG             0
#define ANALOG_RA3_REF         1
#define A_ANALOG               2
#define A_ANALOG_RA3_REF       3
#define RA0_RA1_RA3_ANALOG     4
#define RA0_RA1_ANALOG_RA3_REF 5
#define NO_ANALOGS             6
#define ADC_OFF                0
#define ADC_CLOCK_DIV_2        1
#define ADC_CLOCK_DIV_8     0x41
#define ADC_CLOCK_DIV_32    0x81
#define ADC_CLOCK_INTERNAL  0xc1

#define ADC_DONE            0x8C40    // Used for ENABLE/DISABLE INTERRUPTS
////////////////////////////////////////////////////////////////////////////
#byte   CONFIG=                0x2007
#list


COMPILER-VERSION: IDE 3.43/PCB-PCM-PCH 3.203
Ttelmah
Guest







PostPosted: Mon May 29, 2006 2:09 pm     Reply with quote

Realistically, the most likely thing now, is a faulty crystal. It is suprisingly easy to damage a crystal when soldering, and the only real way to prove this, would be to either put it into a known working oscillator circuit, or use a scope to inspect how it behaves with a signal applied.

Best Wishes
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon May 29, 2006 3:59 pm     Reply with quote

The earlier 3.20x compiler versions was quite buggy. The stable version on those days
was 3.190/91. If you can�t get it, you should try to update it.

http://www.ccsinfo.com/forum/viewtopic.php?t=23792&highlight=203
http://www.ccsinfo.com/forum/viewtopic.php?t=19380&highlight=203


When everything is wrong, the most suitable and recommendable solution is to reduce everything
(hardware and software) to its minimum expression.

Code:

#include <18F877A.h>
#use delay(clock=20000000)
#FUSES HS,NOWDT,NOPROTECT,NOLVP,NOPUT, NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

void main()
{
 while(1)
       {
         output_low(PIN_B2);
         delay_ms(500);
         output_high(PIN_B2);
         delay_ms(500);
       }
}


Compile and post your lst file.


Humberto
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 29, 2006 4:05 pm     Reply with quote

Your program is too complicated to test the crystal problem.
Test it with a very simple program, as shown below. It looks
like you have a spare pin on Pin B5, so I've made the program
toggle that pin. Use this program exactly as shown. Don't
edit the fuses.

Humberto gave you a very good clue when he showed the NOLVP fuse.
You did a test, but you edited out the NOLVP fuse and only tested the
HS fuse. NOLVP is essential for reliable operation with the 16F877A.
Code:

#include <16F877A.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)

//===================================
void main()
{

while(1)
  {
   output_high(PIN_B5);
   delay_ms(500);
   output_low(PIN_B5);
   delay_ms(500);
  }

}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 29, 2006 4:14 pm     Reply with quote

You are including the header file of the 16F877 instead of the 16F877A.

What values have the capacitors on your clock crystal? The crystal you mentioned has a capacitance of 30pF and requires 2 x 56pF capacitors ( capacitors in parallel = 56x56/(56+56) = 31pF)

Code:
#fuses HS,NOWDT
99% of the people on this forum need to set the NOLVP fuse as well or the processor will stall when this pin is floating to an active level.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 29, 2006 4:55 pm     Reply with quote

I don't know if he gave a part number for the crystal, but a typical
20 MHz crystal in an HC-49/US package will be specified to have a
a load capacitance of 18 or 20 pf. See this chart from Digikey:
http://www.digikey.com/scripts/DkSearch/dksus.dll?Detail?Ref=163185&Row=682118&Site=US

Here's an appnote on parallel oscillator circuits.
http://www.icst.com/appnotes/note14.PDF
They have a chart on page 2, where they show the load capacitor values,
based upon the specified crystal load capacitance. This appnote takes
into account the internal stray capacitance of the chip's oscillator
circuit, which is something I haven't seen in other appnotes. So for a
crystal spec'ed with an 18 pf load, they recommend external caps of
25 pf. The commonly available values of 22 or 27 pf would work.
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