Showing posts with label Verilog. Show all posts
Showing posts with label Verilog. Show all posts

Thursday, May 30, 2013

Still plugging away on the FPGA synthesizer

I really bit off a good deal more than I could chew by trying to get that thing running as quickly as I did. A lot of what I'm doing now is going back over minute assumptions about what should work in real hardware, trying to get MyHDL's simulator to agree with Xilinx's ISE simulator (ISE Sim doesn't like datapaths wider than 32 bits) and trying to get the chip to agree with either of them. The chip seems to have a mind of its own. Very annoying.

Anyway I've moved this stuff into its own Github repository so you can show it to your friends and all stand around mocking it without the distraction of other software I've written over the years. So, for as long as it still doesn't work (and with, I hope, the good grace to do it behind my back), y'all can continue with that mocking. Once it actually does what it's supposed to do, all mocking must of course cease.

Saturday, May 18, 2013

My FPGA design skills are a little rustier than I thought

Today I'm going to Makerfaire in the Bay Area. I'd had an idea percolating in my head to use an FPGA to implement fixed-point equivalents of the analog music synthesizer modules of the 1970s, and gave myself a couple of weeks to design and build a simple synthesizer. I'd been a synthesizer enthusiast in high school and college, having attended high school with the late David Hillel Wilson and had many interesting discussions with him about circuit design for synthesizers, a passion he shared with his father. While he taught me what he knew about synthesizers, I taught him what I knew about electronics, and we both benefitted.

Now I have to confess that since my switch to software engineering in the mid-90s, I haven't really done that much with FPGAs, but I've fooled around a couple of times with Xilinx's ISE WebPack software and stumbled across MyHDL, which dovetailed nicely with my long-standing interest in Python. So I ordered a Papilio board and started coding up Python which would be translated into Verilog. My humble efforts appear on Github.
There was a lot of furious activity over the two weeks before Makerfaire, which I hoped would produce something of interest, and I learned some new things, like about delta-sigma DACs. Being an impatient reader, I designed the delta-sigma DAC myself from scratch, and ended up diverging from how it's usually done. My design maintains a register with an estimate of the capacitor voltage on the RC lowpass driven by the output bit, and updates that register (requiring a multiplier because of the exp(-dt/RC) term) as it supplies bits. It works, but has a failure mode of generating small audible high frequency artifacts particularly when the output voltage is close to minimum or maximum. On the long boring flight out, I had plenty of time to think about that failure mode, and it seems to me the classic delta-sigma design would almost certainly suffer from it too. I think it could be reduced by injecting noise, breaking up the repetitive patterns that appear in the bitstream.

I like Python a lot but I'm not sure I'm going to stay with the MyHDL approach. As I learn a little more about Verilog, it seems like a probably better idea to design directly in Verilog. The language doesn't look that difficult, as I study MyHDL's output, and while books on Verilog tend toward expensive, some of them are more affordable. Those books are on the Kindle, and a couple others are affordable in paper form.

MyHDL-translated designs do not implement Verilog modularity well, and I think it would be good to build up a library of Verilog modules in which I have high confidence. MyHDL's simulation doesn't always completely agree with what the Xilinx chip will do. And while MyHDL.org talks a lot about how great it is to write tests in Python, the Verilog language also provides substantial support for testing. Verilog supports signed integers, but as far I've seen, MyHDL doesn't (this is INCORRECT, please see addendum below), and for the fixed-point math in the synth modules, that alone would have steered me toward straight Verilog a lot sooner had I been aware of it.

It appears the world of Verilog is much bigger and much more interesting than I'd originally thought. I've started to take a look at GPL Cver, a Verilog interpreter that (I think) has debugger-like functions of setting breakpoints and single-stepping your design. I had been thinking about what features I'd put into a Verilog interpreter if I were writing one, and a little googling showed me that such a thing already existed. So I look forward to tinkering with CVer when I get home from Makerfaire.

EDIT: Many thanks to Jan Decaluwe, the developer of MyHDL, for taking the time to personally respond to the challenges I encountered with it. Having had a couple of days to relax after the hustle and bustle of Makerfaire, and get over the disappointment of not getting my little gadget working in time, I can see that I was working in haste and neglected to give MyHDL the full credit it deserves. At the very least it explores territory that is largely uncharted, bringing modern software engineering to the HDL world where (like all those computational chemists still running Fortran code) things have tended to lag behind the times a bit.

In my haste, I neglected the documentation specifically addressing signed arithmetic in MyHDL. I didn't take the time to read the docs carefully. As Jan points out in his writings and in the comment to this blog, MyHDL's approach to signed arithmetic is in fact simpler and more consistent than that of Verilog. What does signed arithmetic look like in MyHDL? It looks like this.

    # INCORRECT
    >>> x = Signal(intbv(0)[8:])
    >>> x.next = -1
    Traceback (most recent call last):
        ...blah blah blah...
    ValueError: intbv value -1 < minimum 0

    # CORRECT, range is from min to max-1 inclusive
    >>> x = Signal(intbv(0, min=-128, max=128))
    >>> x.next = -1      # happy as a clam

In the case where MyHDL's behavior appeared to diverge from that of the physical FPGA, my numerically-controlled amplifier circuit above uses one of the hardware multipliers in the XC3S500E, which multiplies two 18-bit unsigned numbers to produce a 36-bit unsigned product. When my music synthesizer was at one point unable to make any sound, I tracked it down to the amplifier circuit, which was working fine in simulation. There was already a hardware multiplier working in the delta-sigma DAC. I poked at things with a scope probe, and scratched my head and studied my code and studied other peoples' code and ultimately determined that I needed to latch the factors in registers just prior to the multiplier. Whether it's exactly that, I still can't say, but finally the amp circuit worked correctly.

I wrongly concluded that it indicated some fault in MyHDL's veracity as a simulator. If it didn't work in the chip, it shouldn't have worked in simulation. But with more careful thought I can see that it's really an idiosyncrasy of the FPGA itself, or perhaps the ISE Webpack software. I would expect to run into the same issue if I'd been writing in Verilog. I might have seen it coming if I'd done post-layout simulation in Webpack, and I should probably look at doing that. Once the bits are actually inside the chip, you can only see the ones that appear on I/O pins.

Friday, March 12, 2010

A new FPGA board to play with

Digilent, a partner of Xilinx, makes eval boards for Xilinx FPGAs. I bought one and plan to hack some Verilog with it. My past experiments involved a board of my own design with a FPGA and a USB-enabled microcontroller. I successfully programmed the microcontroller over the USB cable to wiggle GPIO pins, which should have allowed me to program the FPGA via JTAG. But for some reason, JTAG programming of the FPGA didn't work. This time the JTAG programming pins will be wired directly to parallel port pins and there is a Linux library for programming them, so I should have better luck this time. Fewer unknowns and variables, more easily probed.

Attention (hey, shiny!) deficit break: I stumbled across a couple of very affordable logic analyzers. Amazing stuff, just the thing for debugging errant JTAG signals.

Some nice folks have released a PCI soft core under the LGPL. I'm not ready to tackle that yet, but hope to get there before too long. Speaking of PCI,
here is a nice FPGA board for a PCI bus slot from Enterpoint in the UK. They also have a PCI soft core but the licensing is a bit pricey for a hobbyist. I wonder if the LGPLed PCI core would work on the Enterpoint board.

Tuesday, August 21, 2007

Software-defined radio board: Stalled, for now

Periodically people email me and ask how things are going with my SDR board. Things are quite thoroughly stalled. I can program the FX2 over the USB cable, and I can wiggle the I/O pins, and I've connected the I/O pins to the FPGA's JTAG programming pins. Theoretically it should be pretty easy to program the FPGA after that. But that's where it is stalled; for some reason the FPGA won't program correctly. Go figure.

One thought is to make up a board with a lot more testpoints, like this.
I had a picture of a board design here before, but I think I've since misplaced that file. I'll try to remember to check around for it.
This design is for a temporary two-layer board that I would use only to get the design and development effort back on track. Once I'd resolved the FPGA programming issues, I'd go back to a four-layer design with a lot fewer testpoints.

But if you're one of those impatient folks who wants to play with a software-defined radio RIGHT NOW then you should check out these links, many of which describe projects that are much further along than my board.

Thursday, November 09, 2006

Verilog/FPGA tools for Linux

Until I get more organized with this, it's just a collection of random links. I'll need to figure out a way to program the FPGA on my board.Go to the Xilinx web page for downloading WebPACK and grab a free download. It's a shell script; run it to install the Xilinx tools on your hard disk. It will take about a gigabyte so make sure to install it in a partition with that much room. Start reading doc/usenglish/books/docs/qst/qst.pdf. That's as far as I've gotten today.

Good Verilog tutorial here.

Friday, November 03, 2006

Another software-defined radio board

Two years after my first attempt, I am working on a new board for software-defined radio. In the past, I pursued this as a political agenda, but that made me rush, and ultimately design a crummy board that didn't work. I've split the design into two pieces and this board is the first piece. It has an 8-bit processor with USB slave capability, and it has a Xilinx XC3S400 FPGA with 400K gates, lots of on-chip RAM, and 16 hardware multipliers, each 18-bit by 18-bit. The USB channel can get data to or from your laptop at over 50 megabytes per second. The board has 46 general purpose I/O pins and six dedicated pins. Not counting assembly, which you can do cheaply at home, the board costs about $70, so it's a pretty good deal for a hobbyist.

The second piece of the radio is a board with fast digital-to-analog and analog-to-digital converters, to translate the signals between the digital domain and the world of radio electronics. A receiver would use an ADC, a transmitter would use a DAC. I'd like to design a receiver board first, but I want to get the USB/FPGA board up and running before that.

If you had this thing connected to your laptop, you'd install GNU Radio and you could transmit and receive radio signals. Depending on the analog hardware you had, you could do this on any of several radio bands, and with the USB bandwidth and a fast ADC, you could pull in whole television signals, maybe even HDTV signals. And that's when things get interesting politically, because that's the battleground for fighting the Broadcast Flag battle.

The USB/FPGA board is a remarkable example of what a low-budget electronics hobbyist can do these days. A couple years ago I spent some money on a license for CadSoft Eagle to do four-layer boards but I expect it to fill my hobbyist needs for a long time. Now I can send my Gerber files to PCB fab outfits in China like this one and get boards for ridiculously low prices. As a result, my electronics projects cost very little more than the price of the parts. It's cool, and it calls for a renaissance of electronics hobby activity. To us oldtimers it seemed like the 1970s was the peak for that kind of thing, but it can come back stronger than ever.