Close

Driving an Array of LED Digits with the CAT Board

A project log for CAT Board

The CAT Board is part of a Raspberry Pi-based hand-held FPGA programming system.

dave-vandenboutDave Vandenbout 11/03/2015 at 06:488 Comments

Wow, it's been almost two weeks since I posted! I've been through hell and back.

After getting the simple LED blinker working with the open-source myhdl+yosys+arachne-pnr toolflow, I decided to take one of my existing designs and port it to the CAT Board. I chose the driver interface for the StickIt! LED digits board because I could attach that directly to one of the PMOD sockets on the CAT Board for testing purposes.

The driver uses eight tristateable outputs to control eight seven-segment LED digits. Forcing a high level on one of the outputs powers the common anode of one of the digits. Driving a low level on one or more of the other seven outputs will pull down the cathodes associated with those segments so current will flow and make them light up. The drivers for the rest of the segments are placed in the high impedance state so no current flows and the segments stay dark. Meanwhile, all the other digits stay completely dark because their anodes are either pulled to ground or in a high impedance state. After the pattern on the first digit is displayed, the next digit is activated by powering its anode and placing a pattern of low levels and high impedances on the other seven outputs. A stable pattern of eight characters is displayed by repeatedly cycling through all the digits.

The first challenge was to recast my VHDL code for the LED driver into MyHDL. I had an academic understanding of MyHDL, but that's quite different from actually constructing something that compiles, simulates and synthesizes into an FPGA. Obviously the syntax of MyHDL is different from VHDL, but you also have to re-learn how a design should be organized and partitioned for a new language.

One of the challenges I faced was the heavy use of tristate outputs in the design. MyHDL supports tristate buses, but it doesn't allow bits within a bus to be individually tristated. So I had to break the eight-bit LED driver bus into eight individual signals, which made it more cumbersome to handle since loops couldn't be used.

The MyHDL compiler converts MyHDL source code into Verilog or VHDL that is passed to the synthesis tools for a particular FPGA. But I found the Verilog and VHDL code for the tristate outputs wasn't actually connecting them to the internal logic in the driver. This problem was eventually resolved by attaching each tristate port to a dummy signal inside the driver code so that the port looked more like a true I/O port. It was easiest to implement this fix by building a separate tristate module and instantiating it eight times, once for each output. More cumbersome code.

I attempted to clean the code and make it more parameterized by refactoring it to use loops. While this worked in simulation, and was convertible into Verilog, the yosys synthesizer choked on it because it was, in fact, not synthesizable. So I had to remove the loops and use a more "unrolled" coding style. More cumbersome code.

Finally, I designed some code to send inputs to the LED driver and display a pattern of eight characters. Unfortunately, using an array of byte-wide signal vectors for the characters led to some strange errors. Instead, I had to use a single 64-bit vector with each eight-bit field representing a character to get the behavior I wanted.

After all was said and done, I finally got the LED driver to work:

Discussions

andrea venturi wrote 11/15/2015 at 09:25 point

hi Dave, your Cat board is really inspiring!!

are you going to make a production run, some day?

on the other hand, do you think the Gerber coming out of the Kicad prj on the github tree are ready to run on some site like Oshpark? 

i can't wait playing with the full open source stack for HDL development!

thanx for the gift!

  Are you sure? yes | no

Dave Vandenbout wrote 12/02/2015 at 16:03 point

Hi, Andrea. Thanks for the comment! Apologies for my late reply.

I'm not sure about a production run. I did a bit of costing on the board+parts+assembly and I don't think I can sell it directly for much less than $50. Normally I would consider that a good price. But customer buying habits have changed because they compare it to a one-time purchase of a board on places like Kickstarter at a price that won't sustain a real business.

The Gerber files can be manufactured at PCBWay because they offer 4/4 trace/space design rules and they can do 8-mil drill holes. (The drill holes are what really drive the cost up.) The publicly-available OSHPark design rules are 6/6 trace/space and 13-mil drill holes (I think). There's no way to do the CAT Board PCB with that.

  Are you sure? yes | no

andrea venturi wrote 12/02/2015 at 16:25 point

personally speaking, i would commit for an ice40-8k board for $50.. :-)

it's of course a device with a totally different "scope" then a snickerdoodle or a raspberry zero, but i understand it's a "niche market" not justifying the effort on any business perspective.

then recently i've heard about the  icoboard project on a similar board with ice40:

http://icoboard.org/ 

let's see if they get a good feeling from 32C3 and so if they go further with a production run. i bet the price would be in the same ballpark of your one budget..

i suppose the fastest way to get my hands on a ice40 supported by the open toolchain is really the Lattice semi -8k ref board..

  Are you sure? yes | no

darkstar007 wrote 11/04/2015 at 08:29 point

Looking interesting! Have you added these issues to the MyHDL bug tracker? 

  Are you sure? yes | no

Dave Vandenbout wrote 11/04/2015 at 13:04 point

I'm getting ready to do that. I'm trying to find minimal-sized examples that exhibit the problems.

  Are you sure? yes | no

darkstar007 wrote 11/05/2015 at 08:01 point

Yeah, finding a simple example of the issue ('catching it in the act') can be time consuming but essential.

  Are you sure? yes | no

Dave Vandenbout wrote 11/03/2015 at 13:45 point

Ha ha! Well, maybe. Maybe not. At least I see where a lot of the potholes are and maybe I can avoid them. 

  Are you sure? yes | no

Yann Guidon / YGDES wrote 11/03/2015 at 08:53 point

Awesome !

  Are you sure? yes | no