Blinking Led using PIT-module

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Blinking Led using PIT-module

ソリューションへジャンプ
997件の閲覧回数
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

ラベル(2)
0 件の賞賛
返信
1 解決策
749件の閲覧回数
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 返信
750件の閲覧回数
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 件の賞賛
返信