Hello,
I’m using TPM1_ch0 in edge aligned PWM mode, triggered by the TPM0 overflow. TPM0_ch0 is set in software compare mode. The intent is to shift the phase of TPM1 whenever the channel interrupt occurs on TPM0 to create a BPSK signal. I have both TPM timers running off an external 6.144MHz crystal via OSCERCLK. I am not using the external clock mode that requires TPM_CLKIN0 or TPM_CLKIN1 pins.
This works perfectly when I run the core clock off the same external Crystal. I use the following code for this:
//Set up the Run Clock MCGOUTCLK at 6.144MHz from crystal via OSCCLK
MCG_C1=0b10000000; //Set the external clock as the main clock mode (10), disable the LIRC
MCG_C2=0b00000000; //External clock requested
MCG_SC=0b00000000; //Set the FCRDIV=000 for division factor=1
MCG_MC=0b00000000; //Set the low-frequency internal reference clock divider=000 for division factor=1 (not using this), Disables HIRCEN
SIM_CLKDIV1=0b00000000000000010000000000000000; //Sets bits 31-28 as Outdiv1=0000 (/1), Outdiv4=001 (/2)
//Start-up the external crystal for the core clock
GPIO_WR_PSOR(GPIOA, 1U<<8); //Set pin8 on PortA to turn on external crystal
GPIO_WR_PSOR(GPIOA, 0U<<9); //clear pin9 on PortA to make it active
OSC_BWR_CR_ERCLKEN(OSC, 1); //Enables the external reference clock (OSCERCLK)
OSC_BWR_CR_EREFSTEN(OSC, 1); //Controls whether or not the external reference clock (OSCERCLK) remains enabled when the MCU enters Stop mode (0) disables, (1) enabled
However, when I change the core clock to one of the internal clocks (3MHz HIRC, 2MHz LIRC, 8MHZ LIRC), the timers do not quite work properly. This is especially noticeable for the 2MHz and 8MHz internal core clocks. I thought that the timer module would be independent of the core clock when it is running off an external clock. This is obviously not true. So…what affects it? Does the bus clock have anything to do with the TPM generation? It seems from the User’s Manual that the bus clock clocks the peripherals. How does this work?
Any help you can provide would be great!
Thanks,
Sara
Sara Stout-Grandy, M.Eng., Ph.D., P.Eng.
Senior Hardware Designer
20 Angus Morton Dr., Bedford,
NS, Canada, B4B 0L9
902-450-1700, x278