Some time ago, I purchased a Papilio Arduino from the Gadget Factory. This is an open-source FPGA board that's based on a Xilinx Spartan 3E. The Papilio comes with a bit stream that turns the FPGA into an Arduino microcontroller, but it also works great as a generic FPGA development board. Not long after I'd purchased this board, I won an add-on -- called the B/LED Wing -- in a contest on the Gadget Factory site. This add-on has four push button switches and four LEDs. Although this may not seem like much, they will make fiddling with this board a lot more convenient.
Of course, I still like my Spartan 6 LX9 board and I'm far from done playing with it. In fact, I have an Avnet WiFi Pmod and a set of 15 Maxim Pmods covering a whole slew of applications to work with and write about. But the Spartan 6 board won't have enough input/outputs (I/Os) for my robot avatar project. I'm thinking that the Papilio's 48 I/Os will get me a lot further than the Spartan 6 LX9's 16 accessible pins.
Today, I'm going to:
Dig up the documentation for my Papilo
Start a new project
Map the I/O for my Button / LED Wing
Synchronize the switch inputs
Attempt to de-bounce those inputs
Pass the de-bounced value out to the LEDs
Papilio FPGA development board with B-LED Wing daughter card.
I'll start by creating a new ISE project and calling it "PaIO." In the New Project Wizard, I need to select "Spartan 3E" as the family, "XC3S250E" as the device, and "VQ100" as the package. The Papilio Wiki at the Gadget Factory has a "Xilinx UCF File" that I can draw from, but I'll have to create the Verilog file from scratch. This is really back to the basics, which is a nice change from killing myself with clocks last week.
I plugged the Wing into section "BH" on the Papilio, which connects up to the Spartan pins P58, P54, P41, P36, P34, P32, P25, and P22. The Wing has the pins clearly labeled as seen in the image below, so it will be easy to properly set the UCF. (I like clear labeling.)
Still in the ISE New Source Wizard, on the Define Module screen, I named my ports "WingLED" and "WingSW," both being busses with an MSB (most-significant bit) of 3 and an LSB (least-significant bit) of 0. The supplied UCF defines those pins on lines 43 through 50. Once I stripped all of the non-used lines out, except the clock, which I'll need later, this ended up as shown below (click here to see a larger, more detailed version of this image):
A simple "assign WingLED[3:0] = WingSW[3:0];" could end this exercise, but someday I'll need those switches to be de-bounced. What I'm thinking is:
I'll hold the current state of the switch
Send the switch inputs through a synchronizer
If the state changes, I'll start a timer
When the timer stops, I'll have a stable switch value
Click here to see a larger, more detailed version of the above image. And click here to download a ZIP file containing my Verilog source code to see if it makes sense. It's late at night as I pen these words, so please be kind. This code does pass the switch value on to the LED. The only problem is that I can't use ChipScope on this board to verify that it's doing what it's supposed to be doing. This means I'll have to put my code on the Spartan 6 LX9 board and ChipScope it out.
Duane Benson 1/28/2013 1:54:45 PM User Rank Blogger
Re: Papilio
Detox - Thanks for your comments. The Papillio is an interesting product. I originally bought it for the Arduino capabilities, but have used it more as an FPGA learning tool.
Im just goofing around with Papilio and some wings, using VHDL, Verilog, and C-style code(whilst im in the Andruino like IDE for Papilio). Just starting to get it to do fun stuff and see how far I can take it. Im not a hippie but im loving this open source stuff, and I want to thank you Duane for this excellent article. I downlaoded your code and complied it with ISE and its working great. Im going to check out all your other stuff as you seem like a real expert.
By the way I tried to compile Mr. Gassetts VHDL code for the Button_Led but it seemed to have a lot of extraneous inputs and outputs in the code and when I used a simple 8 net(4 button in, 4 led out) constraints file which I extrapolated from his (posssibly superfluous?) code, but it gave me a ton of erros.
Another way to implement this same result is with the Button_Led example provided as part of the Papilio/Arduino IDE located within examples folder - just in case your readers didnt know.
will do. Just didn't want to bog things down too much right away. I've got my thinking cap on (which, amazingly doesn't include pizza or beer right now)... I'm starting the 1st seps of making my own logic analyzer using the Opal Kelly stuff. It'll be a lotmore involved, though, since I'll have to write a bit of software, too...
Duane Benson 1/14/2013 3:39:28 PM User Rank Blogger
Re: Debouncing.
Tomii - I don't think there is a personal messaging system, but you can email me at "duane benson @ hot mail . com" (remove all spaces). Still, don't hesitate to ask questions live on the site here if the answer might benefit others.
Seems like an excellent way to screw with your users. Just speed up the keypress timer after they've been using it a while. They'll swear it's *really* fast...
PS: I'm curious about your clock wizarding stuff... Do you know of a way to PM here on the site? I'd hate to broadcast my e-mail...
This whole discussion reminds me of this article I read some time ago...
Interesting article, but the part I'm distinctly recallis is this:
The cohesiveness of consciousness is essential to our judgments about cause and effect—and, therefore, to our sense of self. In one particularly sneaky experiment, Eagleman and his team asked volunteers to press a button to make a light blink—with a slight delay. After 10 or so presses, people cottoned onto the delay and began to see the blink happen as soon as they pressed the button. Then the experimenters reduced the delay, and people reported that the blink happened before they pressed the button.
Duane Benson 11/7/2012 9:13:40 PM User Rank Blogger
Re: Debouncing.
Rfindley - Now that makes a lot of sense. I'd never thought of that, but it would allow the debounce to start a lot earlier. I'm not sure how long it takes on average to lift your finger up and press it back down when jabbing a button, but rather than just having that time to debounce, you've added the down dwell time as available for de-bounce. I like it.
I've experimented with the method shown in that video, and there's one thing I didn't like about it: the output is always delayed from the input by whatever the filter time is. If your switch needs relatively large debounce, this creates visible 'lag'. I've found that even 10ms creates a slightly uncomfortable lag. Many MIDI musicians are familiar with this 10ms barrier, because it is the point at which your brain starts having trouble 'hiding' the delay between when you press a note on the keyboard and when your ear starts to hear the corresponding note.
So the method I use is:
At the first glitch from the input (as the switch begins making or breaking contact), I change the output state immediately, and I simply ignore the input for the next xx milliseconds while the switch completes its noisy transition.
Duane Benson 11/7/2012 10:22:20 AM User Rank Blogger
Re: Debouncing.
William - That video is pretty interesting. The circuit described is similar to the pair of flip-flops I've been using for synchronization, but with an added inverter and AND gate. Basically, she's combining a multi-stage synchronizer and de-bounce circuit. She also had some examples of edge detection circuitry.
Duane has decided that the time is ripe to get his ZedBoard bolted onto his robot with a Linux distribution up and running. That was the ultimate plan anyway, so why wait?
To save this item to your list of favorite All Programmable Planet content so you can find it later in your Profile page, click the "Save It" button next to the item.
If you found this interesting or useful, please use the links to the services below to share it with other readers. You will need a free account with each service to share an item via that service.