PIT not working

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

PIT not working

6,753 Views
airswit
Contributor III
hey everyone,

I am trying to get a PIT to interrupt, so that I can sample a quadrature encoded signal. I have used the following code to initialize the timer:

void quad_gpt_setup(void)
{
MCF_PIT0_PMR = MCF_PIT_PMR(70); //set modulus to 2!!
MCF_PIT0_PCSR = 0
| MCF_PIT_PCSR_PRE(0xA)
| MCF_PIT_PCSR_PIE
| MCF_PIT_PCSR_EN
| MCF_PIT_PCSR_RLD; //enable PIT (32768 prescaler, interrupts)
}


and have called this before an empty while loop within main. now, I have created a handler for it:

__interrupt__ void quad_handler(void)
{
board_led_display((MCF_GPIO_SETTA & 0x03));
MCF_PIT0_PCSR &= 0xFFFE; //clear the interrupt
}

and initialized the interrupt as follows, in the main:

mcf5xxx_set_handler(64 + 55,quad_handler);


now, this is not working for me. The system sits in the infinite loop, and this is bad. do I need to set up any other registers, or is there an error in my code anywhere, or what?

another question i have is whether i can use a GPT for this purpose if I am using their pins as digital I/O. if so, how do i set this up? specifically, do i select output compare or input capture mode, or does it matter?

any help would be appreciated!

Thanks,

Trevor

p.s. if it matters, I am using a MCF5213, specifically the M5213EVB...

Message Edited by airswit on 04-04-200602:08 AM

Labels (1)
0 Kudos
Reply
4 Replies

1,255 Views
thz
Contributor I
Did you setup the interrupt controller?
0 Kudos
Reply

1,255 Views
airswit
Contributor III
well, I am not too sure what all I have to set up. to get the edge port interrupts to work was real simple, i just used:

MCF_EPORT_EPPAR = 0
| MCF_EPORT_EPPAR_EPPA1_RISING
| MCF_EPORT_EPPAR_EPPA4_RISING
| MCF_EPORT_EPPAR_EPPA5_RISING
| MCF_EPORT_EPPAR_EPPA7_LEVEL;
mcf5xxx_set_handler(64 + 4, sw1_handler);
mcf5xxx_set_handler(64 + 5, sw2_handler);
mcf5xxx_set_handler(64 + 7, abort_handler);
mcf5xxx_irq_enable();

and that got me running on the three buttons on the eval board. now, i have tried to set up the PIT0 interrupt likewise with:

mcf5xxx_set_handler(64 + 55,quad_handler);
MCF_INTC_ICR55 = 0
| MCF_INTC_ICR_IP(6)
| MCF_INTC_ICR_IL(6); //set priorities
mcf5xxx_irq_enable();

but as of now, the system is stuck (not interrupting like it should). when i debug the program, it sits in the main loop, it is not like it runs to a bad address or something. I am using codewarrior v6.2, and I have attached my whole file for you (a little bloated, but hopefully that helps more than the cutting/pasting!)

Thanks again,

Trevor
0 Kudos
Reply

1,255 Views
airswit
Contributor III
update:

I can get it to interrupt once while in debug mode. but, i am not sure that it is interrupting when i 'run' the code (choose run rather than debug in codewarrior). I achieved this by clearing the INT_MASK[55] bit in the IMRH. my 'main' code is now this:

int main()
{
MCF_EPORT_EPPAR = 0
| MCF_EPORT_EPPAR_EPPA1_RISING
| MCF_EPORT_EPPAR_EPPA4_RISING
| MCF_EPORT_EPPAR_EPPA5_RISING
| MCF_EPORT_EPPAR_EPPA7_LEVEL;
mcf5xxx_set_handler(64 + 4, sw1_handler);
mcf5xxx_set_handler(64 + 5, sw2_handler);
mcf5xxx_set_handler(64 + 7, abort_handler);
mcf5xxx_set_handler(64 + 55,quad_handler);
MCF_INTC_ICR55 = 0
| MCF_INTC_ICR_IP(6)
| MCF_INTC_ICR_IL(6); //set priorities
MCF_INTC_IMRH &= ~MCF_INTC_IMRH_MASK55;

mcf5xxx_irq_enable();

quad_gpt_setup();
check_quadrature();
}


can anyone see anything in my code that will prevent it from interrupting continuously, like it should?
0 Kudos
Reply

1,255 Views
thz
Contributor I
> can anyone see anything in my code that will prevent it
> from interrupting continuously, like it
> should?

yes, in your interrupt service the PIF-Bit has to be set, not reset!

i.e.: MCF_PIT_PCSR(PIT) |= MCF_PIT_PCSR_PIF;

cheers, Thomas
0 Kudos
Reply