HCS12 Crystal Monitor Failure

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS12 Crystal Monitor Failure

933 Views
sebasira
Senior Contributor I

Hi all!


I have some troubles with the Clock Monitor. I'm not sure I fully understand it. I'm working with HCS12


Here's what I want to do:

- I work with a 16MHz OSC and uses the PLL to set the frequency at 48MHz (bus = 24MHz). If I touch the crystal (insert noise on it) the MCU crushes (not reset, it stays still)

I want the MCU to reset when losses the crystal or it fails. I assume that's the Clock Monitor Failure Reset for. So I implement it. But still the same


Here's what I'm doing:


PRM FILE:

 

VECTOR ADDRESS 0xFFFE  _Startup
VECTOR ADDRESS 0xFFFC  _Startup
VECTOR ADDRESS 0xFFFA  COP_ISR

As you can see when Clock Monitor Failure Reset is fetched the StartUp sequence is initiated


MAIN FUNCTION

 

COP_init();

/* PLL */
/*******/
SYNR = 5;
REFDV = 3;
     
PLLCTL_PLLON = 1;
PLLCTL_AUTO = 1;
PLLCTL_CME = 1;
PLLCTL_SCME = 0;
     
while(!CRGFLG_LOCK);
CRGFLG_LOCKIF = 1;
    
CLKSEL_PLLSEL = 1;


// Then goes all the other initializations and the main LOOP
// For now, the COP is only feeded no the main LOOP

 

When I touchd de xtal or some noise disturb it, the MCU crushes.

It seems that the RESET sequence is executed as the MCU remains still, but no StartUp...

 

An alternative to this is executing the StartUp code in the LOCKIF ISR, when the PLL is unlocked (LOCK == 0). If I do this, when noise enter the xtal pins, the MCU resets and starts again.

 

I'll like to know why is failing what's mentioned above. And why won't the CMF Resets & StartUp again the MCU.

 

Thanks in advance!!!

 


Labels (1)
0 Kudos
6 Replies

517 Views
sebasira
Senior Contributor I

New info:

 

As I said above, I put StartUp inside PLL LOCK ISR. Here's the code:

 

void PLL_LOCK_ISR (void){    CRGFLG_LOCKIF = 1;

    if (CRGFLG_LOCK){      // PLL LOCKED      CLKSEL_PLLSEL = 1;          }else{      // PLL UNLOCKED
      _Startup();    }}

 

 Doing this sometimes work, but sometimes won't. When it doesn't work 2 things happend (one or the other, never both)

1- The same described previously (MCU remains still)

2- The MCU counitnuously resets (I guess MCU startup, then the ISR call startup and so on and on)

 

Thanks! Any comment is greatly appreciatted

 

0 Kudos

517 Views
kef
Specialist I

You should mention what MCU you are using, S12 is not enough.

 

To reset on failure you should disable self clock mode (SCME=0), but your code does it wrong and self clock mode is kept enabled while in normal modes. Just look at SCME bit description, it is write once! When you write access PLLCTL register for the first time (PLLCTL_PLLON=1), you are locking reset default value of SCME=1 to the SCME bit. You can't change it later when you are doing PLLCTL_SCME=0.

 

Jump from ISR to _Startup works only if you are not assuming reset-default register values and initialize every register, which you are using in your code. Is it the case?

 

 

0 Kudos

517 Views
sebasira
Senior Contributor I

Hi Kef, thanks for your reply!

 

I'm using MC9S12A256.

 

You were right about SMCE being write once, I passed over that. Now, I'm writing PLLCTL once, with the value 0xE0.

Anyway, same thing happend.

It's strange, because it seems like self-clok mode were enable, because I've got a buzzer wich plays a tone everytime a key is stoke. When I introduce some noise over the XTAL line, while I'm stroking keys, the sound plays slowly as if the bus speed were slowly. Other times, happens what I'm mention in the other post, the MCU just remains still, frozen.


I didn't understand your last question:

 

Jump from ISR to _Startup works only if you are not assuming reset-default register values and initialize every register, which you are using in your code. Is it the case?

 

I'm jumping from ISR to _Startup... and register values are written inside the main function. The value written to PLLCTL is as I said before, 0xE0 (Self-Clock Mode Disable)

 

Now, I also have PLL LOCK IRQ disable... I just want the MCU to restart everytime the clock monitor fails

 

 

One more thing I'm discussing with the team here. The way I'm introducing noise over the XTAL line is by touching it (with my finger). What happend if I touch it fot too long (a second or two)? Let's assume the Crystal Monitor works, resets the MCU and _Startup is correctly executed. If I'm not wrong, when reseted the SCME = 1 so MCU will star with self clock, then when PLLCTL is written SCME = 0... Is it possible that the MCU won't start correctly because the XTAL is still noisy?

 

Thanks!

0 Kudos

517 Views
kef
Specialist I

When CME reset happens, self clock mode is again enabled (SCME=1). So, if you still have no oscilator cclock, then you are unable to clear SCME bit (you can't clear it while in self clock mode). To disable self clock mode you need to wait for CRGFLG_SCM=0, and only then clear SCME bit.

But what will happen if MCU will enter self clock mode between (t0) when you read SCM=0 and before (t1) when you write SCME=0? I don't know. Maybe SCME=0 will be write-once-locked and will be applied after you recover from self clock mode. Or maybe SCME=1 will be write-once-locked, and then you won't be able to turn off self clock mode without cycling power or using COP to reset MCU.

 

I meant that to jump from ISR to Startup, you should provide that your setup code won't break in case you get there with any values in peripheral registers. For example you have on the same port some "open drain" pin, controlled using DDRx bit, and another output-only pin. On reset you can assume that all DDRx bits are 0, but you can't assume this jumping from ISR to Startup. Another example. On reset you can enable interrupts (CLI) on the top of main(), but you can't do so when jumping from ISR to Startup, because you may have some interrupts already enabled, but pin setup or variables setup is not complete, so may enter some unexpected dead loop or smth.

0 Kudos

517 Views
sebasira
Senior Contributor I

I think the same as you about not knowing what happens when writting to SCME bit while XTAL is still unstable.

 

Regarding jumping from ISR to _Startup... I thought that Clock Monitor Failure performs a Reset (hardware reset), and then "resume" from CMF ISR... Just like COP ISR.. So, if the MCU is reseted all registers have their reset value... Am I wrong?

0 Kudos

517 Views
kef
Specialist I

There's no clock monitor failure interrupt and ISR. Clock monitor reset is resetting all registers to reset-default state and this is fine. I meant your code in first message. You are jumping there from PLL lock status change ISR to _Startup().

 

So did you try to wait for SCM flag?

0 Kudos