Reply
Highlighted
Posts: 13
Registered: ‎04-13-2017
Accepted Solution

EFM8 Laser Bee cannot run on HFOSC1 72MHz oscillator

Dear all,

 

I am getting up to fix a weird problem with EFM8LB12F64E. I want to generate some delay by using Timer2. I manage to do it by using HFOSC0, but HFOSC1. Here is the code for 24.5 MHz

 

// MAIN PROGRAM

#include "MCU_init.h"
#include <SI_EFM8LB1_Defs.h>

sbit LED = P3^0;

void Timer2_ISR(void) interrupt 5 
{
LED             = ~LED ;
TMR2CN0_TF2H    = 0   ;	
}


void main(void) 
{
  MCU_init();
	IE           = 0xA0 ;       // Interrupts and T2 Interrupt Enable
	TMR2CN0_TR2  = 1    ;       // Run T2
	
	while(1);
}



// MCU_init.h

#include <SI_EFM8LB1_Register_Enums.h>

void MCU_init(void)  
{
	CLKSEL    =0x00;     // HFOSC0 selected. SYSCLK=HFOSC0 /1 = 24,5 MHz
...
	HFOCN     =0x08;     // HFOSC0 enabled (24,5 MHz)
	
...
	
	CKCON0     = 0x30;   // Timer2 Uses SYSCLK
	
	// T2 reload value = 0xD026 = 53.286
	
	TMR2RLH    = 0xD0;   // T2 Reload Value High Byte
	TMR2RLL    = 0x26;   // T2 Reload Value Low  Byte


Here is the output from P3.0 (1kHz, as expected)

 

Capture at 24.5MHz.JPG

 

I just played around CLKSEL and HFOCN register to get 72MHz SYSCLK

 

// MCU_init.h

#include <SI_EFM8LB1_Register_Enums.h>

void MCU_init(void)  
{
	CLKSEL    =0x03;     // HFOSC1 selected. SYSCLK=HFOSC1 /1 = 72 MHz
...
	HFOCN     =0x80;     // HFOSC1 enabled (72 MHz)
	
...
	
	
	CKCON0     = 0x30;   // Timer2 Uses SYSCLK
	
	// T2 reload value = 0xD026 = 53.286
	
	TMR2RLH    = 0xD0;   // T2 Reload Value High Byte
	TMR2RLL    = 0x26;   // T2 Reload Value Low  Byte
...

Here is the output (125 Hz)

 

Capture at 72MHz.JPG

 

Normally, 72MHz / (65536-53286) /2 = 2938 kHz has been expected for this configuration, but, I got 125 Hz which indicates a frequency around 3 MHz at the input of T2. 

 

I tried for 48 MHZ (with 1.5 prescale), but, same result. It looks like T2 trigger frequency cannot be more than 3 MHz. 

 

What may be wrong? Is there a bug?

 

Best regards!

 

 

 

Posts: 13
Registered: ‎04-13-2017

Re: EFM8 Laser Bee cannot run on HFOSC1 72MHz oscillator

I have just tried 72 MHz / 4 = 18 MHz and everything just fine. But, failed at 36Mhz, 48MHz and 72 MHz.

 

<a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero</font></font> </a> jmg
Posts: 1,155
Registered: ‎04-27-2004

Re: EFM8 Laser Bee cannot run on HFOSC1 72MHz oscillator


What may be wrong? Is there a bug? 


Search in the RM for FLRT.

This is not explicitly mentioned in the  8. Clocking and Oscillators 

section, but probably should be mentioned there, as well as in 10.3.2 Prefetch Engine

 

Posts: 13
Registered: ‎04-13-2017

Re: EFM8 Laser Bee cannot run on HFOSC1 72MHz oscillator

Thanks for the info. I am now aware one more critical thing which must be known. However, the code yet doesn't work

 

 

void MCU_init(void)  
{

	HFOCN     = 0x80;     // HFOSC1 enabled (72 MHz)
	

	PFE0CN    = 0x20;     // SYSCLK < 75 MHz	

	
	CLKSEL    = 0x83;     // HFOSC1 selected. SYSCLK=HFOSC1 /1 = 72 MHz
	

I checked the registers by debugger and found the root cause. CLKSEL register holds 0xB0 though It is initialized to 0x83 by code. It results in a 24.5 MHz clock divided by 8 clock at T2 gate. That matches what I measure from the pin.

 

 

Has someone an idea why CLKSEL cannot be changed?

 

 

Posts: 13
Registered: ‎04-13-2017

Re: EFM8 Laser Bee cannot run on HFOSC1 72MHz oscillator

Here is how to initialize HFOSC1;

 

	CLKSEL = 0x00;
	CLKSEL = 0x00;
	while (CLKSEL == 0x00);
	CLKSEL = 0x03;
	CLKSEL = 0x03;
	while (CLKSEL == 0x03);

Shame on you Silabs for not to mention such a basic thing (initializing the heart of the MCU) nowhere in the reference manual! Shame on you!

<a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero</font></font> </a> jmg
Posts: 1,155
Registered: ‎04-27-2004

Re: EFM8 Laser Bee cannot run on HFOSC1 72MHz oscillator

The RM does say this :

 

This device family has restrictions when switching to clock sources that are greater than 25 MHz.

SYSCLK must be running at a frequency of 24 MHz or greater before switching the CLKSL field to HFOSC1.

When transitioning from slower clock frequencies, firmware should make two writes to CLKSEL.

Posts: 13
Registered: ‎04-13-2017

Re: EFM8 Laser Bee cannot run on HFOSC1 72MHz oscillator

I have checked the RM, Yes, it is written. 

 

Anyway, it would have been in a better and more clear format. Thanks for your help! I appreciate that. Best regards!