Forum Discussion

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

gpio input and output

I have a de2-115 board and i'm trying to do some basic functions but i'm hitting a roadblock.

I used SOPC builder to create a system that has nios ii, two PIO interfaces where one is input and the other is output (2 bits each) and the sysid interface.

Basically what i'm trying to do is retrieve an input from the GPIO (two pins that I chose), check whether they're high or low then send high or low to the output pins.

My baby steps so far:

-in the main verilog file (projectname.v) I declared the GPIO port:

inout [35:0] GPIO;

-in the structural part I picked the pins I'm going to use as in and out. outputa and inputa are the PIO interfaces. I hope that concatenation is correct

.out_port_from_the_outputa({GPIO[5],GPIO[7]}),

.in_port_to_the_inputa({GPIO[1],GPIO[3]})

-all pins are assigned correctly using the pin editor (confirmed)

-everything compiles fine at this point

-now in eclipse NIOS II IDE I want to do the basic functions that I outlined above. I want to take the signals at pins 1 and 3 of the GPIO, play around with them (not important) then send signals to GPIO pins 5 and 7. I'm a complete noob though and can't wrap my head around this. I've coded in C before but this is going right over my head. I know this should be extremely simple.

Any pointers?

8 Replies

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

    You need to include <altera_avalon_pio_regs.h> in your code and you can use the IORD_ALTERA_AVALON_PIO_DATA(base) and IOWR_ALTERA_AVALON_PIO_DATA(base, data) macros to read/write to/from your PIO ports.

    base is the component's base address, that you can find in the system.h file generated with the BSP.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok that i understood and it pointed me in the right direction for something else. Thank you.

    Going on, I want to detect change on the 2 input signals and after further reading I understand that I may have to use the edge-capture register (is that correct?). Now this isn't some high speed application, so timing isn't a huge issue. All I want to do is detect the change and go from there.

    I know i'm going to have to do pretty much the same as you've mentioned and use the IOWR_ALTERA_AVALON_PIO_EDGE_CAP? Of course I have to do the same as for the data one and find the base address...etc. Anything I should keep in mind or is this on the right track?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes. You can either detect the change in software (i.e. read the pio and compare with a provious value stored in a variable) or enable the edge detection options in SOPC builder and use the IOWR_ALTERA_AVALON_PIO_EDGE_CAP macro.

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

    Hey guys !

    I am using THDB_ADA daughter card G.P.I.O and the DE2-115 to design a monitoring unit to measure signals coming out from a signal generator . I am still new at using the THDB_ADA daughter card G.P.I.O and in early stages of testing the demo code !!!

    I downloaded the THDB_ADA daughter card CD Rom from the Altera website, the demonstration for De2-115 has pin assignments for ADA HSMC :(

    I needed the pin assignments for ADA GPIO connecting De2-115 board , to test the demo code just to get the feel of using the ADA !!! People who have done the pin assignments for the ADA GPIO I really need your'e help !!!

    Thanks in advance :)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    use the system builder included on the cd, it does all the pin assignments for you

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

    Thanks for the suggestion :) Well i did use system builder for pin generation but for De2-115 it generates pin assignments for ADA HSMC ( which i am using in my project, but i needed pin assignments for ADA GPIO) . Eventually i had to do it the hard way by doing it manually in the assignment editor.

    But now I am facing problems with the S.O.P.C builder !! I want to read/write values from the GPIO port to the SD RAM through SGDMA( Scatter Gather DMA) and display it on the touch interface. However the SOPC builder wouldn't let me read/write or connect the GPIO to the SD RAM ( read PIO interface). But the demonstration has SOPC builder built in such a way that SD RAM is accessed through the pixel FIFO( which i wont be using in my project)

    So my question is how do you instantiate ADA GPIO in the SOPC builder ??? In such a way that i can read the data out from the GPIO to the SD RAM and finally display on tPad and vice-versa from SD RAM to ADA GPIO to display on an oscilloscope!! I am really confused how to do it ... I tried all possible ways but i failed :( I hope you can help me out with this since you guys have experience doing these :(
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Lol !!! Thanks for sparing your time and going through my problem !!:) Really appreciate that !! Have you used the GPIO port to connect the ADA daughter board???? In that case I will really be pleased if you could send me a snap shot of your SOPC !!! Thanks a ton :)

    Regards !!