Jump to content
  • 1

KEYBOARD INTERFACING WITH FPGA


Venkata Ratnam Chamakuri

Question

18 answers to this question

Recommended Posts

Hi @Venkata Ratnam Chamakuri,

If you don't have experience with this kind of stuff, my suggestion is taking it step by step. I don't know if this is a project for school or you want to learn something but if you have time I suggest you to start with the basics.

1. Remove the keyboard and just try to understand the VGA https://reference.digilentinc.com/learn/programmable-logic/tutorials/vga-display-congroller/start . Try to draw things on your monitor, a circle, a rectangle, change the colors, draw the Olympic Circles to make sure you understand how the colors combine and how to avoid that. 

2. Once you understand how and why your object is there, try using what the Nexys4 provides you, buttons and switches. draw a circle, or something and try to move it using the buttons, try to change the color using the switches. 

3. Try to build your snake game elements, map, obstacles, etc. and make the object stop in those points

4. Put identical points all over the map and add+1 on the tail every time your pixels encounter the points then try to find a way to generate every point at a time.

5. Add other rules as you go, Don't try to do it all at once. Make everything easier, understand what you are doing then add a little extra and so on.

6. After you see the game running with the buttons and you understand how everything works together, that is the moment to start adding keyboards or pmods or whatever you want https://reference.digilentinc.com/learn/programmable-logic/tutorials/nexys-4-ddr-keyboard-demo/start  and move the functionality from the buttons and switches to the keyboard's buttons. It is not very complicated to make a snake game and it's a good option to learn FPGA. You just have to invest time, start from the beginning, and give yourself the chance to fail then figure it out why it doesn't work. 

I don't know if this will help or will make you even more confused, here you also have the link to our Digilent Design Contest page http://www.digilentdesigncontest.com/ . We have published all the projects from our participants since we started the contest. They are free and open. The only thing is that the platforms are different. There is even a retro game console made, but on a zybo so it's C and not HDL. If you get stuck on something maybe their work will help you but I suggest you to try by yourself and fail, and try again until you understand how everything is working. If you understand and not just copy parts from one project to another, after you finish the snake, you'll know how to implement every game :). If you take codes from other sources and put them together, you get'll bugs and won't know how to fix them. I know that starting to make everything by yourself when you already have modules seems like an overkill and losing time. But if you don't understand the VGA, even if the code is working in a context, you won't figure out why it won't work in yours.Also, not every keyboard is compatible and this is why you have to make sure you can get the bug, by testing everything separately. If I were you, I would not use the VGA module if its made by someone else and you don't understand it, and start from there. It's not a complicate module and it's worth making your own.  

I wish you best of luck

Regards,

Bianca

 

Link to comment
Share on other sites

@Venkata Ratnam Chamakuri,

Did you wish to store binary values to block RAM from within the FPGA, or did you want to control this externally?  If from within the FPGA, you can see a (fairly) simple block RAM component here that is written in Verilog.  (You can assume EXTRA_CLOCK is zero, just to make things simpler--I only added that when I wanted to support a 200MHz design)

If you want to control the memory from your host computer (i.e. your PC), then check out my blog posts regarding a "debugging bus" that allows you to interact with FPGA memory using simple C++ methods on a host computer.

Let me point out, though, that this is rather off topic from "keyboard interfacing with FPGA"--so you might want to start a new topic if this doesn't answer your question.

Dan

Link to comment
Share on other sites

2 hours ago, Venkata Ratnam Chamakuri said:

Thanks alot. Yes,now i am trying to interface vga with zedboard.But i'm not able to program the vga using verilog.Let me know how to do that.Can any one help me.

 

The first video at my "Inside the Box" YouTube channel is all about driving the Zybo's VGA.  The example code (on github) is VHDL but did you know that VHDL and Verilog sorucefiles may be used together in the same Vivado project (for example even in a VHDL project a lot of the IPs have Verilog simulation sets)?  For another VGA driver example, a little digging around the channel's github https://github.com/gau-veldt/InsideTheBox/tree/master/Progress_2017_12_21 and you will find the sources for the Zybo C64 and in there you'll find vic_ii.vhd -- the VHDL file for the VIC II chip.

 

Edit: One thing I'll add here is that be sure you have downloaded the constraints file (.XDC) for the ZedBoard.  Import a copy into your project (be sure to tell Vivado to make a copy into the project), open the imported file and uncomment the VGA section (also note the pin names as these are what you'll use in your entity's port declaration [sorry I don't know the Verilog analogue to VHDL's entity/port declaration]).  There will be three vector signals for R,G,B and two 1-bit signals to control the H and V sync.

 

 

Link to comment
Share on other sites

On 12/13/2017 at 10:04 PM, Venkata Ratnam Chamakuri said:

Thanks for information but I didn't get any idea regarding snake game. Can you please explain clearly how to start and proceed the project(designing snake game using zedboard).

while Project_Is_too_Large:

    break problem into parts

    treat each part as separate project

connect the parts to communicate as needed

 

This really simple process applies to pretty much every big problem.  So break the "snake game" into parts: it needs output (VGA), it needs input (keyboard), a snake (state machine),  deciding when the snake dies (combinational logic), and so forth.

Link to comment
Share on other sites

On 12/12/2017 at 8:39 PM, Venkata Ratnam Chamakuri said:

Hi, I want to interface ps2 type keyboard with zedboard.Is it enough to have a pmodeps2 convertor to interface keyboard with zedboard.Can any one please help me.Can anyone suggest me how to design  snake game using zedboard.Please specify the steps involved in the process of  the design.

First obtain from Digilent one of the PS2-PMOD adapters.  Ideally, since these are actually PMOD6 (the Zybo/Zedboard have PMOD12 ports) get two PS2-PMOD adapters and a PMOD12-2xPMOD6 splitter cable.  Doing so will allow in future projects using a mouse in addition to a keyboard.  The cable with a dashed line where it comes off the main connector is pins 1-6 (Jx(3 downto 0) at the PL where x is the PMOD connector used).

 

Once connected uncomment the appropriate lines in your project's copy of the board .XDC file depending on which particular PMOD port you plugged the splitter cable into.

 

On the PL side a design needs to receive the 11-bit words that come in at the PMOD port.  For input-only the process is trivial: clock an 11-bit shift register using the PS/2 clock line and feed the data line to the SR's input.  Use a 0-10 counter and process the word received whenever this counter overflows (count=0 after increment).

 

Please check the process ps2_recv on line 1577 of https://github.com/gau-veldt/InsideTheBox/blob/master/Progress_2017_12_21/chiptest.vhd (part of my Zybo C64 project being made as basis for my youtube channel videos (Please see the top level readme for that github project) for a VHDL example that receives the PS/2 input.

 

Link to comment
Share on other sites

I won't be able to assist you every step and check codes for errors and bugs. You just have to find what works for you. You have to know what is important to understand. In your case, the VGA, at first. As fast as you understand it and you'll know how to manipulate the pixels, you can make them do what you want. Beside that, you'll have to figure out, how you want to make your map, and the obstacles, your score and whatever you might need and how you will access them. If you will need help with something specific, like how to read something from the memory or whatever you might struggle with, you can try to search for keywords on the forum. There were a lot of others here trying to make projects and the question might be already answered in another topic. Try all the sources you can, and if the answer is not there, ask and someone from the community might have an answer for you.

Have fun with your project

Bianca

 

 

Link to comment
Share on other sites

@Venkata Ratnam Chamakuri,

If you've never done this type of work before, there are unwritten "rules" that become very useful when getting things going.  They help to guarantee your success.

For example, to get an embedded software algorithm working, it helps to get it working on your desktop first where design and debugging is easy--then move it to your chosen platform.  This can apply to an FPGA as well, if your simulator is "good-enough" for the task.  I like Verilator myself.  I've found I can simulate even the VGA using Verilator--so it's been quite useful for me.

It sounds like you are struggling with the challenge of knowing what is going wrong within your design.  This is a common FPGA challenge, and one that I have written about extensively.  Indeed, if you read through my blog, you'll find that I've also struggled with this issue.  To be successful, you need to start with a bit of patience, to expect these things to take some time, and to start with the right design process.

My recommendation to you would be to capture a trace of the interaction between your design and the keyboard you want to work with.  Compare this to the PS/2 specification, or the drawings you may find online.  Add your own variables to the trace if necessary.  If, once you get a trace, you still don't have things working--then feel free to come back here and post a screen shot from gtkwave or some such and I'm sure someone will be able to point out what you are doing wrong.

But to search your code for a bug?  That's expensive.  That's not likely going to happen with the volunteers here--especially not with multiple files of code to search through.  If that's the type of help you really want, I'd be glad to offer it, but  .... my time is expensive--much like most of the mentor's on this forum.

Dan

Link to comment
Share on other sites

Hi @Venkata Ratnam Chamakuri,

Unfortunately, we do not have time to go through your code and get it working. I would suggest trying to get smaller portions of you project working and then integrating them with other working portions of your project. I would suggest simulating you HDL to find where the issues are. Here is a github project for the basys 3 that takes input from a serial terminal on a computer and displays it on a monitor through the VGA. This is not exactly what you are trying to do but should provide additional insight.

thank you,

Jon

Link to comment
Share on other sites

Hi sir,

I have source code in verilog for both keyboard and vga without any errors, but still I'm not getting any output(i.e. when a key is pressed, it's not displaying on monitor)

Here is our source code...

Will you please verify once and let me know the problem...

Thank you.

clkdiv.v

prom_DMH.v

ps2.v

ps2_rx.v

segments.v

vga_640x480.v

vga_initials.v

vga_initials_top.v

vga_keyboard_7seg.v

Link to comment
Share on other sites

Hi @Venkata Ratnam Chamakuri,

You will need to make a project that takes the keyboard input into the Nexys 4's usb. Then the project will need to use a state machine that determines what image you send to the VGA  based on the keyboards input and the snake game rules.  Then you will also to design the  process to send data to the VGA.  Above is a linked  verilog Instructable that should help with this. Also here is a keyboard demo and here is a VGA/mouse demo that should help with communicating with the keyboard and VGA.

Cheers,

Jon 

Link to comment
Share on other sites

Hi @Venkata Ratnam Chamakuri,

Unfortunately, we don't have the time available to create a step by step guide on how to create your specific project. I would first figure out your design. Then I would figure out how you want the game to work. What I would recommend doing next is getting some of the pieces of the snake game working individually with the PS2 input, and the VGA display. I would then look at the resources that implement the game in verilog/VHDL since those will prove invaluable for getting the various components including the game itself working together. I did find an Instructable here that goes through creating the snake game using verilog using a different board. You should be able to use this as a reference as to what you need to do. Their verilog should be very helpful as well. 

cheers,

Jon

Link to comment
Share on other sites

Hi @Venkata Ratnam Chamakuri,

You will need to use the Pmod PS2 here to interface with the keyboard. You would not be able to use the USB OTG unless you are using an embedded linux on the zedboard like petalinux. We do not have a snake game example made for FPGA's. I did find some projects on github that you should be able to either modify to work with the zedboard or use as a reference here and hereHere is an Instructable that might be helpful for reference using a microcontroller. 

cheers,

Jon

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...