11 years ago.

Can anyone tell me why I don't seem to be getting any PIT interrupts?

!!!!!!!!!!!! sorry - posted twice - too long at the computer :>( !!!!!!!!!!!!!!!!!!!!!

  1. include "mbed.h"

extern void PIT_IRQHandler();

unsigned char Iflag;

DigitalOut myled(LED1); blue DigitalOut intled(LED2); green

void baud(int baudrate) { Serial s(USBTX, USBRX); s.baud(baudrate); }

void pit_init(void) PIT Initialization { SIM->SCGC6 |= SIM_SCGC6_PIT_MASK; Enable the clock to the PIT module

NVIC_SetVector(PIT_IRQn, (uint32_t)PIT_IRQHandler);

NVIC_EnableIRQ(PIT_IRQn); Initialize the NVIC to enable the PIT interrupt

PIT->MCR = 0X00; turn on the PIT

PIT->CHANNEL[0].TFLG = PIT_TFLG_TIF_MASK; Reset the Timeout Flag

PIT->CHANNEL[0].LDVAL = 80000000; Default start value 1.6 sec.

PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TIE_MASK; Enable timer PIT->CHANNEL[0].TCTRL |= PIT_TCTRL_TEN_MASK; Enable timer interrupt

Iflag = 0; }

void PIT_IRQHandler() { PIT->CHANNEL[0].TCTRL = 0; Disable timer PIT->CHANNEL[0].TFLG = PIT_TFLG_TIF_MASK; Clear the timer interrupt flag PIT->CHANNEL[0].TCTRL |= PIT_TCTRL_TEN_MASK | PIT_TCTRL_TIE_MASK; Enable timer

Iflag = 1; }

int main() {

myled = 1; blue intled = 1; green

baud(57600); printf("Starting PIT test\n\r");

pit_init();

while(1) { if (Iflag == 1) { Iflag = 0; myled = 1; turn off blue led intled = 0; flash green led printf("PIT\n\r"); wait(0.9); intled = 1; }

myled = !myled; toggle blue led wait(0.9); } }

2 Answers

11 years ago.

Hello ,

the default timer used by mbed for KL25Z is PIT & lptmr timers, thus during the first call wait(), PIT gets initialized (disables PIT interrupts). Comment out wait() calls, if you initialized PIT & interrupts properly, isr should be invoked. What do you want to achieve? There's timer API where you can attach a function.

Regards,
0xc0170

11 years ago.

Hi, Thanks for your response.

This is just a simple test program to help me understand how to use the PIT timer. My goal is to have a program that will send a trigger pulse to another logic board, which captures data. And then read the captured data at a later time. The trigger pulse needs to be precisely timed, at rates up to about (hopefully) 25 MHZ. It appeared to me that the PIT would be able to do this.

Is there a better way to do what I am trying to do?

Are you saying that because I am using mbed tools that the PIT is not available for use? Or is only available if I don't use the wait call?

Your statement "if you initialized PIT..." seems to say that I haven't initialized properly. If so, can you show me what I should do differently? Interrupt setup and handling seems to be a very under-documented area.

Can you please also point me to the timer API? I haven't come across it in my searching for interrupt documentation.

Thanks again. Herschel