AnsweredAssumed Answered

Need help to configure PIT timer

Question asked by Mathieu GOLLNICK on Jun 18, 2012
Latest reply on Jun 20, 2012 by Mathieu GOLLNICK

Hello!

I am new in embedded systems and I try to configure my PIT timer but have some problems.

I work on TWR-K60N512 and I would like to raise an interrupt each 0.5 sec thanks to my timer.

In debug mode I stop correctly on my breakpoints in the function isr_PIT2 (which manage the interrupt).

But when I run my code in normal mode, it doesn't seem to be working.

This is what I did already : 

 

void main(void)
{


disable_watchdog();

// Enable clock for port A
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;

//Set PTA10 (connected to LED's) for GPIO functionality
PORTA_PCR10 = (0|PORT_PCR_MUX(1));

//Change PTA10 in output mode
GPIOA_PDDR = GPIO_PDDR_PDD(GPIO_PIN(10));

//Enable external clock (50mhz)
OSC_CR |= OSC_CR_ERCLKEN_MASK;

//Select system oscillator for MCGCLKSEL
SIM_SOPT2 &= ~SIM_SOPT2_MCGCLKSEL_MASK;


//
MCG_C1 |= MCG_C1_CLKS(0x2);

//Divide frequency by 10 on OUTDIV2 (bus clock)
SIM_CLKDIV1 |= SIM_CLKDIV1_OUTDIV2(0xA);

//*************************** PIT *************************************

//Activate PIT clock in SIM_SCGC6
SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

//Turn on PIT timer

PIT_MCR &= ~PIT_MCR_MDIS_MASK;


//Timer will stop in debug mode
PIT_MCR |= PIT_MCR_FRZ_MASK;


// Timer 2
PIT_LDVAL2 = 0x26259F; //2 500 000 - 1


// TIF = Time Interrupt flag. Is cleared by writing it with 1.
PIT_TFLG2 = PIT_TFLG_TIF_MASK;


NVICIP70 = 0x30; //Set priority 3 
NVICICPR2|=(1<<6);//Clear any pending interrupts
NVICISER2|=(1<<6);//Enable interrupts


PIT_TCTRL2 = PIT_TCTRL_TIE_MASK;
PIT_TCTRL2 |= PIT_TCTRL_TEN_MASK;




while(1)
{


}


}


void disable_watchdog()
{
asm(" CPSID i");
/* Write 0xC520 to the unlock register */
WDOG_UNLOCK = 0xC520;
/* Followed by 0xD928 to complete the unlock */
WDOG_UNLOCK = 0xD928;
/* enable all interrupts */
asm(" CPSIE i");
/* Clear the WDOGEN bit to disable the watchdog */
WDOG_STCTRLH &= ~WDOG_STCTRLH_WDOGEN_MASK;
}

 

//********************************Interrupt code************************

 

(tIsrFunc)isr_PIT2,

 

void isr_PIT2(void)
{
PIT_TFLG2 = 0x01;

//Toggle blue LED on each interrupt
GPIOA_PTOR|=GPIO_PDOR_PDO(GPIO_PIN(10));
}


 

Thanks for your help

Outcomes