Hi,
I am using mc9s08dz96 microcontroller with 8 MHz external clock osc.
I want to generate 2MHz output clock on the port PTA0 of microcontroller for another IC? I want to ask how is it done?
Thank you.
Solved! Go to Solution.
What is your bus clock frequency ?
If you set the bus clock to 4 MHz
something like this
/* ### MC9S08DZ128_100 "Cpu" init code ... */
/* PE initialization code after reset */
/* Common initialization of the write once registers */
/* SOPT1: COPT=0,STOPE=0,SCI2PS=0,IIC1PS=0,??=0,??=0,??=0 */
setReg8(SOPT1, 0x00U);
/* SOPT2: COPCLKS=0,COPW=0,??=0,ADHTS=0,??=0,MCSEL=0 */
setReg8(SOPT2, 0x00U);
/* SPMSC1: LVWF=0,LVWACK=0,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */
setReg8(SPMSC1, 0x1CU);
/* SPMSC2: ??=0,??=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */
setReg8(SPMSC2, 0x00U);
/* System clock initialization */
/*lint -save -e923 Disable MISRA rule (11.3) checking. */
if (*(uint8_t*)0xFFAFU != 0xFFU) { /* Test if the device trim value is stored on the specified address */
MCGTRM = *(uint8_t*)0xFFAFU; /* Initialize MCGTRM register from a non volatile memory */
MCGSC = *(uint8_t*)0xFFAEU; /* Initialize MCGSC register from a non volatile memory */
}
/*lint -restore Enable MISRA rule (11.3) checking. */
/* MCGC2: BDIV=1,RANGE=1,HGO=0,LP=0,EREFS=0,ERCLKEN=1,EREFSTEN=0 */
setReg8(MCGC2, 0x62U); /* Set MCGC2 register */
/* MCGC3: DIV32=1 */
setReg8Bits(MCGC3, 0x10U);
/* MCGC1: CLKS=0,RDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
setReg8(MCGC1, 0x1AU); /* Set MCGC1 register */
/* MCGC3: LOLIE=0,PLLS=0,CME=0,DIV32=1,VDIV=1 */
setReg8(MCGC3, 0x11U); /* Set MCGC3 register */
/* MCGT: ??=0,??=0,DMX32=0,??=0,??=0,??=0,??=0,DRST_DRS=0 */
setReg8(MCGT, 0x00U); /* Set MCGT register */
while(MCGSC_IREFST != 0U) { /* Wait until external reference is selected */
}
while((MCGSC & 0x0CU) != 0x00U) { /* Wait until FLL clock is selected as a bus clock reference */
and after you need to set
the MCSEL to 01
I hope this will help you.
Thank you so much, the problem solved with setting MCSEL to 01.
What is your bus clock frequency ?
If you set the bus clock to 4 MHz
something like this
/* ### MC9S08DZ128_100 "Cpu" init code ... */
/* PE initialization code after reset */
/* Common initialization of the write once registers */
/* SOPT1: COPT=0,STOPE=0,SCI2PS=0,IIC1PS=0,??=0,??=0,??=0 */
setReg8(SOPT1, 0x00U);
/* SOPT2: COPCLKS=0,COPW=0,??=0,ADHTS=0,??=0,MCSEL=0 */
setReg8(SOPT2, 0x00U);
/* SPMSC1: LVWF=0,LVWACK=0,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */
setReg8(SPMSC1, 0x1CU);
/* SPMSC2: ??=0,??=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */
setReg8(SPMSC2, 0x00U);
/* System clock initialization */
/*lint -save -e923 Disable MISRA rule (11.3) checking. */
if (*(uint8_t*)0xFFAFU != 0xFFU) { /* Test if the device trim value is stored on the specified address */
MCGTRM = *(uint8_t*)0xFFAFU; /* Initialize MCGTRM register from a non volatile memory */
MCGSC = *(uint8_t*)0xFFAEU; /* Initialize MCGSC register from a non volatile memory */
}
/*lint -restore Enable MISRA rule (11.3) checking. */
/* MCGC2: BDIV=1,RANGE=1,HGO=0,LP=0,EREFS=0,ERCLKEN=1,EREFSTEN=0 */
setReg8(MCGC2, 0x62U); /* Set MCGC2 register */
/* MCGC3: DIV32=1 */
setReg8Bits(MCGC3, 0x10U);
/* MCGC1: CLKS=0,RDIV=3,IREFS=0,IRCLKEN=1,IREFSTEN=0 */
setReg8(MCGC1, 0x1AU); /* Set MCGC1 register */
/* MCGC3: LOLIE=0,PLLS=0,CME=0,DIV32=1,VDIV=1 */
setReg8(MCGC3, 0x11U); /* Set MCGC3 register */
/* MCGT: ??=0,??=0,DMX32=0,??=0,??=0,??=0,??=0,DRST_DRS=0 */
setReg8(MCGT, 0x00U); /* Set MCGT register */
while(MCGSC_IREFST != 0U) { /* Wait until external reference is selected */
}
while((MCGSC & 0x0CU) != 0x00U) { /* Wait until FLL clock is selected as a bus clock reference */
and after you need to set
the MCSEL to 01
I hope this will help you.