The Claw Game, How does the Basys 3 Know What to Do?


As you probably already heard, the claw game is built, programmed and ready to be shipped off to ASEE and ECEDHA. You’ve been hearing tidbits about the parts I used, including the Basys 3, PmodSTEP, and PmodJSTK. But, what you haven’t heard about is what is under the hood…what the Basys 3 is actually doing to control the movement of the claw game. Well, all of this will be revealed in good time!


The craziness that is the electronics of the claw game.

However, to start with I’d like to talk about one of the most important pieces, the state machine. A while ago I wrote a post about what a state machine and state diagram is. If you’ve forgotten, feel free to check it out to get a refresher.

One reason why I like using FPGAs is because, since you are programming the hardware, everything is really flexible, deliberate, and fast. Also for being an entry level board the Basys 3 has loads of configurable I/O. If you read my post announcing the claw game was complete, then you know I used almost all of the Pmod ports.

Being an FPGA, and having those characteristics as well as lots of I/O, the Basys 3 fit well to run the claw machine with a state machine. So to start I drew a state diagram. It of course changed along the way, but ended up looking something like this.

The claw state diagram!

The claw state diagram!

We start in the wait state, where the claw is quite literally waiting for someone to start the game. The motors cannot be engaged here, the only way to leave this state is to press the start button. Once the button is pressed it moves into the start state. Here is where the user can move the motors around to position the claw. This can be seen in the various direction states. If the joystick sends a direction signal it moves to one of those states, where it enables the corresponding motor.

Alternatively, if the drop claw button is pressed it will go into the drop claw sequence. First it opens the claw, then drops down until the down limit is reached. Then it closes the claw, to hopefully grasp a prize, then moves up and left, over the prize shoot, and opens the claw.

In the end, the drop claw button and start button ended up being the same, since they couldn’t be triggered from the same state. Now, when I said this was the final state diagram, that was a little fib. The true final state diagram includes the debouncing state, that Tommy added, to make sure the button and limit switches aren’t being triggered by bouncing. However it just makes the state diagram more complicated, and I will cover debouncing on FPGA’s in a later post. This just covers the basic functionality.


Well the diagram is fun to look at, but I’m sure you’re interested in what is actually deployed on the Basys 3, so here it is, the state machine code.


The claw machine code!

It was too long to add as a picture, and the blog doesn’t trust .v files, so a text file it is! You can view it in any text editor.

Now that you’ve seen some of the parts, and the brain of the claw machine, stayed tuned to the blog and Instructables collection for all the other pieces. After all, the brain is only one part of the battle, we still had to figure out a way to actually interface it with the Pmod ports on the Basys 3 and the outside world.

Share on FacebookTweet about this on TwitterShare on Google+Pin on PinterestShare on RedditShare on TumblrShare on LinkedInShare on StumbleUponEmail this to someone

About Author

When I started school I wasn’t interested in any of things I’m passionate about now. In fact originally I started out wanting to study art. But then I decided I didn’t want to have people telling me what to create, so I changed to music. Then I decided I didn’t want to ruin a hobby by making it my career. At the same time my Physics class was teaching a unit on the physics of music, and I thought that was way interesting, so I changed to physics. Then by the time physics was over I decided that the coolest part of physics was electricity and magnetism, and I may as well get a degree that transfers directly into a career. So while all this was happening, I was attending Shoreline Community College, and during that time I found my passion, or rather presented itself repeatedly, until I realized, maybe I should take a hint from the universe. While at community college, I was asked to help at the high school by tutoring chemistry students. Then I was asked to help at the elementary school by being a math Olympiad coach. I continued both because I found I really enjoyed it. I also had an opportunity, and was hired to be a tutor in the Math Learning Center at the Community College, a job I really loved. At the same time I was working as a Nanny, which I had been doing for several years, the main reason because I could and would answer the hard questions the kids asked honestly (i.e. why is the sky blue). I then was recommended by the patrons of the MLC to the transfer tutoring center (private tutoring,) and developed a wait list of students. Through all these opportunities at some point I realized that I loved watching people go from totally lost, to masters of a subject. I was also forced to admit that having all these opportunities continually renewed, I must have been somewhat good at it. So I decided I wanted to teach, which fits with my mission oriented personality. I saw a serious lack of passionate ECE professors in the institutions I attended. At WSU I continued this trend by being ask to TA for computer science and electrical engineering, being a TA for a total of 4 semesters. This continued by getting an amazing opportunity in my first semester at Washington State University to work at Digilent, an educational company. So even if I didn’t want to teach, turns out I can’t avoid it. Luckily it is my main passion.

1 Comment

  1. James Colvin on

    I’m glad to see the Basys 3 lives up to it’s full potential and can survive existing as the source of a childhood nightmare.

    But I’m impressed you survived making the claw game– I look at “the craziness that is the electronics of the claw game” and the room starts spinning. How did you do it?

Leave A Reply