Electronics - Verilog - Blinking a LED with GPIOs

As you certainly liked this Altera DE1 tutorial for blinking a LED on the board, you will love this one by doing the same easy thing but with GPIOs.

I'm sure you are really excited about that. So let's go.

Explanation

On the DE1 board, there are many GPIOs.

What is a GPIO? --> GPIO stands for General Purpose Input Output.

It's a group of pins that you can set to input or output individually.

It means that when a pin is set to ouput and when you send a 0 or a 1 on it, you can get this value outside the board.

And when it's input, you get data from outside.

In this tutorial we are going to use output direction.

On the DE1 board, there are 2 GPIOs:

  • GPIO_0
  • GPIO_1

As you can see from the video, there are two green LEDs plugged to the breadboard (on the right).

Each green LED is paired with a 150 ohm resistor.

The black wire is the GND that I've taken from GPIO_0[11] and the red wire is the VCC (+3V) taken from GPIO_0[28].

This first green LED is just here to say there is a current through the breadboard.

Then I've taken a green wire to connect the + of the second LED to the GPIO_1[0].

It could be a bit difficult to understand that, especially because on the DE1_Schematics (that you can find easily on Internet) the first pin starts from 1 and not 0.

Furthermore we use CLOCK_24[1] instead of the famous CLOCK_50.

Code

// module blink_led_gpio

module blink_led_gpio(

    input wire [1:0] CLOCK_24,
    output wire [35:0] GPIO_1
    
);

    // reg
    reg [32:0] counter;
    reg turn;
    
    // assign
    assign GPIO_1[0] = turn;
    
    // always
    always @(posedge CLOCK_24[1]) begin
        counter <= counter + 1;
        if (counter[25]) begin
            turn <= 1'b1;            // LED turned on
        end else begin
            turn <= 1'b0;            // LED turned off
        end
    end
    
endmodule

Conclusion

After using the DE1 LEDs, you are now able to handle LEDs outside the board.

A new step for the glory.

Well done, you've made it. cool

Comments

Comment: 

Hello,

Thanks for this article, actually it helped me using GPIO's.
I just bought the DE1-SoC board, but I can't really find the GPIO's schematic, the one which shows which pins are the analog and digital ones, and such... Do you know where can I find this schematic?

Much Regards.
Jacky

Comment: 

Hello Jacky,

Glad to see the tutorial helped you.

You could find schematic in the DE1 CD-ROM.

In your case, you should find it inside this package: http://www.terasic.com/downloads/cd-rom/de1-soc/

Taking DE1-SoC_v.3.1.0_SystemCD.zip, for example, will give you:

  • User manual
  • Tools
  • Schematic
  • Demonstrations
  • Datasheet

Anyway, there're a lot of others stuff by clicking the right tab (Resources for example): http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=167&No=836&PartNo=1

Enjoy. cool

Comment: 

Thanks for your fast reply Mi-K.

Also, thanks so much for your writings and articles in this site, it really helped understanding a lot of stuff about the DE1-SoC board.

Just wanted to ask one more question if you don't mind, Do you know a better place (better than the board's documentations and manuals) which gives tutorials or simpler articles on how to use the different peripherals and components of the DE1-SoC board?

Thanks a lot in advance.
Much Regards

Comment: 

Thank you for you comment Jacky.

You could try the Altera public FTP: ftp://ftp.altera.com/up/pub/, especially the Altera_Material folder that gives somes examples depending of your Quartus version.

But to be honest there're not a lot of easy tutorials, that's why I tried to make some. angel

Comment: 

First, I'm really thankful for your tutorial, the Altera lacks in tutorials, I'm a dummy in electronics so forgive me.
I want to know the pin assignments, I have Altera DE2, do I assign the GPIO[0] to the pin of the output only? and the CLOCK_24, what pin do I have to assign to it?
THanks :)

Comment: 

Hello Mcubbed,

I don't know exactly the DE2 pin assignments but what I'm sure it's that you must set:

  • LED to output
  • CLOCK to input

There is some information in the DE2 user manual:
ftp://ftp.altera.com/up/pub/Altera_Material/12.1/Boards/DE2/DE2_User_Manual.pdf

You could find at page 36 the Expansion header description.

Each pin has a code assigned.

Each code refers to a functionnality that you can find in the tables in the same user manual or directly from this pins table:
http://www.terasic.com.tw/attachment/archive/30/DE2_Pin_Table.pdf

I agree this is not easy to get at first glance. cool

Comment: 

Thanks for the tutorial.
I have a doubt, how did you know that GPIO_0[11] is GND and GPIO_0[28] is VCC?
I first thought that you configure them, but I see in the code nothing about this ports.

Thank you.

Comment: 

Hello Wendy,

I took this information in the datasheet and user manuals.

Have a look in these zip files: http://www.terasic.com/downloads/cd-rom/de1-soc/.

You should find what you are looking for. smiley

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.