MC9S08QE128 internal clock

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MC9S08QE128 internal clock

1,784 次查看
MicMoba
Contributor V
Hello,
last week I got the new chip (MC9S08WE128). The datasheet says that the internal clock can be configured up to 20MHz.

So I set up the ICS and toggle a port but I can only measure 2MHz. Why?

Has anybody a explanation?


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

#define clrSetReg8Bits(RegName, ClrMask, SetMask)  (RegName = (RegName & (~(byte)(ClrMask))) | (byte)(SetMask))
#define setReg8(RegName, val)                      (RegName = (byte)(val))


void InitSystems() {
 
  SOPT1  = 0x23;                          // Disable COP,RSTO, enable STOP,BKGD,RESET
  SOPT2  = 0x00;                          // SPI1 on PTB2/3/4/5, IIC1 on PTA2/3
  SPMSC1 = 0x00;                          // Disable LVD
  SPMSC2 = 0x00;                          // Disable power-down modes
  SPMSC3 = 0x00;                          // Disable LVWIE, low trip points
  SCGC1  = 0xFF;                          // Enable bus clock to peripherals
  SCGC2  = 0xFF;                          // Enable bus clock to peripherals
  
  /*  System clock initialization */
  /* ICSC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */
  setReg8(ICSC1, 0x06);                /* Initialization of the ICS control register 1 */
  /* ICSC2: BDIV=0,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */
  setReg8(ICSC2, 0x00);                /* Initialization of the ICS control register 2 */
  while(!ICSSC_IREFST) {               /* Wait until the source of reference clock is internal clock */
  }
  /* ICSSC: DRST_DRS=2,DMX32=1 */
  ICSSC = 0xA1;
} // end InitSystems


/************************
   Main Program Loop
************************/
void main(void) {

 
  InitSystems();

  PTCD_PTCD0   = 0;
  PTCDD_PTCDD0 = 1;                  // Turn ON PTC0 LED

  while(1)
  {
        PTCTOG_PTCTOG0   = 1;
  }
}


Best regards

Michael
标签 (1)
0 项奖励
回复
3 回复数

518 次查看
bigmac
Specialist III
Hello Michael,
 
It would appear that each pass through the while loop takes 5 bus cycles to complete, and for each output cycle there needs to be two passes through the loop.  To verify this, you will need to examine the assembly code generated during compile, and then consider the number of cycles required by each assembly instruction.
 
Regards,
Mac
 
 
 
0 项奖励
回复

518 次查看
Ake
Contributor II
Hi,
If you measure the speed of something, it is convienent to use 
for (;:smileywink:
  {
        PTCD_PTCD0 = 1;//5 cycles
        PTCD_PTCD0 = 0; //5 cycles
  } //3 cycles
 
The  PTCD_PTCD0 instruction is translated to
bset         PTCD_PTCD0,PTCD //5 clocks

That makes 13 cycles. If your code runs at 2 MHz, * 13 = 26 MHz.
Thats not bad!
(I tried it on your software.)
 
Regards,
Ake
0 项奖励
回复

518 次查看
MicMoba
Contributor V
Hello Marc,
thank you for answer. I calculate the cycles and then I get the result of 2MHz.

Is there a way to measure the internal clock frequenzy?

Submit Post
0 项奖励
回复