Forum Discussion

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

40 pin gpio connector

hello

how i can use the 40 pin gpio of a de2 cyclone 4 as an input and output?

can it be added in qsys?

thanks

10 Replies

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

    If you wish to instantiate them via Qsys then you can put down one (or more) PIO (Parallel I/O) peripherals. These can be configured as input, output or bidirectional signals which can be routed out of the FPGA to the GPIO connector.

    Regards,

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

    thanks alex

    then how can i used the pins 1-15 as an input and 16-30 pins as an output if i used the systembuilder of the de2 board?

    thanks again :)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I'm afraid I'm not familiar with the systembuilder that comes with the DE2 board. However, referring to your original question, it is very possible, using Qsys, to instantiate 2 (or more) PIO modules to give you the two sets of input and output signals you need.

    Regards,

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

    I'd like to add that not all pins are IO. Some are just I, and others are just O. If I remember correctly.

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

    hi this is an interfacing between lcd and a keypad. am i doing it right? then this will be done in nios II

    this is the code generated using qsys plus a code for keypad from tear086

    //=======================================================

    // This code is generated by Terasic System Builder

    //=======================================================

    module testingx(

    //////////// CLOCK //////////

    CLOCK_50,

    CLOCK2_50,

    CLOCK3_50,

    //////////// LED //////////

    LEDG,

    LEDR,

    //////////// KEY //////////

    KEY,

    //////////// EX_IO //////////

    EX_IO,

    //////////// SW //////////

    SW,

    //////////// LCD //////////

    LCD_BLON,

    LCD_DATA,

    LCD_EN,

    LCD_ON,

    LCD_RS,

    LCD_RW,

    //////////// GPIO, GPIO connect to GPIO Default //////////

    GPIO

    );

    //=======================================================

    // PARAMETER declarations

    //=======================================================

    //=======================================================

    // PORT declarations

    //=======================================================

    //////////// CLOCK //////////

    input CLOCK_50;

    input CLOCK2_50;

    input CLOCK3_50;

    //////////// LED //////////

    output [8:0] LEDG;

    output [17:0] LEDR;

    //////////// KEY //////////

    input [3:0] KEY;

    //////////// EX_IO //////////

    inout [6:0] EX_IO;

    //////////// SW //////////

    input [17:0] SW;

    //////////// LCD //////////

    output LCD_BLON;

    inout [7:0] LCD_DATA;

    output LCD_EN;

    output LCD_ON;

    output LCD_RS;

    output LCD_RW;

    //////////// GPIO, GPIO connect to GPIO Default //////////

    inout [35:0] GPIO;

    //=======================================================

    // REG/WIRE declarations

    //=======================================================

    wire keyboard_val;

    matrixKeyboard_drive (

    .i_clk(CLOCK_50),

    .i_rst_n(1),

    .row(GPIO[3:0]), // ???? ?

    .col(GPIO[7:4]), // ???? ?

    .keyboard_val(keyboard_val) // ???

    );

    //=======================================================

    // Structural coding

    //=======================================================

    assign LCD_BLON = 1'b1;

    assign LCD_ON = 1'b1;

    testingX (

    .pio_led_external_connection_export(LEDG), // pio_led_external_connection.export

    .pio_sw_external_connection_export(SW), // pio_sw_external_connection.export

    .lcd_0_external_data(LCD_DATA), // lcd_0_external.data

    .lcd_0_external_E(LCD_EN), // .E

    .lcd_0_external_RS(LCD_RS), // .RS

    .lcd_0_external_RW(LCD_RW), // .RW

    .reset_reset_n(1), // reset.reset_n

    // pio_in_gpio_external_connection.export

    .clk_clk(CLOCK_50), // clk.clk

    .pio_out_gpio_solenoid_external_connection_export(GPIO[15:13]), // pio_out_gpio_solenoid_external_connection.export

    .pio_out_gpio_buzzer_external_connection_export(GPIO[18:16]) // pio_out_gpio_buzzer_external_connection.export

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

    Have you got something working yet?

    I see the code you posted was generated using Terasic's system builder - rather than Qsys. There isn't enough info there to determine if it'll work or not. The way it's hooked together is valid, that's about all I can determine from that...

    Cheers,

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

    as of now i don't have because i'm having hard time programming it in eclipse cause i'm not that familiar in programming using c or c++.

    thanks for checking it.

    oh yes it was from terasic systembuilder because the qsys generated was too long so i just have to get a portion of it to put it in my top module and this is the code for the keypad.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hi alex,

    how can i do it in eclipse?

    this is the project i want to accomplish. i have a 4x3 keypad that will serve as a source for my password that will display in the lcd then when the password is correct the solenoid will open or close but if the password is wrong the buzzer will buzz. the solenoid and buzzer are connected to gpio and the keypad also is connected to gpio.

    can you give me a pattern or something i can use to finish this project. thank you.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I think you're getting confused as to what to use to do what you want.

    If you want to develop C code, in Eclipse, I recommend you use the standard PIO peripheral - where we started with this thread. You can then develop your application entirely in C code, within the Eclipse environment. This way there would be no need for any custom rtl.

    The rtl you posted could be used (subject to it working, I've not checked it ;)) if you want to capture the keystrokes in hardware - a commendable way of solving this. However, if you then wish to use this code as a Nios peripheral then you will need to add an appropriate interface to that code.

    Or, you could use your rtl to drive a PIO peripheral set as 4-bit, input only, driven by the 'keyboard_val' signal from your rtl.

    Rhetorical question: What are you most comfortable coding? If you're happy writing rtl do it that way, minimisung the amount of C code you have to write. If you prefer writing C, use qsys/systembuilder to implement the logic and write the solution in C, within Eclipse.

    Regards,

    Alex