I need to generate slow PWM across the range of 20-150 Hz. I've found that the IRC of 2Mhz (kMCGLITE_Lirc2M) is still too fast to get that slow. So I'm attempting to use an external oscillator. I've used the NXP Clocks tool to generate my clock init. However I do not see any ouput when I switch the clock source. Attached are oscope snaps showing my 32khz external clock is working, and that pwm works when using internal clocks. I've attempted this on my own board as well as the KL27 Freedom Board.
/*******************************************************************************
* Code for BOARD_BootClockRUN configuration
******************************************************************************/
void BOARD_BootClockRUN(void)
{
/* Set the system clock dividers in SIM to safe value. */
CLOCK_SetSimSafeDivs();
/* Initializes OSC0 according to board configuration. */
CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
/* Set MCG to HIRC mode. */
CLOCK_SetMcgliteConfig(&mcgliteConfig_BOARD_BootClockRUN);
/* Set the clock configuration in SIM module. */
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}
PWM Code:
#define TPM_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_Osc0ErClk) // HERE
#define BOARD_TPM_BASEADDR TPM0
#define BOARD_FIRST_TPM_CHANNEL 3U
#define IRC_CLOCK_MUX 0x3
#define OSCERCLOCK_MUX 0x2
#define MCGPCLK 0x1
tpmParam.chnlNumber = (tpm_chnl_t)BOARD_FIRST_TPM_CHANNEL;
tpmParam.level = kTPM_HighTrue;
tpmParam.dutyCyclePercent = 40;
CLOCK_SetTpmClock(OSCERCLOCK_MUX); // HERE MCGPCLK
TPM_GetDefaultConfig(&tpmInfo);
TPM_Init(BOARD_TPM_BASEADDR, &tpmInfo);
TPM_SetupPwm(BOARD_TPM_BASEADDR, &tpmParam, 1U, kTPM_EdgeAlignedPwm, frequency_hz, TPM_SOURCE_CLOCK);
TPM_StartTimer(BOARD_TPM_BASEADDR, kTPM_ExternalClock); // kTPM_SystemClock // HERE
TPM_UpdatePwmDutycycle(BOARD_TPM_BASEADDR, (tpm_chnl_t)BOARD_FIRST_TPM_CHANNEL, kTPM_EdgeAlignedPwm,
40);
while(1)
{
}