Forum Discussion
Altera_Forum
Honored Contributor
11 years agoGPIO output on DE2_115
I have a DE2-115 board and i'm trying to do some basic functions.
I want provide a high/low input using a switch on the board,and read this high/low input as output onto a GPIO pin. i.e. whenever I 'ON' the switch, '1' is supposed to appear at the GPIO pin,and whenever the switch is 'off' the GPIO should provide '0'. This is the corresponding verilog code: module dswitch(SW,CLOCK_50,GPIO); input [17:0]SW; input CLOCK_50; output reg[35:0]GPIO; always @(posedge CLOCK_50) begin GPIO[31:1]= 32'hz; if(SW[0]==1) GPIO[0]=1'b1; else GPIO[0]=1'b0; end endmodule all the pins are assigned correctly using the pin editor. The code compiles fine. But,when i try to read the output from the GPIO[0] pin, on the board, onto a scope,there is no change in activity when the switch is pushed on or off. I am unable to figure out what is wrong. Am I missing something?Is there any thing else that needs to be done or any other connections to be given? Also,what would be a good ground on the fpga board that could be used to connect the ground pin of the scope to? Thanks!6 Replies
- Altera_Forum
Honored Contributor
Your code works (unchanged) on my DE2-115. So, I think you need to look at for something else wrong in your project settings.
However, whilst we're here, a few comments on your code. You are loading registers GPIO[31:1] with 'z'. Ask yourself whether a register (a real one, in a device) can be loaded with a 'z'. How Quartus (or other vendor tools) interprets your statement may not be well defined. So, different tools may produce different results - not a good thing. As you will see from the compilation report the number of registers used for your design is 1, even though you've declared and inferred 36 in your code. Loading registers with 'z' can be a useful tool when simulating - it allows you to follow a particular path through a design - very useful for fault finding. However, a real register, in a device, can only be loaded with a '0' or '1'. Secondly, a minor point, you've declared GPIO[35:0] in your port list but only coded for GPIO[31:0]. GPIO[35:32] are left wanting... I suggest you trim (tidy) your code to this:
...or if you must tri-state the remaining GPIO...module dswitch (SW,CLOCK_50,GPIO); input wire SW; input wire CLOCK_50; output reg GPIO; always @(posedge CLOCK_50) begin if(SW==1) GPIO=1'b1; else GPIO=1'b0; end endmodule
Cheers, Alexmodule dswitch (SW,CLOCK_50,GPIO); input wire SW; input wire CLOCK_50; output wire GPIO; reg GPIO_reg; always @(posedge CLOCK_50) begin if(SW==1) GPIO_reg=1'b1; else GPIO_reg=1'b0; end assign GPIO=GPIO_reg; assign GPIO=35'hz; endmodule - Altera_Forum
Honored Contributor
Thanks for your reply Alex! I will clean up the code.
Did you try looking at the GPIO output by reading it onto a scope? The reason I am asking this is,when I connect the GPIO output to an LED onto the board,to check whether the output is really coming across the GPIO line,the LED works correctly according to the on or off of the switch. But it doesn't show any change in the signal when connected to an oscilloscope. I wanted to know what could be the reason for this. Would be great if you could help me on that! Thanks, Ankita - Altera_Forum
Honored Contributor
Hi Ankita,
have you applied voltage settings on your clock_50 signal in assignment editor ? Try giving the voltage if you havent. This will give you the correct pin names and their voltage level - ftp://ftp.altera.com/up/pub/altera_material/12.1/boards/de2-115/de2_115.qsf Also, according to what you want to do, why not use assign statement and remove the clock altogether ? unless you have further code and this is just a small part. - Altera_Forum
Honored Contributor
I assume you did the correct pin assignments?
- Altera_Forum
Honored Contributor
Hi Ankita,
I checked my GPIO pin with a DVM (rather than a scope). However, I'm confident it worked. If you can drive an LED directly from the same GPIO pin (that's what you tired - yes?) then you can be confident the logic level is appearing on the GPIO pin. I'm now suspecting your scope setup if that's not showing the level change. Cheers, Alex - Altera_Forum
Honored Contributor
Hi Ankita,
Just to add on that you could also use SignalTap to monitor the signal levels on top of using LED and scope. The SignalTap would allow you to monitor the input controls and output status on the same window.