Forum Discussion

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

HELP,I can't generate Hardware interrupt

I need help,please

What I want is : When I press a button ON Board, Nios Let LEDs lights.Of course,the LEDs is turned off before.(The board is DIY,Just a cyclone ep1c3t144c8 without flash and sdram.I download program to On_chip 4K ram for test. this is a test board,later I will make Nios with flash and sdram on PCB.SO,thanks for advice!!)

the Problem is,Software is make just like nios example: nios\examples\software\count_binary

software:

static void handle_button_interrupts(void* context, alt_u32 id)

{

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(0x1820, 0);

//0x1820 is the addbase, input of my button for interrupts

//problem is not getin here,I put breakpoint here,but never stop!

IOWR_ALTERA_AVALON_PIO_DATA(0x1830,0xf);//Let leds light!

// 0x1830 is the addbase of leds

}

int alt_main (void)

{

alt_u8 led = 0x00;

alt_u16 i=0x0;

alt_u16 j=0x0;

alt_u8 inbit;

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(0x1820, 0xf);

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(0x1820, 0x0);

j=alt_irq_register( 0, 0, handle_button_interrupts );

//The first para is 0:the IRQ on SOPC,I set it as 0

//the 2nd para is 0: the number to interrupt ,I set it 0

//the 3rd para is handle_button_interrupts:my interrupt gate!

//I set breakpoint here,after this instruction ,j gets 0.it indicate that registe success!

......

the NIos developer's handbook says: Button is pressed, generating an IRQ.

But when I press the button,Irq didn't generate!!

The step I make SOPC:

In SOPC,When I set key_in_pio,(IP is PIO),

1.In the first Dialog window,Width set "1"bits.and choose"Input ports only."

2.In the 2nd Dialog window,I just let it Generate IRQ, I choose "Level".then Pressed finish.

Then in the main window,I set pio's IRQ as"0";

other IP:cpu,led pio,key_in_pio,onchip memory_0;

Out of the FPGA,I let a Key to triger .When I press button,the level is 3.3v;otherwise the level is 0v;

Thanks for spending time on reading this.

8 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    - better to use edge triggered interrupts in your input pio

    - i don't know if you need a system timer, this normally

    has IRQ0 assigned.

    does your program runs normal in debugger

    e.g let a led blink in while loop ?

    ..

    ..

    while(1) {

    usleep(100000);

    led ^= 0x01;

    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,led);

    }
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Fischer,

    I am afraid ,I also can't get IRQ.

    I found that "status" is always '0'.it means IE is not enable.

    I thought the register can enable IE,I don't know I miss what .
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello TommyCP,

    i tried the following in an ep1c3t144 chip, quartus 5.1 nios 5.1,

    and it works as expected.

    in to schematic i have:

    input clk : 50Mhz

    input reset_n , connected to VCC in fpga

    inport button [7..0] (PIO_0)

    outport led [7..0] )PIO_1)

    cpu nios II/e

    jtag debug module: 0x00..0x7ff

    onchip memory 4k

    add: 0x1000..0x1fff

    pio_0 8 bit input only,sync capture faling edge, generate irq edge

    add: 0x800 irq:0

    pio_1 8 bit output only

    add: 0x810

    uses hello world small as start and modified it as following

    switch on input 0 generates irq and toggles output 1

    output 0 is toggled in while loop

    program compiles:

    make -s all

    Compiling hello_world_small.c...

    ../hello_world_small.c: In function `main':

    ../hello_world_small.c:88: warning: passing arg 2 of `alt_irq_register' discards qualifiers from pointer target type

    Linking hello_world_small_1.elf...

    Info: (hello_world_small_1.elf) 2080 Bytes program size (code + initialized data).

    Info: 2016 Bytes free for stack + heap.

    Post-processing to create onchip_memory_0.dat

    Post-processing to create onchip_memory_0.hex

    Post-processing to create onchip_memory_0.sym

    Build completed

    # include <stdio.h># include <unistd.h> // usleep()# include "system.h"# include "sys/alt_irq.h"# include "altera_avalon_pio_regs.h"

    static void handle_button_interrupts(void* context, alt_u32 id);

    volatile alt_u8 led=0;

    /* A variable to hold the value of the button pio edge capture register. */

    volatile int edge_capture;

    volatile int irq_count;

    # define BUTTON_PIO_BASE PIO_0_BASE# define BUTTON_PIO_IRQ PIO_0_IRQ# define LED_PIO_BASE PIO_1_BASE

    int main()

    {

    // Enable all 4 button interrupts.

    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);

    // Reset the edge capture register.

    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);

    // Register the interrupt handler.

    alt_irq_register( BUTTON_PIO_IRQ,&edge_capture, handle_button_interrupts );

    while(1) {

    usleep(100000);

    led ^= 0x01;

    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,led);

    }

    return 0;

    }

    static void handle_button_interrupts(void* context, alt_u32 id)

    {

    // Cast context to edge_capture&#39;s type. It is important that this be

    // declared volatile to avoid unwanted compiler optimization.

    //

    volatile int* edge_capture_ptr = (volatile int*) context;

    // Store the value in the Button&#39;s edge capture register in *context.

    *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);

    // Reset the Button&#39;s edge capture register.

    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);

    led^=0x02;

    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,led);

    // irq_count++;

    }
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Fischer,

    I actually works as expects,thanks a lot.

    now the instruction

    "WRCTL ienable,r2"

    works,It can enable IRQ.

    the difference between us:

    you uses "hello world small" as start,while I use"hello led".

    other different like :memory addr,input triger(you use &#39;fall edge&#39;;I &#39;rise edge&#39; ),and some I think less important set.

    all in all.thank you a lot!

    Best wishs.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have met the same problem before.

    So far, I don&#39;t know the root reason cause this issue.

    I just try to modify the IRQ, and sometimes it works, sometimes not...