View previous topic :: View next topic |
Author |
Message |
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Wed Aug 29, 2007 7:16 am |
|
|
I think might be your problem, the max crystal you can use is 32 kHz.
To use higher frequencies you have to drive it with an oscillator. |
|
 |
sjharris
Joined: 11 May 2006 Posts: 78
|
|
Posted: Wed Aug 29, 2007 7:23 am |
|
|
Agh ok, will swap it over and try that!!
Thanks |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Aug 29, 2007 7:39 am |
|
|
When your PIC16F688 goes into sleep it turns off all internal oscillators, the newer PIC models have more selectable sleep grades. Without oscillators running there is no way the PIC can wake up by itself and needs an external trigger. Your external crystal is not being driven and hence useless in sleep mode. You have two options:
1) Replace the crystal by a clock generator. These components are a crystal with integrated drivers.
or
2) You use the configuration from my post above, but then only up to max. 32kHz. Note that this is 32kHz during sleep but when active you use the internal RC clock up to 8MHz. |
|
 |
sjharris
Joined: 11 May 2006 Posts: 78
|
|
Posted: Wed Aug 29, 2007 7:58 am |
|
|
OK so I set up the PIC to use 32kHz, from an external crystal??
Then I set the PIC up using:-
Quote: | Code: | setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); |
|
And this should work??
Is the 32KHz limit are hard limit, i.e. can I run a 32.768 KHz crystal in sleep mode or is that too high still?? |
|
 |
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Wed Aug 29, 2007 8:20 am |
|
|
Yes that should work.
32 KHz is the crystal limit not the oscillator limit.
I'm driving my chip with a 1.8432 MHz oscillator |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Aug 29, 2007 8:22 am |
|
|
sjharris wrote: | Is the 32KHz limit are hard limit, i.e. can I run a 32.768 KHz crystal in sleep mode or is that too high still?? | All my knowledge comes from the PIC16F688 datasheet, you can read this just as I have to do. Hint: table 14-1 'LP Oscillator mode'. |
|
 |
sjharris
Joined: 11 May 2006 Posts: 78
|
|
Posted: Wed Aug 29, 2007 8:40 am |
|
|
Look guys,
All I want is a bit of knowledge. I havnt done this before. I need help. I am asking for your help. Why make someone else go on the extrapalated tour of datasheets that you obvioulsy had to do??
Why can you not just tell me whether what I am doing is correct or not??
Surely this is a SUPPORT forum, where is the support in Quote: | you can read this just as I have to do. Hint: table 14-1 'LP Oscillator mode' |
I am really stuck with this problem. All I want to do is to wake the PIC up from sleep with an external crystal.
Can someone just give me a difiinitive answer as to what I need to do with Hardware and in Software with a piece of tested code that works.
PLEASE someone help.
Thanks |
|
 |
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Wed Aug 29, 2007 8:56 am |
|
|
did the 32 khz crystal not work? |
|
 |
sjharris
Joined: 11 May 2006 Posts: 78
|
|
Posted: Wed Aug 29, 2007 9:01 am |
|
|
No,
I used a 32.768 KHz crystal, I want to check my code with someones whos did work.
Thanks |
|
 |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Aug 29, 2007 9:36 am |
|
|
Quote: |
I used a 32.768 KHz crystal, I want to check my code with someones whos did work.
|
No way. If you want to wake up the PIC using Timer1 interrupt, the only way to do it is:
1) Using the built-in internal RC oscillator.
2) Driving PIN3 with an external clock source.
Do not forget in your first request you claim for:
Quote: |
Can anyone tell me what I need to do to:-
1) Set timer1 as an external clock source
2) Enable timer1 as an interrupt source
3) Service the interrupt (I assume a flag set then return to code).
|
Quote: |
Surely this is a SUPPORT forum, where is the support in
|
NOP. This is not a SUPPORT forum.
Pls read the first paragraph.
http://www.ccsinfo.com/forum/viewtopic.php?t=26245&sid=e267fb23edc98e099ae10f6e9fac57df
1. This forum is not an official support forum
Humberto |
|
 |
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Wed Aug 29, 2007 10:15 am |
|
|
Have you verified with a scope that the crystal circuit is working? |
|
 |
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Wed Aug 29, 2007 10:59 am |
|
|
ok, here is some code that works on a PIC18F part but should work on your part.
This is about as simple as you can get, if this doesn't work you probably have a hardware problem.
Code: |
#include "..\default.h"
#pragma byte OSCCON = getenv( "SFR:OSCCON" )
#pragma bit IDLEN = OSCCON.7
#define EXT_OSC_SPEED 32768
#define LED PIN_E5
unsigned int32 cycleCount = EXT_OSC_SPEED;
unsigned int8 seconds = 0;
#pragma INT_TIMER1
void RTC( void )
{
#pragma use fast_io( E )
if ( seconds == 0 ) {
seconds = 1;
output_low( LED );
}
else {
seconds = 0;
output_high( LED );
}
}
void main( void )
{
#pragma use standard_io( E )
// IDLEN = 1; //Enable IDLE mode
setup_timer_1( T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);
output_high( LED );
enable_interrupts( INT_TIMER1 );
enable_interrupts( GLOBAL );
for( ; ; ) {
sleep( );
}
}
|
default.h
Code: |
#include "18F65J10.h"
#pragma device ADC = 10
#pragma case
#pragma fuses DEBUG //Enable Dedicated Debugger Pins
#pragma fuses NOWDT //Disable Watchdog Timer
#pragma fuses STVREN //Enable Stack Over/Underflow Reset
#pragma fuses NOXINST //Disable Extended Instructions
#pragma fuses NOPROTECT //Disable Code Protection
#pragma fuses NOIESO //Disable Two Speed Start-up
#pragma fuses FCMEN //Enable Fail Safe Clock Monitor
#pragma fuses PRIMARY //Set Defaul Clock as PRIMARY
#pragma fuses H4_SW //High Speed Crystal and PLL
#pragma fuses WDT32768 //Set WDT Postscaler to MAX
#pragma fuses CCP2C1 //ECCP2/P2A is Multiplexed with RC1
#pragma use delay( clock = 36,864,000, crystal = 9,216,000 )
|
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 29, 2007 11:21 am |
|
|
See this post. The PIC has a 4 MHz crystal on the main oscillator pins
and a 32 KHz crystal on the Timer1 oscillator pins. The 32 KHz crystal
continues to run while the PIC is sleeping. When Timer1 counts up to
the max count and rolls over, it generates an interrupt and wakes up
the PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=28158&start=8 |
|
 |
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Wed Aug 29, 2007 11:30 am |
|
|
We have a design in production very similar to that, except 20MHz main crystal. For an 18F part but 16F should be similar. Wakes up on Timer 1 rollover. |
|
 |
sjharris
Joined: 11 May 2006 Posts: 78
|
|
 |
|