Problem with the interruptions, mcf5329

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

Problem with the interruptions, mcf5329

3,557 Views
VeronicaFNX
Contributor I
Hello,
 
I have a problem with the interruptions. I want to generate an interruption each 1 ms with a timer (PIT0) and i want to turn on a led.
 
I believe that I make all good. I form the timer and I put the interruption,
 
void main
{
 init_interrupt_timers();
 mcf5xxx_irq_enable();
.........
}
 
void init_interrupt_timers (void)
{
    MCF_INTC1_ICR43 = MCF_INTC_ICR_IL(0x07);                      
    MCF_INTC1_IMRH &= ~MCF_INTC_IMRH_INT_MASK43;
 
 
    MCF_PIT0_PCSR = MCF_PIT_PCSR_PRE(0x1) |
                    MCF_PIT_PCSR_PIE      |
                    MCF_PIT_PCSR_RLD      |
                    MCF_PIT_PCSR_EN;
    MCF_PIT0_PMR = MCF_PIT_PMR_PM(0x9c3f);
 
    MCF_PIT1_PCSR = 0;
    MCF_PIT2_PCSR = 0;
    MCF_PIT3_PCSR = 0;
}
I prepare the interrupt vectors,
 
vectorA9: .long         _irq_handler
vectorAA: .long        _irq_handler
vectorAB: .long        _PITimer0_interrupt
vectorAC: .long       _irq_handler
vectorAD: .long       _irq_handler
vectorAE: .long      _irq_handler
 
and the interruption routine is the following one:
 
__interrupt__
void PITimer0_interrupt(void)
{
uint32 i;

 MCF_PIT0_PMR |= MCF_PIT_PCSR_PIF;
 
 MCF_GPIO_PODR_TIMER &= ~MCF_GPIO_PODR_TIMER_PODR_TIMER3;// apaga los leds
 for (i=0; i<0xFFFF; i++);

    MCF_GPIO_PODR_TIMER |= MCF_GPIO_PODR_TIMER_PODR_TIMER3; // enciende los leds
    for (i=0; i<0xFFFF; i++);
}
 
What I am making bad? Please, this is important, i need aid.
 
Thanks
Labels (1)
0 Kudos
Reply
7 Replies

1,129 Views
mccPaul
Contributor I
Hi
 
So this looks OK, but I can see a couple of places where there may be a mistake:
 
When you set up the counter, you should first disable it, and then you clear the interrupt flag and set the overwrite flag to 1 like so:
 
void init_interrupt_timers (void)
{
    MCF_INTC1_ICR43 = MCF_INTC_ICR_IL(0x07);                     
    MCF_INTC1_IMRH &= ~MCF_INTC_IMRH_INT_MASK43;

    MCF_PIT0_PCSR = 0;

    MCF_PIT0_PCSR = MCF_PIT_PCSR_PRE(0x1) |
                    MCF_PIT_PCSR_PIE      |
                    MCF_PIT_PCSR_PIF      |     // Clear interrupt flag
                    MCF_PIT_PCSR_OVW      |     // Set overwrite flag
                    MCF_PIT_PCSR_RLD      |
                    MCF_PIT_PCSR_EN;

    MCF_PIT0_PMR = MCF_PIT_PMR_PM(0x9c3f);

    MCF_PIT1_PCSR = 0;
    MCF_PIT2_PCSR = 0;
    MCF_PIT3_PCSR = 0;
}

 
Then I assume you want to make the LED flash? The way that you have configured the PIT you would expect an interrupt every 1ms, but your ISR has two loops which I assume are so that the LED flashes slowly?
 
This is what happens:
 
Your PIT timer starts counting.
 
After 1ms your ISR is called, as you have set the interrupt level to 7 all interrupts at level 7 and below (in other words _all_ interrupts) are masked.
 
You immediately clear the interrupt, which will start the PIT counter again.
 
You then switch a LED, wait for some time, switch again and wait. After 1ms, the PIT interrupts again, but all interrupts are masked so no problem, even though this is probably not what you expect.
 
Why don't you count the number of times that the interrupt occurs, or set the interrupt to occur at a slower frequency:
 
To get a 1 second flash you could do this:
 
__interrupt__
void PITimer0_interrupt(void)
{
  static uint32 interval = 0;

  MCF_PIT0_PMR |= MCF_PIT_PCSR_PIF;

  interval++;

  if (interval == 1000)
  {
    MCF_GPIO_PODR_TIMER ^= MCF_GPIO_PODR_TIMER_PODR_TIMER3;
    interval = 0;
  }
}


 
Or change the prescaler and modulo to give 1 interrupt every second then you just need this:
 
Code:
__interrupt__
void PITimer0_interrupt(void)
{
  MCF_PIT0_PMR |= MCF_PIT_PCSR_PIF;

  MCF_GPIO_PODR_TIMER ^= MCF_GPIO_PODR_TIMER_PODR_TIMER3;
}



 
 
Paul
0 Kudos
Reply

1,129 Views
VeronicaFNX
Contributor I
Hello,
 
no, that was not the problem.
The problem is that the function of the PIT0 is not compiled. It seems that I do not program the file well vectors.s,
 
#ifdef __GNUC__ /* { */
#define sr %sr
#define _ethernet_handler ethernet_handler
#define _irq_handler      irq_handler
#define _PIT0_handler     PIT0_handler
#endif /* } __GNUC__ */
 .global VECTOR_TABLE
 .global _VECTOR_TABLE
 .global start
 .extern ___SP_INIT
 .extern _asm_startmeup
 .extern _asm_exception_handler
 .extern _irq_handler
 .extern _ethernet_handler
 .extern _ephy_handler
 .extern _PIT0_handler
 .text
 
/*
 * Exception Vector Table
 */
VECTOR_TABLE:
_VECTOR_TABLE:
INITSP:  .long ___SP_INIT    /* Initial SP   */
INITPC:  .long _asm_startmeup   /* Initial PC   */
vector02: .long _asm_exception_handler /* Access Error   */
vector03: .long _asm_exception_handler /* Address Error  */
vector04: .long _asm_exception_handler /* Illegal Instruction */
vector05: .long _asm_exception_handler /* Reserved    */
vector06: .long _asm_exception_handler /* Reserved    */
vector07: .long _asm_exception_handler /* Reserved    */
vector08: .long _asm_exception_handler /* Privilege Violation */
vector09: .long _asm_exception_handler /* Trace    */
vector0A: .long _asm_exception_handler /* Unimplemented A-Line */
vector0B: .long _asm_exception_handler /* Unimplemented F-Line */
vector0C: .long _asm_exception_handler /* Debug Interrupt  */
vector0D: .long _asm_exception_handler /* Reserved    */
vector0E: .long _asm_exception_handler /* Format Error   */
vector0F: .long _asm_exception_handler /* Unitialized Int.  */
vector10: .long _asm_exception_handler /* Reserved    */
vector11: .long _asm_exception_handler /* Reserved    */
vector12: .long _asm_exception_handler /* Reserved    */
vector13: .long _asm_exception_handler /* Reserved    */
vector14: .long _asm_exception_handler /* Reserved    */
vector15: .long _asm_exception_handler /* Reserved    */
vector16: .long _asm_exception_handler /* Reserved    */
vector17: .long _asm_exception_handler /* Reserved    */
vector18: .long _asm_exception_handler /* Spurious Interrupt */
vector19: .long _irq_handler   /* Autovector Level 1 */
vector1A: .long _irq_handler   /* Autovector Level 2 */
vector1B: .long _irq_handler   /* Autovector Level 3 */
vector1C: .long _irq_handler   /* Autovector Level 4 */
vector1D: .long _irq_handler   /* Autovector Level 5 */
*********************
 
vectorAA: .long _irq_handler
vectorAB: .long _PIT0_handler
vectorAC: .long _irq_handler
vectorAD: .long _irq_handler
*****************
 
start:
 move.w #0x2700,sr
 jmp  _asm_startmeup
 .end
What I can be making bad?
 
Thanks
0 Kudos
Reply

1,129 Views
mccPaul
Contributor I
Hi
 
I don't understand - are you seeing compiler or linker error messages?
 
Paul.
0 Kudos
Reply

1,129 Views
VeronicaFNX
Contributor I
Hello Paul,
 
I send you my code and so you can see it and to said me sometihng,.
 
Message Edited by t.dowe on 2009-10-21 02:15 AM
0 Kudos
Reply

1,129 Views
Napoletano
Contributor I
CodeWarrior Version 6.3 generates an STLDSR instruction in the ISR if you declare it with __interrupt__ . According to the Prozessor Errata this instruction doesn't work.
You will get an exception.
To fix this Compiler Error you should declare you ISR with __declspec(interrupt:0)...

__declspec(interrupt:0) void PIT0_handler (void)
{
    MCF_PIT0_PMR |= MCF_PIT_PCSR_PIF;
    MCF_GPIO_PODR_TIMER ^= MCF_GPIO_PODR_TIMER_PODR_TIMER3;
}

You should do this with all running Interupts.
I hope this helps.

BTW. You are toggling the LED also in the Main Loop

Daniel
0 Kudos
Reply

1,129 Views
VeronicaFNX
Contributor I
Hello,
 
I have a problem and I do not see any solution. I have created a new project and
I want an interruption each 1ms and that ignites a LED in the interruption.
 
I try to execute the code but I have an exception in 0xFBAFE9F0.
I no longer that to do because I don't see any error, I think that I am doing everything correctly.
 
Please, I need that somebdy executes my code and says to me if can see some error.
 
I thank for the interest to you because I have been several days with this problem.
 
My code is this one,
 
Message Edited by t.dowe on 2009-10-21 02:14 AM
0 Kudos
Reply

1,129 Views
Kremer
Contributor I
 For interrupt isr´s you need to declare them as so using __declspec(interrupt:0) and not void.
0 Kudos
Reply