AnsweredAssumed Answered

Enabling the 32 kHz MCGIRCCLK on KL25Z Freedom Board?

Question asked by exgreyfox on Jun 18, 2015
Latest reply on Jun 19, 2015 by exgreyfox

Hello,

 

I am new to freescale controllers and I am playing around with making delays using TPM0 module. I am not using PE, just doing baremetal coding. I would like to use the MCGIRCCLK to be the source clock for the TPM0 module bit I can't seem to get it to kick in. I am aware of the different FEI, BLPI, etc... clock state modes but am unsure how to manipulate them. I am writing a small piece of code to create a delay for the Blue LED. Here is my code. Thank you for any help.

 

P.S. I am running on CodeWarrior 10.6

 

#include "derivative.h" /* include peripheral declarations */

#define BLUE_LED_LOC (1<<1)
#define MCG_IRC_CLK 0x03000000
#define BLUE_LED_ON   GPIOD_PCOR = BLUE_LED_LOC
#define BLUE_LED_OFF   GPIOD_PSOR = BLUE_LED_LOC
#define BLUE_LED_TOGGLE GPIOD_PTOR = BLUE_LED_LOC

void Blue_LED_Init(void);
void TPM0_Init(void);

int main(void)
{
  Blue_LED_Init();
  TPM0_Init();

  for(;;) {  
  while((TPM0_SC & 0x80) == 0) {}
  TPM0_SC |= 0x80;
  BLUE_LED_TOGGLE;
  }
  return 0;
}

/* 
 * Initialise the Blue LED (PTD1)
 * 
 */
void Blue_LED_Init(void)
{
  SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;  /* Turn on clock to PortD module */
  PORTD_PCR1 = PORT_PCR_MUX(1); /* Set the PTD1 pin multiplexer to GPIO mode */
  GPIOD_PDDR |= BLUE_LED_LOC; /* Set the pins direction to output */
  GPIOD_PSOR = BLUE_LED_LOC; /*Turn off Blue LED*/
}

/* 
 * Initialise TPM0
 * 
 */
void TPM0_Init(void)
{
  SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK; /* Enable clock to TPM0 module */
  SIM_SOPT2 |= 0x03000000; /* Source clock to TPM0 module PLL select, MCGPLLCLK/2 */
  TPM0_SC |= 0x00; /* Disable timer/counter during configuration, set up for up-counter */
  TPM0_SC |= 0x02; /* Set Prescalar to DIV by 128 */
  TPM0_MOD = 40960 - 1; /* Max modulous  */
  TPM0_SC |= 0x80; /* Clear TOF flag */
  TPM0_SC |= 0x08; /* Enable counter free running mode */
}

Outcomes