0
\$\begingroup\$

Using pic16f690 with xc8, I can't figure out how to set external osc with quartz crystal.

I have set :

#define FOSC_XT

Is that enough? Because I don't think it actually does something, I took out the xtal and the circuit still performs.

My configs:

#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown-out Reset Selection bits (BOR enabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)

 #define FOSC_XT

EDIT: Tried:

config FOSC = HS  //8MHZ
config FOSC = XT  

Same results-when taking out the xtal the circuit runs as usual, or even starts without it. (At the speed of internal osc of 8mhz.)

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

This is not correct. You need to be setting the FOSC configuration bit as shown in REGISTER 14-1, page 174 of this datasheet.

You do not mention your crystal speed but this will make a difference, you might need HS, XT or LP. The FOSC configuration bit can be set by specifying the correct value like below:

#pragma config FOSC = XT // use external crystal/resonator

\$\endgroup\$
6
  • \$\begingroup\$ I actually did that after my post, exactly that line, and i can see that when i remove the xtal, the circuit still perform right, so i guess it didnt work .... \$\endgroup\$
    – Curnelious
    Commented Oct 11, 2013 at 10:59
  • \$\begingroup\$ I am using 8mhz \$\endgroup\$
    – Curnelious
    Commented Oct 11, 2013 at 10:59
  • \$\begingroup\$ i have also tried with HS mode , config FOSC = HS and got the same result, so circuit runs without the xtal.. \$\endgroup\$
    – Curnelious
    Commented Oct 11, 2013 at 11:02
  • \$\begingroup\$ (talking about the timers-they runs in the same speed as when i used the internal osc) \$\endgroup\$
    – Curnelious
    Commented Oct 11, 2013 at 11:07
  • \$\begingroup\$ You'll need to confirm that (1) the configuration #pragmas are correctly generated in the .hex file (2) your programmer is using them properly (and not using defaults) and (3) perhaps show us a diagram of how you have it hooked up. \$\endgroup\$
    – David
    Commented Oct 11, 2013 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.