View previous topic :: View next topic |
Author |
Message |
sindyme
Joined: 05 Aug 2009 Posts: 37
|
PIC24: How can I setting fuse for both external oscillator |
Posted: Wed Sep 15, 2010 9:45 pm |
|
|
I use PIC24FJ256GA1006 and my CCS version is PCD 4.105
------------------------------------------------------------------------------------
How can I use the ( OSCO,OSCI ) & (SOSCO,SOSCI) at the same time ?
I want to use 16MHz & 32.768KHz,
16MHz as primary oscillator & 32.768KHz for RTC.
Could someone teach me how to set the fuses? Thanks.
Note:
I use oscilloscope to monitor 16MHz and 32.768KHz.
16Mhz have work but 32.768 do not work.
Now my .h file setting follows:
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICSP2 //ICD uses PGC2/PGD2 pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES PR //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES HS //External clock with CLKOUT
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES WPEND_LOW
#FUSES NOWPCFG
#FUSES NOWPDIS
#FUSES WPFP
#FUSES RESERVED //Used to set the reserved FUSE bits
|
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Sep 16, 2010 12:03 am |
|
|
The secondary oscillator has to be enabled by the SOSCEN bit in OSCCON.
As far as I experienced, the PCD built-in function setup_rtc() also enables the SOSC, even if you don't want it to. |
|
|
sindyme
Joined: 05 Aug 2009 Posts: 37
|
|
Posted: Thu Sep 16, 2010 12:23 am |
|
|
FvM wrote: | The secondary oscillator has to be enabled by the SOSCEN bit in OSCCON.
As far as I experienced, the PCD built-in function setup_rtc() also enables the SOSC, even if you don't want it to.
|
Then in main, I am setting these function:
Code: |
setup_spi(FALSE);
setup_spi2(FALSE);
setup_wdt(WDT_ON);
setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0x00);
setup_timer1(TMR_EXTERNAL|T1_EXTERNAL_RTC|TMR_DIV_BY_1); |
But oscilloscope still can't see 32.768 work.
And question 2:
The "rtc_write(datetime)" and "rtc_read(datetime)" can't compile.
CCS give me error msg for "Undefined identifier".
By the way ~ If RTCC work normal, then How can I read RTCC value to printf ? how is the Syntax? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Sep 16, 2010 10:02 am |
|
|
Quote: | But oscilloscope still can't see 32.768 work. |
It's working for me with Explorer16 board and 24F256GB110 PIM. May be a problem with your crystal circuit?
Quote: | The "rtc_write(datetime)" and "rtc_read(datetime)" can't compile. CCS give me error msg for "Undefined identifier". |
I guess for the variable datetime, if it's undefined? |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Sep 16, 2010 11:04 pm |
|
|
sindyme wrote: |
And question 2:
The "rtc_write(datetime)" and "rtc_read(datetime)" can't compile.
CCS give me error msg for "Undefined identifier".
By the way ~ If RTCC work normal, then How can I read RTCC value to printf ? how is the Syntax? |
the RTC commands read/write a structure.
The typedef for that structure is listed in the .H file...
You would then define a static struct for that using something like
static rtc_time_t mytime;
And now anytime you read/write to the RTC, you'd use syntax like:
rtc_write(&mytime);
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|