- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 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); }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fischer, http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
thanks,I will try to use IRQ1,and use edg. the LED is OK in normal test(It can lights and blank),and I will let it blank in the interrupt test program when the irq not generate!.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 .- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif
I also found that there is a weird problem: the instruction : //r2=10 WRCTL ienable,r2 ........ but after this instructon ,I traced the debug in disassumbly,the ienable didn't change. can anyone help!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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'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's edge capture register in *context. *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); // Reset the Button'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++; }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fischer,
I really thank you a lot. I will do exactly as you did. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 'fall edge';I 'rise edge' ),and some I think less important set. all in all.thank you a lot! Best wishs.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have met the same problem before.
So far, I don't know the root reason cause this issue. I just try to modify the IRQ, and sometimes it works, sometimes not...
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page