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 support@ccsinfo.com

16F676 - Oscillator not starting - 32.768khz

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



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

16F676 - Oscillator not starting - 32.768khz
PostPosted: Wed Jul 03, 2013 6:23 am     Reply with quote

Hi All,

I am trying to run 16F676 with external crystal - 32.768khz.
The oscillator is not starting i tried load capacitance with values -
10 - 47 pf.


Please reply with suggestion.

main.h

Code:

#include <16F676.h>
#device adc=8
#fuses NOWDT, LP, NOPROTECT, NOMCLR, PUT, NOBROWNOUT
#use delay(clock=32768)


Code:

#include <main.h>

void main()
{

 
   while(TRUE)
   {
    output_toggle(PIN_C3);
    delay_ms(1000);
    //TODO: User Code
   }

}


Thanks and Regards,
Jai.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Wed Jul 03, 2013 7:36 am     Reply with quote

Start by getting a specification for the crystal.
It may well require a series resistor (most 32K crystals are 'strip cut' XY).
Sometimes at low power, a parallel resistor needs also to be added to get the oscillator to start,
Remember that the capacitors, are not directly the Cl seen by the crystal. It sees:

Cl = (C + Cx)/2

Where 'C' is the capacitors you fit, and Cx is the total 'extra' capacitance from the pin, tracks etc..
Now the PIC pin, plus PCB traces will typically give something like 5pF for Cx. Many watch crystals only want a Cl perhaps as low at 7pF. So solving for 'C' gives:

C = (Cl*2)-5

C = (14)-5 = 9pF

Get the actual figure for your crystal, and calculate the capacitor.

Remember if you are using something like a breadboard Cx, may easily be 20 or 30pF already. This then makes the oscillator less likely to start, and adding a resistor across the crystal may be essential, and your frequency will be slightly in error.

Best Wishes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jul 03, 2013 7:37 am     Reply with quote

Are you using a series resistor, RS in figure 9.1 page 57 of the datasheet? If not you may have damaged your crystal. Some of those 32kHz crystals require very low power levels to avoid damage. See if the crystal datasheet has a recommended drive circuit. The PIC data sheet recommends 68pF to 100pF for 32KHz.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Wed Jul 03, 2013 7:56 am     Reply with quote

Yes.
The capacitor totally depends on what load the crystal expects. There are types designed for low capacitance (in particular the ones meant to work directly with chips like the DS1307), which are meant to only have the pin capacitance of the chip, while many of the 'traditional' watch crystals require much higher capacitances. At low power a series resistor is commonly essential, and also sometimes just a little extra 'kick' to get the oscillator to start, with a resistor between the PIC pins.
Generally most will work with the load capacitance too high, but significantly 'off frequency'.
This is why the data sheet is essential.

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Wed Jul 03, 2013 10:47 am     Reply with quote

OK, I have to ask the obvious question....
Why run the PIC at that speed? Awfully sloooooow and a waste of PIC. It'll take forever to do anything, and operations like serial communications, printf(), a 'float' operation will take, well days !!!

I'm just curious....


jay
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jul 03, 2013 11:30 am     Reply with quote

Generally people run uC's from 32kHz crystals when they want accurate speed without much to do and want long battery life. Examples might include an ocean tide recorder, star tracking telescope, watering lawns, delivering animal feed, and of course a clock.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Wed Jul 03, 2013 12:39 pm     Reply with quote

However people after super battery life would probably use a PIC designed for this - one of the modern low power chips rather than the 676, and most often switch oscillator rates to give short bursts with higher performance.

Best Wishes
jaikumar



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

PostPosted: Wed Jul 03, 2013 11:15 pm     Reply with quote

Thanks everyone for your suggestion/comments.

This is a simple timer project. Need to turn 2 relay at specified time.
I thought nothing else to do so can use watch crystal to provide accurate
timing as possible.

Also just wanted to know whether implementing the code on the below:
http://www.romanblack.com/one_sec.htm

Will that be accurate.

Regards,
Jai.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Thu Jul 04, 2013 3:01 am     Reply with quote

OK.
What you want is perfectly 'possible', but the key always is needing to start with data.
32KHz crystals, have so many varieties it is insane.
Common features though are:
1) They are generally low power devices. Designed to be running off oscillators using something like a single Mercury (historically), or Silver oxide cell. As such they will be overdriven by a PIC oscillator, unless you use a series resistor. I mentioned this in the second line of my first post:
"It may well require a series resistor (most 32K crystals are 'strip cut' XY).", and this is highlighted by SherpaDoug.
2) The PIC oscillator typically exhibits about 10MR between the two pins. Sometimes in low power mode, this is not quite enough to start the oscillator, and a resistor needs to be added here.
3) To get reasonably accurate frequencies, you must use the quoted loading resistance. Hence again data is needed. A quick glance at one UK supplier had 176 different varieties of 32768Hz crystals, with loading capacitances from 6pF to 76pF, series resistances from 32KR, to 194KR, etc. etc...

Best Wishes
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 04, 2013 6:00 am     Reply with quote

Did you try to run the board with the internal oscillator?
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu Jul 04, 2013 7:05 am     Reply with quote

you could use a regular crystal and use this:

http://www.ccsinfo.com/forum/viewtopic.php?t=26177&highlight=drift

for relay timing purposes that should be enough...
EDIT: i say this since mechanical relays all have different response times which may change over time due to wear.... so +/-10ms or 100ms in an action controlled by a relay should not be a problem in most aplications... i doubt a tank will overflow if the pump starts 100ms later... for example.

since battery operated relays are pointless, i feel safe assuming this will be powered by a regular stable 5V... so power saving is not an issue..

Ive used that code and it works beautifully... ive also made my own modifications to use TMR1 with a 32k crystal and that works great too..

you can do alarms and schedules with a little bit of code...

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
temtronic



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

View user's profile Send private message

PostPosted: Fri Jul 05, 2013 11:14 am     Reply with quote

I've used that code the Gabriel links to and 2nd that it does work...however...
Once the power fails..oops, there goes the RTC as well as setpoints.

Consider using a RTC chip like the DS1307. Benefits include no loss of 'real time', battery backed SRAM for setpoints, an interrupt is available.

Or a two battery system, one for the processor, one for the relays.

As for 'battery operated relays'...given a reasonably sized battery and low power relays you can easily get 12-24 hours of operation. My remote energy control systems use this combination. The key is the details, knowing power consumed, power available, duration of use, etc.

hth
jay
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Fri Jul 05, 2013 11:29 am     Reply with quote

A couple of things to consider with relays and 32khz operation. Not sure if it is still the case, but it used to be the emi testing requirements were quite different (relaxed) if the uP used a clock frequency of 32khz or less (one reason we used the 68332 processor years ago externally at 32khz but internally at 16mhz). As far as the relays go, while for normal relays, battery operation will depend on current drain in the relays, there are also latching relays available for specialized types of things where it only takes a pulse to latch them in either state, then no current after that which would drop the total power usage way down for something that only switches state periodically.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Jul 05, 2013 3:00 pm     Reply with quote

Quote:
Once the power fails..oops, there goes the RTC as well as setpoints.


indeed Jay.. however.. if he just wants to create a schedule or get a defined delay... for example:

switch relay 1 hour after event X happens

The contents of the time registers is irrelevant.. on reset he could set the time to a ficticious time and just make use of the accurate time keeping properties... hours, minutes, etc...

g.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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