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

PIC16f1789 Crystal Mode
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hunter07



Joined: 28 Dec 2005
Posts: 12

View user's profile Send private message

PIC16f1789 Crystal Mode
PostPosted: Sun Sep 24, 2017 12:26 pm     Reply with quote

I could not get the proper result from PIC16F1789 using crystal.

Its ok with internal oscillator but when I put in Crystal (10Mhz is used) mode with simple
Code:

//Example blinking LED program
output_low(LED);
delay_ms(1000);
output_high(LED);
delay_ms(1000);

But it takes too long 14 seconds may be so, instead of 1 second. (in real circuit not proteus).

My oscillator setup is in the following;
Code:

#include <16F1789.h>
#device ADC = 12  // ADC returns 12 bit result 
#FUSES NOMCLR                   // No Master Clear (Pin assigned to IO).
#FUSES HS                       //High speed Osc (> 4Mhz for PCM/PCH) (>10Mhz for PCD)
//#FUSES PLL_SW
#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES NOFCMEN                  //Fail safe clock monitor disabled
#use delay(crystal=10MHz)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,errors)

#define LED PIN_b3


Could you please show me the correct crystal setup for the F1789
Thank you.

Hunter
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Sun Sep 24, 2017 1:01 pm     Reply with quote

Currently you are enabling the PLL (it is enabled by default unless you have the PLL_SW option selected). If you have a 10MHz crystal attached you will be trying to run at 40MHz, 8MHz faster than the chip supports.
What crystal have you got?.
Which pins have you attached it to?.
What load capacitors are you using?.
hunter07



Joined: 28 Dec 2005
Posts: 12

View user's profile Send private message

PostPosted: Sun Sep 24, 2017 2:14 pm     Reply with quote

Ttelmah wrote:
Currently you are enabling the PLL (it is enabled by default unless you have the PLL_SW option selected). If you have a 10MHz crystal attached you will be trying to run at 40MHz, 8MHz faster than the chip supports.
What crystal have you got?.
Which pins have you attached it to?.
What load capacitors are you using?.


Crystal: https://www.digikey.com/product-detail/en/ndk-america-inc/NX8045GB-12.000000MHZ/644-1020-1-ND/1128892

The crystal is connected to PinA6 and PinA7 of the controller.
Two 22pf are attached to the crystal pins and the ground.

Thank you.
hunter07



Joined: 28 Dec 2005
Posts: 12

View user's profile Send private message

PostPosted: Sun Sep 24, 2017 2:36 pm     Reply with quote

Sir,
How about the following setup?

Code:

#include <16F1789.h>
#device ADC=12

#FUSES NOWDT                      //Watch Dog Timer
#FUSES PUT                      //Power Up Timer
#FUSES NOMCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection
#FUSES NOBROWNOUT                 //Reset when brownout detected
#FUSES ECH                  //external clock

#FUSES HS                  //crystal oscillator   
#FUSES PLL
#FUSES NOCLKOUT                 //I/O function on OSC2for internal oscillator & external clock
#FUSES NOIESO                     //Internal External Switch Over mode disabled
#FUSES NOFCMEN                    //Fail-safe clock monitor disabled
#FUSES NOWRT                    //Program memory not write protected
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=10M)         //external clock or crystal oscillator

Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Sun Sep 24, 2017 2:54 pm     Reply with quote

Code:


#include <16F1789.h>
#device ADC = 12  // ADC returns 12 bit result
#FUSES NOMCLR   // No Master Clear (Pin assigned to IO).
#FUSES HS           //High speed Osc (> 4Mhz for PCM/PCH) (>10Mhz for PCD)
#FUSES PLL_SW    //This disables the PLL
#FUSES NOWDT    //No Watch Dog Timer
#FUSES NOCLKOUT //Ensure no FOSC/4 output
#FUSES PUT         //Generally the PUT should always be enabled for a crystal
#FUSES NOFCMEN //Fail safe clock monitor disabled
#FUSES NOLVP

#use delay(clock=10MHz, crystal=10MHz) //Belt and braces

#define LED PIN_A0

void main(void)
{
   while (TRUE)//Example blinking LED program
   {
      output_low(LED);
      delay_ms(1000);
      output_high(LED);
      delay_ms(1000);
   }
}


On your new one you are both forcing the PLL 'on', and saying you have an external oscillator not a crystal.

On these chips the PLL defaults to 'on'. There is no 'NO_PLL' option. Instead you have to select PLL_SW, and then just don't turn it on.
hunter07



Joined: 28 Dec 2005
Posts: 12

View user's profile Send private message

PostPosted: Mon Sep 25, 2017 3:26 am     Reply with quote

Thank you Ttelmah,

I 've just tried your example but,

For the Led
~20secs ON then
~20secs OFF
Continuously
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Mon Sep 25, 2017 4:05 am     Reply with quote

Do you have a scope?.

If so, enable the OSCOUT, and monitor the output on this.

Implies the chip is running off 500KHz, which is the default boot. It won't switch to the crystal if the crystal is not seen as running (this is different from FSCM, which will switch 'back' to the fall back oscillator if in fails when running).

It is behaving as if you have something stopping the crystal from oscillating. Triple check your connections.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 25, 2017 5:34 am     Reply with quote

Mr T is probably right, again ! Sounds like the xtal is not working. Could be a solder 'whisker' shorting one of the pins. easy to do, HARD to see.

If you don't have a scope, or easy access to one then save up your coins and buy one. even a 30 year old,20MHz, 2 channel analog scope ill be a tremendous asset in your hobby. Being able to SEE the signals will cut down your 'hardware debuggin' and almost eliminate your frustration of 'why doesn't it work,now' !!
Check flea markets, 2nd hand shops,hamfests, etc. You can probably get a scopt for less than $100.

Really it's a 'must have' tool.

Jay
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Mon Sep 25, 2017 6:59 am     Reply with quote

You keep stating 10MHz crystal but the part you link to is 12MHz.
The load capacitance on the part you linked to is 8pf so the two 22pf caps are going to be too large for that crystal.

Which is correct, what you are writing or the part linked to?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Sep 25, 2017 7:12 am     Reply with quote

gaugeguy wrote:
You keep stating 10MHz crystal but the part you link to is 12MHz.
The load capacitance on the part you linked to is 8pf so the two 22pf caps are going to be too large for that crystal.

Which is correct, what you are writing or the part linked to?


If he's using an 8pF crystal, 22pF caps will likely prevent oscillation. In fact, the proper cap is ~8pF...depending on the circuit (professionally done board vs some type of prototyping arrangement), there could be enough parasitic capacitance to allow the circuit to work without crystal caps. If the board is professionally done but a "rookie" mistake was made by pouring the ground plane in amongst the crystal traces, adding any additional capacitance would definitely prevent oscillation. Been there, done that.

Try removing the crystal caps entirely to see if the processor starts running at the proper frequency.
hunter07



Joined: 28 Dec 2005
Posts: 12

View user's profile Send private message

PostPosted: Mon Sep 25, 2017 2:20 pm     Reply with quote

I don't have an oscilloscope but I will try to get one.
I sent the link to inform you about the type of the crystal. Mine is 10Mhz.

Actually, I've used this crystal with 22pf in 16fF883 based circuit, without a problem. And I assumed that it will be ok with F1789.

You pointed me to the hardware side and I think you were right. I will try the crystal with 8pf as soon as possible and let you know.

Thank you very much for your support.
Hunter
hunter07



Joined: 28 Dec 2005
Posts: 12

View user's profile Send private message

PostPosted: Tue Sep 26, 2017 2:23 am     Reply with quote

Code:

CCS PCM C Compiler, Version 5.061, 41304               27-Eyl-17 21:03

               Filename:   x_pic16f1789.lst

               ROM used:   61 words (0%)
                           Largest free fragment is 2048
               RAM used:   6 (0%) at main() level
                           18 (1%) worst case
               Stack used: 0 locations
               Stack size: 16

*
0000:  MOVLP  00
0001:  GOTO   019
0002:  NOP
.................... #include <16F1789.h> 
.................... //////////// Standard Header file for the PIC16F1789 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... ////        (C) Copyright 1996, 2014 Custom Computer Services          ////
.................... //// This source code may only be used by licensed users of the CCS C  ////
.................... //// compiler.  This source code may only be distributed to other      ////
.................... //// licensed users of the CCS C compiler.  No other use, reproduction ////
.................... //// or distribution is permitted without written permission.          ////
.................... //// Derivative programs created using this software in object code    ////
.................... //// form are not restricted in any way.                               ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC16F1789
.................... 
.................... #list
.................... 
.................... #device ADC = 12  // ADC returns 12 bit result 
.................... #FUSES NOMCLR   // No Master Clear (Pin assigned to IO). 
.................... #FUSES HS           //High speed Osc (> 4Mhz for PCM/PCH) (>10Mhz for PCD) 
.................... #FUSES PLL_SW    //This disables the PLL 
.................... #FUSES NOWDT    //No Watch Dog Timer 
.................... #FUSES NOCLKOUT //Ensure no FOSC/4 output 
.................... #FUSES PUT         //Generally the PUT should always be enabled for a crystal 
.................... #FUSES NOFCMEN //Fail safe clock monitor disabled 
.................... #FUSES NOLVP 
.................... 
.................... #use delay(clock=10MHz, crystal=10MHz) //Belt and braces 
0003:  MOVLW  20
0004:  MOVWF  05
0005:  MOVLW  02
0006:  MOVWF  04
0007:  MOVF   00,W
0008:  BTFSC  03.2
0009:  GOTO   018
000A:  MOVLW  03
000B:  MOVWF  78
000C:  CLRF   77
000D:  DECFSZ 77,F
000E:  GOTO   00D
000F:  DECFSZ 78,F
0010:  GOTO   00C
0011:  MOVLW  3C
0012:  MOVWF  77
0013:  DECFSZ 77,F
0014:  GOTO   013
0015:  GOTO   016
0016:  DECFSZ 00,F
0017:  GOTO   00A
0018:  RETURN
.................... 
.................... #define LED PIN_a0 
.................... 
.................... void main(void) 
0019:  MOVLB  03
001A:  CLRF   0C
001B:  CLRF   0D
001C:  CLRF   0E
001D:  CLRF   0F
001E:  CLRF   10
001F:  MOVLB  02
0020:  CLRF   12
0021:  CLRF   11
.................... { 
....................    while (TRUE)//Example blinking LED program 
....................    { 
....................       output_low(LED); 
0022:  MOVLB  01
0023:  BCF    0C.0
0024:  MOVLB  02
0025:  BCF    0C.0
....................       delay_ms(1000); 
0026:  MOVLW  04
0027:  MOVLB  00
0028:  MOVWF  21
0029:  MOVLW  FA
002A:  MOVWF  22
002B:  CALL   003
002C:  DECFSZ 21,F
002D:  GOTO   029
....................       output_high(LED); 
002E:  MOVLB  01
002F:  BCF    0C.0
0030:  MOVLB  02
0031:  BSF    0C.0
....................       delay_ms(1000); 
0032:  MOVLW  04
0033:  MOVLB  00
0034:  MOVWF  21
0035:  MOVLW  FA
0036:  MOVWF  22
0037:  CALL   003
0038:  DECFSZ 21,F
0039:  GOTO   035
003A:  MOVLB  02
003B:  GOTO   022
....................    } 
.................... } 
.................... 
003C:  SLEEP
.................... 
.................... 
.................... /*
.................... 
.................... #include <16F1789.h>
....................   
.................... #device ADC = 10  // ADC returns 12 bit result
.................... #FUSES NOMCLR   // No Master Clear (Pin assigned to IO). 
.................... #FUSES HS           //High speed Osc (> 4Mhz for PCM/PCH) (>10Mhz for PCD) 
.................... #FUSES PLL_SW    //This disables the PLL 
.................... #FUSES NOWDT    //No Watch Dog Timer 
.................... #FUSES NOCLKOUT //Ensure no FOSC/4 output 
.................... #FUSES PUT         //Generally the PUT should always be enabled for a crystal 
.................... #FUSES NOFCMEN //Fail safe clock monitor disabled 
.................... #FUSES NOLVP 
.................... #use delay(clock=10000000) 
.................... 
.................... #Fuses HS,NOWDT,NOPROTECT,NOLVP 
.................... //#use delay(clock=10000000) 
.................... 
.................... //#use delay(clock=10MHz, crystal=10MHz) //Belt and braces 
.................... //#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,errors)
.................... 
.................... #define LED PIN_C7 
.................... 
.................... void main(void) 
.................... { 
.................... 
....................    while (TRUE)//Example blinking LED program 
....................    { 
....................       output_low(LED); 
....................       delay_ms(1000); 
....................       output_high(LED); 
....................       delay_ms(1000); 
....................    } 
.................... }
.................... 
.................... */

Configuration Fuses:
   Word  1: 1F82   HS NOWDT PUT NOMCLR NOPROTECT NOCPD BROWNOUT NOCLKOUT IESO NOFCMEN
   Word  2: 1EFF   NOWRT NOVCAP PLL_SW STVREN BORV19 NOLPBOR NODEBUG NOLVP


Last edited by hunter07 on Wed Sep 27, 2017 12:07 pm; edited 4 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Tue Sep 26, 2017 3:36 am     Reply with quote

You leave out the two bits that matter:
The top lines that show what compiler version you are using, and the bottom lines that show what fuses are actually being generated.
hunter07



Joined: 28 Dec 2005
Posts: 12

View user's profile Send private message

PostPosted: Tue Sep 26, 2017 5:20 am     Reply with quote

Done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Tue Sep 26, 2017 8:55 am     Reply with quote

Compile the code as I posted it. Just change A0 to C7 for your LED.

You have added and duplicated several fuses, and removed a couple of critical lines. If you look at what your code generates for fuses:
Code:

Configuration Fuses:
   Word  1: 3FC2   HS NOWDT PUT MCLR NOPROTECT NOCPD BROWNOUT NOCLKOUT IESO FCMEN
   Word  2: 1FFF   NOWRT NOVCAP PLL STVREN BORV19 NOLPBOR NODEBUG NOLVP


Versus what I posted (with your compiler):
Code:

Configuration Fuses:
   Word  1: 1F82   HS NOWDT PUT NOMCLR NOPROTECT NOCPD BROWNOUT NOCLKOUT IESO NOFCMEN
   Word  2: 1EFF   NOWRT NOVCAP PLL_SW STVREN BORV19 NOLPBOR NODEBUG NOLVP


You have turned the PLL back on. This will almost certainly prevent the clock from starting, since the internal start-up circuit tests that it is seeing a reasonable clock output before changing away from the internal oscillator. With the PLL enabled, this will not be the case...

I have deliberately set this code up so it will not start if the crystal is not running. You have also removed this.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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