Blinking Led using PIT-module

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Blinking Led using PIT-module

Jump to solution
882 Views
rohananand
Contributor II

Hello,

I am trying to blink the on-board red led using the PIT-module.The code is as follows:

#include "MKL46Z4.h"

void initPITM(void)

{

  PIT_MCR= 0x00000000;//Module enable

}

void delay()

{

  PIT_LDVAL0=0x00FFFFFF;//Value of timer 0

  PIT_TCTRL0=0x00000001;//Timer enable

  while((PIT_TFLG0 & 0x00000001)==0)

  {

  }

}

void initLEDR()

{

  SIM_SCGC5=SIM_SCGC5_PORTE_MASK;

  PORTE_PCR29=256;

  GPIOE_PDDR=1u<<29;

}

int main(void)

{

     initLEDR();

     initPITM();

     while(1)

     {

     GPIOE_PDOR=0u<<29;

     delay();

     GPIOE_PDOR=1u<<29;

     delay();

     }

    return 0;

}

When I am debugging this code,it goes to PIT_MCR=0x00000000; and then goes to handler.

Please help.I am unable to find whats wrong with the code?

It goes here and then oscillates back and forth.

ldrr0, =DefaultISR

    bx r0

0 Kudos
1 Solution
634 Views
mjbcswitzerland
Specialist V

Hi

Before

PIT_MCR= 0x00000000;//Module enable

you need

SIM_SCGC6=SIM_SCGC6_PIT_MASK;

Some chips have an errate [ID7914] where there needs to be also a short delay between enabling the PIT clocks and enabling the module.

SIM_SCGC6=SIM_SCGC6_PIT_MASK;

(void)PIT_MCR; // dummy read of PIT_MCR to guaranty a minimum delay of two bus cycles after enabling the clock gate and not losing next write

PIT_MCR = 0;

Regards

Mark

View solution in original post

0 Kudos
1 Reply
635 Views
mjbcswitzerland
Specialist V

Hi

Before

PIT_MCR= 0x00000000;//Module enable

you need

SIM_SCGC6=SIM_SCGC6_PIT_MASK;

Some chips have an errate [ID7914] where there needs to be also a short delay between enabling the PIT clocks and enabling the module.

SIM_SCGC6=SIM_SCGC6_PIT_MASK;

(void)PIT_MCR; // dummy read of PIT_MCR to guaranty a minimum delay of two bus cycles after enabling the clock gate and not losing next write

PIT_MCR = 0;

Regards

Mark

0 Kudos