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

Cant get right oscillator

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Cant get right oscillator
PostPosted: Thu Mar 13, 2014 5:39 pm     Reply with quote

HI all,

I cant get this to run at 20MHz with the external crystal.

I see on my scope that the crystal is oscillating but the pic is not running,

I can get it to run with the internal osc at 8MHZ but not the crystal.

Code:
#include <16f1825.h>
#DEVICE adc=10
#DEVICE *=16
#DEVICE PASS_STRINGS=IN_RAM
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NODEBUG,MCLR
#use delay(clock=20mhz)
#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5, ERRORS)


void main()
{

   //SETUP_OSCILLATOR(OSC_8MHZ);
   ENABLE_INTERRUPTS(GLOBAL);               // Enable Interrupts
   ENABLE_INTERRUPTS(INT_RDA);               // Enable Serial Interrupts   

   setup_comparator(NC_NC_NC_NC);
   setup_adc_ports(sAN2|sAN4|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_16 );
   SETUP_TIMER_1(T1_DISABLED);

   while(1)
   {
      delay_ms(500);
      output_toggle(PIN_C2);
   }
}



Thanks

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 13, 2014 5:57 pm     Reply with quote

I compiled this for vs. 5.021. But anyway, look at the fuses at the end
of the .LST file. Look for anything weird or unintended:
Quote:
Configuration Fuses:
Word 1: 39C2 HS NOWDT PUT MCLR NOPROTECT NOCPD NOBROWNOUT NOCLKOUT IESO FCMEN
Word 2: 1FFF NOWRT PLL STVREN BORV19 NODEBUG NOLVP
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu Mar 13, 2014 11:29 pm     Reply with quote

you are right as usual.

Thanks!

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Fri Mar 14, 2014 1:47 am     Reply with quote

The key is that 'fuses' in general all set to '1', unless you change them.

On most older chips, the oscillator fuses had 'HS', or 'HS with PLL' setting, with the former turning the PLL off, so 'HS' also implied that the PLL was off.

On these particular chips, the PLL is a separate fuse, so selecting 'HS' does not automatically turn it off Instead there is a separate 'PLL on', or 'PLL off, but can still be software enabled' option. The default ('1') is the first.....

PCM_programmer points out a really 'critical' thing here. If you are having problems, look at the fuses at the end of the listing file. Do these agree with what you expect?. If not, what controls the bit that is different? (in this case, PLL_SW).

Fun isn't it!... Smile
temtronic



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

View user's profile Send private message

PostPosted: Fri Mar 14, 2014 5:36 am     Reply with quote

Fun ..??? I've been down that road a couple of times!
I now take NOTHING for granted and configure every fuse on each own line.When I get the '1 Hz LED' program running right, I save the fuses as an 'include' file usually named 'pictype.fuz'. it not only gives me a set of known working fuses, it reduces visual 'space' in the program and saves me retyping misspelled or dylsexic words.

I do the same with defining I/O pins.If not used 'NU' is prefix of the name.
#define NUB4 PIN_B4 //pin 37 not used
#define SIO_TX1 PIN_C6 //pin 23 //data to PC (debug)
Again, saved as an 'include' file, 'PICtype_projectname.pnz'
It quickly allows me to see what pins are used or available.


hth
jay
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Mar 14, 2014 6:51 am     Reply with quote

Hi All,

This is a new pic for me... first time dealing with PLL.
I believed HS would disable the PLL.

Temtronic, like you have a "standard" fuses bit of code.
But my PICs were never this sophisticated.

Why aren't the fuses listed and described individually on the datasheet? Like a summary, instead of all over the DS.... sigh.

I got it to run properly.. so thank you all.
_________________
CCS PCM 5.078 & CCS PCH 5.093
temtronic



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

View user's profile Send private message

PostPosted: Fri Mar 14, 2014 7:01 am     Reply with quote

Part of the problem is that CCS calls them 'fuses' and Microchip calls them 'configuration words'.
I'm pretty sure section 4- Device Configuration of the Datasheet will describe them all for you( I looked at the LF version of the DS).

Fuses comes from the 'good old days' when you actually blew a small fuse(really !) to configure cells within the chip.I don't know why CCS called them that...

I also don't know why PICs do NOT default to digital I/O on all pins instead of some of the peripherals being enabled.

Just two quirks we have to be aware of.


hth
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Fri Mar 14, 2014 9:23 am     Reply with quote

The first problem is 'evolution'.
The earlier PIC's had one oscillator, and one set of fuses configuring them.
When the first PLL was added, it was an extra 'line' in the list of oscillator 'type'.
Then When USB PIC's came along, things got more complex, with the PLL having a lot of programmable divisions, and the CPU and the USB operated from the same, or separate clocks.
Then we switch to the PIC24's, where you have oscillator 'setup', as a separate entity from the 'oscillator to use'.
Then newer PIC's switched to having the PLL configurable _after boot_ in the software. Makes sense (allows you to slow the PIC and save power, then switch it up to higher speeds when needed), but means the oscillator now has to separate from the PLL...
Unfortunately the same names are used for all the types of chips, which is why the data sheet is your friend.

On the name, CCS followed MicroChip. The early PIC data sheets called them fuses. The earliest PIC's, were OTP devices though.

On digital I/O, you don't want a pin selected as 'digital' (even as an input), if analog sources are connected to it. Hence the default to analog in many cases. Why some peripherals default to enabled, is only answerable by MicroChip....

Best Wishes
jeremiah



Joined: 20 Jul 2010
Posts: 1353

View user's profile Send private message

PostPosted: Fri Mar 14, 2014 12:41 pm     Reply with quote

temtronic wrote:

I also don't know why PICs do NOT default to digital I/O on all pins instead of some of the peripherals being enabled.


If it makes you feel any better, most of the PIC24's do default to digital I/O. There are a few exceptions (I2C), but things like UART and SPI default to disabled on the PIC24's usually and all regular I/O is defaulted to digital (as opposed to analog).
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