element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Programmable Logic
  • Challenges & Projects
  • Project14
  • Programmable Logic
  • More
  • Cancel
Programmable Logic
Blog PragrammaBall - getting started on the Verilog
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Programmable Logic requires membership for participation - click to join
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Fred27
  • Date Created: 1 Jul 2019 5:57 PM Date Created
  • Views 1905 views
  • Likes 15 likes
  • Comments 9 comments
  • programmablelogicch
  • arty s7
Related
Recommended

PragrammaBall - getting started on the Verilog

Fred27
Fred27
1 Jul 2019

So, I've decided what I'm going to do for my Programmable Logic Project 14 entry. It's going to be a ball-rolling sort of game controlled by a couple of micro:bits. I'm hoping my kids will be able to help with the micro:bit side of things.

 

As the FPGA (a Spartan 7 on an Arty S7 board) will be generating the output VGA signal I started looking into how to generate FPGA. I found an excellent resource on VGA generation at timetoexplore. It describes all the timing required for a 640 x 480 VGA output from a VGA and even started going into generating graphics. I also discovered a different approach by Andy West here on E14. I really wanted to understand what I was doing rather than copy someone else's code so I took inspiration from both. The timing and generation on my version takes a lot from timetoexplore, but I liked the separation of the VGA signal generation from the rendering of element from Andy's solution.

 

Getting some video output

I also decide that I wanted to render the output on the fly rather than writing to an area of RAM to display from there. I felt that I'd learn more from doing it this way. Of course, I stumbled into a few FPGA pitfalls. At one point I managed to (I think) get the timing a little too close and half the screen was blanked and I got a smudgy green / purple mess. As a coder, that's not something you'd expect when only dealing with grey and blue.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Displaying something a little more game like

Once I'd got my timing issue sorted I decided to move on to having something a little more interesting than a square. This got me into the realm of uploaded an image file onto the FPGA. Once again timetoexplore was helpful. Still in my retro vibe and with a PacMan machine at work, I decided that a PacMan ghost would be cool. I ended up hand-entering image data in the form of a 14 x 14 grid of 2-bit binary data to form the image and a 4 colur palette to translate these to a 12-bit colour for display. If you look closely you can just about make out the figure in the image. Well, I can. Maybe I've been staring at it for too long.

// Pacman ghost 14x14, eyes looking left
// 00 background
// 01 white eye
// 10 blue iris
// 11 main colour
// Hand typed by Fred from image here: https://www.pngkey.com/detail/u2e6e6e6a9u2e6q8_pacman-sprites-pixel-art-14x14-pac-man/
00 00 00 00 00 11 11 11 11 00 00 00 00 00
00 00 00 11 11 11 11 11 11 11 11 00 00 00
00 00 11 11 11 11 11 11 11 11 11 11 00 00 
00 11 01 01 11 11 11 11 01 01 11 11 11 00 
00 01 01 01 01 11 11 01 01 01 01 11 11 00 
00 10 10 01 01 11 11 10 10 01 01 11 11 00 
11 10 10 01 01 11 11 10 10 01 01 11 11 11
11 11 01 01 11 11 11 11 01 01 11 11 11 11
11 11 11 11 11 11 11 11 11 11 11 11 11 11
11 11 11 11 11 11 11 11 11 11 11 11 11 11
11 11 11 11 11 11 11 11 11 11 11 11 11 11
11 11 11 11 11 11 11 11 11 11 11 11 11 11
11 11 00 11 11 11 00 00 11 11 11 00 11 11
11 00 00 00 11 11 00 00 11 11 00 00 00 11
// secondary image for moving "feet"
11 11 11 11 11 11 11 11 11 11 11 11 11 11
11 11 11 11 00 11 11 11 11 00 11 11 11 11
11 11 11 00 00 00 11 11 00 00 00 11 11 11

and the palette:

// Palette for pacman ghost 
// 4 12-bit colour values 
0F0 // 00 = "green screen" background 
FFF // 01 = white eyes 
48F // 10 = blue iris 
F00 // 11 = red body

 

These were loaded into distributed RAM (i.e. probably a load of LUTs) for simplicity. I may move them to Block RAM later. Once you've got the memory files as part of your Vivado project, they're simple imported like this. Note the readmemb for binary and readmemh for hex.

initial begin 
     $display("Loading target and target palette."); 
     $readmemb("pacman_ghost.mem", target_image); 
     $readmemh("pacman_ghost_palette.mem", target_palette); 
 end

 

I liked the way that the ghost's eyes always looked the way they were going in Pacman. Whilst Pacman had only 4 directions, I hoped my ghost was also going to move diagonally. I decided that just 2 images would be enough and that I could do this by flipping the whole ghost horizontally depending on the direction of travel. For some reason I'm struggling to animate his moving legs properly. This was the result so far:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Sorry for the poor hand-held video of the screen. One thing I noticed when doing this is that there's no easy way to record the output without buying some specialist hardware. The video is generated on the fly and never actually exists as a video file. Which I suppose is sort of the point!

 

What's next?

Next, I'm going to make the ghost move randomly and then start on the balls that need to be rolled towards him.

  • Sign in to reply

Top Comments

  • Fred27
    Fred27 over 5 years ago +4
    Unfortunately I got in a bit of a rut with the Verilog to animate the ghost's legs. (Are they legs? You know what I mean.) Despite being almost identical to the code for flipping the image horizontally…
  • genebren
    genebren over 5 years ago +3
    David, That is looking pretty cool. This is some great progress on your project. We learn by trying small pieces at a time and using what we learn to leverage our progress as we begin to tackle larger…
  • dubbie
    dubbie over 5 years ago in reply to Fred27 +3
    Sounds like life! Dubbie
  • Fred27
    Fred27 over 5 years ago

    Thanks guys. The software developer market is bouyant right now so finding work shouldn't be hard. Right now my home, job and kids' school are all within a mile of each other, so what might be hard to replace is that convenience!

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 5 years ago in reply to Fred27

    Hi Fred,

     

    Sorry to hear that, you're clearly a smart capable person, hopefully you'll be in demand.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • gecoz
    gecoz over 5 years ago in reply to Fred27

    Gosh!,Sorry to hear about this. It must have been really bad there. I'm sure you will find something better soon, perhaps the job market might be a bit slow now and in August, because of the holidays, but definitely should pick up in September, and that gives you time to brush up on your skills for the interview. Are you going to stick with the Software Development world, or are you going to go move more towards Electronics?

     

    Anyway, all the best with your job search, good luck!

     

    Fabio

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 over 5 years ago in reply to Fred27

    Work went crazy to the point that I quit yesterday after working there for 10 years! I'm on three months notice so I  now have 3 months to find another job. To be honest that means that fun projects like this will have to take a back seat for a bit whilst I brush up on skills required for interviewing.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 5 years ago

    Hi Fred,

     

    This is awesome progress! It's very inspiring seeing how far you have already got, despite the pause due to work. The sprite movement is looking superb.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube