Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

interrupt problem

Hi all,

i've modified the DE2 Media Computer demo, in order to register\play 2 different messages.

It works fine.

Then i've tried to add a blinking led adding an interval timer(period 1 sec, simple periodic interrupt) in my SOPC, but i've some problem with it:

- it blinks, but faster than 1 sec, and every 3 blinks, 1 is faster than the others

- when i press a button, it stops blinking until i relese the button

I supposed that it was related with the IRQ number in SOPC builder, and i changed it to 0 for my interval timer...anything changed...

my code is:

# ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
    static void alt_avalon_timer_sc_irq (void* base)# else
    static void alt_avalon_timer_sc_irq (void* base, alt_u32 id)# endif
{
  alt_irq_context cpu_sr;
  // clear the interrupt
  IOWR_ALTERA_AVALON_TIMER_STATUS (base, 0);
  illu_led = !illu_led; //switch a flag
  /*
   * Dummy read to ensure IRQ is negated before the ISR returns.
   * The control register is read because reading the status
   * register has side-effects per the register map documentation.
   */
  IORD_ALTERA_AVALON_TIMER_CONTROL (base);
  // ALT_LOG - see altera_hal/HAL/inc/sys/alt_log_printf.h
  // ALT_LOG_SYS_CLK_HEARTBEAT();
  /*
   * Notify the system of a clock tick. disable interrupts
   * during this time to safely support ISR preemption
   */
  cpu_sr = alt_irq_disable_all();
  alt_tick ();
  alt_irq_enable_all(cpu_sr);
}
//-----------------------------------------------------
void alt_avalon_timer_sc_init (void* base, alt_u32 irq_controller_id,
                                alt_u32 irq, alt_u32 freq)
    {
      // set the system clock frequency
      alt_sysclk_init (freq);
      // set to free running mode
      IOWR_ALTERA_AVALON_TIMER_CONTROL (base,
                ALTERA_AVALON_TIMER_CONTROL_ITO_MSK  |
                ALTERA_AVALON_TIMER_CONTROL_CONT_MSK |
                ALTERA_AVALON_TIMER_CONTROL_START_MSK);
      // register the interrupt handler, and enable the interrupt
# ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
      alt_ic_isr_register(irq_controller_id, irq, alt_avalon_timer_sc_irq,
                      base, NULL);# else
      alt_irq_register (irq, base, alt_avalon_timer_sc_irq);# endif
    }
and in my main function, inside while(1):

 
       IOWR_ALT_UP_PARALLEL_PORT_DATA( RED_LEDS_BASE, illu_led);

someone can help?
No RepliesBe the first to reply