Using external crystal oscillator on Freescale MC9S08SH8

Thread Starter

mgookin

Joined Mar 21, 2017
11
Dear Group:

We have a Freescale MC9S08SH8 data sheet: http://www.mouser.com/ds/2/302/MC9S08SH8-783274.pdf
We're on the Freescale Demo Board DEMO9S08SH8/SG8 user guide: http://www.nxp.com/assets/documents/data/en/user-guides/DEMO9S08SH8UG.pdf
Using Codewarrior v10.6

We are using an external crystal oscillator with the RTC. We can not seem to figure out the code to get the two in harmony.
Our code is as follows:

// Use external clock (32.768kHz crystal), based on table 13-3
RTCMOD = 0b00100000; // 32 (32*31.25ms=1s)
RTCSC = 0b00110111; // CS=ERCLK, RTIE, PS=0111 (/1024=31.25ms)

Crystal oscillator circuit has been designed per Appendix B of the data sheet and connected to the demo board header at XTAL & EXTAL.

We can get the RTC to trigger an interrupt and blink an LED when we use the 1kHz low power oscillator, but not when we use the crystal.

What are we missing?

Many thanks in advance.
 

Thread Starter

mgookin

Joined Mar 21, 2017
11
Bump:
Am I not asking the question correctly?
I've researched the forums for an answer to this question and come up blank.
Thanks.
 

bertus

Joined Apr 5, 2008
22,270
Hello,

Have a look at the following sections taken from the provided documents.
In the MC doc this is given:

MC9S08SH8_timing.png

In the DEMO doc is given:

DEMO9S08SH8_timing.png

So the demoboard standard uses the internal clock, but has space for an external clock.

Bertus
 

BR-549

Joined Sep 22, 2013
4,928
Have you selected the correct oscillator.......in your config files? It might be defaulted to the an internal.
 

Thread Starter

mgookin

Joined Mar 21, 2017
11
Thanks BR-59. I should have included the entire code.

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

// Clock source constants
#define LPO 0
#define IRCLK 1
#define ERCLK 2
#define CLK_SRC LPO

#define LED_DIR PTADD_PTADD2
#define LED_OUT PTAD_PTAD2

// Interrupt service routine for real time counter
interrupt VectorNumber_Vrtc void RTC_ISR(void)
{
// Clear interrupt flag
RTCSC |= 0x80;
LED_OUT = !LED_OUT; // toggle the LED every second
}

void main(void) {
// Board has an LED connected to PDB7; make it output
LED_DIR = 1;

#if CLK_SRC == IRCLK
// Use the higher accuracy 32kHz internal clock
RTCMOD = 0b01111101; // 125 (125*8ms=1s)
RTCSC = 0b01010101; // CS=IRCLK, RTIE, PS=0101 (8ms)
#elif CLK_SRC == ERCLK
// Use the external clock (32.768kHz xtal)
RTCMOD = 0b00100000; // 32 (32*31.25ms=1s)
RTCSC = 0b00110111; // CS=ERCLK, RTIE, PS=0111 (/1024=31.25ms)
#else
// Use the 1kHz low power oscillator (30% margin for error)
RTCMOD = 0x00; // 0b00000000
RTCSC = 0x1F; // 0b00011111
#endif

EnableInterrupts;
/* include your code here */

for( ; ; {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
 

BR-549

Joined Sep 22, 2013
4,928
Alrighty......did it work? I wouldn't be able to tell with just the code. I am not familiar with your chip.

There is a like button on each response post. If the response helps you (or is real funny).....click the like button to show it.

Have a good one.
 

Thread Starter

mgookin

Joined Mar 21, 2017
11
Alrighty......did it work? I wouldn't be able to tell with just the code. I am not familiar with your chip.

There is a like button on each response post. If the response helps you (or is real funny).....click the like button to show it.

Have a good one.
That's the code we had before I posted the question. It will flash a LED using the internal counter but not with the RTC & external oscillator. It seems as if we are missing something.
 

BR-549

Joined Sep 22, 2013
4,928
Evidently. You really have to study those datasheets. They are not an easy read for most. As previously noted, we haven't seen too many freescale users here.

Perhaps a freescale forum could help.
 

Thread Starter

mgookin

Joined Mar 21, 2017
11
Evidently. You really have to study those datasheets. They are not an easy read for most. As previously noted, we haven't seen too many freescale users here.

Perhaps a freescale forum could help.
Our software engineer posted it on the NXP community but it has garnered zero response. I've had success on this venue previously so I posted it here.

Thank you for your responses.
 
Top