Blinking Led using PIT-module

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Blinking Led using PIT-module

跳至解决方案
958 次查看
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 项奖励
回复
1 解答
710 次查看
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 项奖励
回复
1 回复
711 次查看
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 项奖励
回复