Programmable Logic

Posted: April 10, 2015 in Electronics

I’ve been interested in programmable logic for a while now. Recently, I bought a couple of cheap dev boards; One Altera MAX II EPM240 (available on ebay for less than $10AU delivered to Australia);


And one XC9572XL CPLD dev board from dangerous prototypes ($15US + postage)


(also, thanks to this post I’m tempted to take a look at these as well. I’ll save that for a later post)

Let’s take a look at the two devices in a bit more detail:

Altera MAX II EPM240

  • 240 Logic Elements (LEs)
  • Each LE consists of a 4-bit LookUpTable (LUT) and a register
  • Lots of interconnect between the LEs
  • 80 user I/O pins
  • Configuration is stored in on-board flash
  • 8kbits of user flash available
  • on-board clock
  • 3.3V  I/O

Xilinx XC9572XL

  • 72 Macro cells
  • Each Macro Cell has a single output which can be selected from a sum-of-products of the inputs  plus a register
  • Lots of interconnect between the Macro Cells
  • 34 user I/O pins
  • 5V tolerant I/O

What I take away from this is; a) the MaxII is more like a small FPGA with internal config flash. b) The MaxII is more powerfull c) the XC9572 is useful for 5V logic

While I was waiting for the boards to arrive, I downloaded the design software for both (Altera Quartus II Web Edition and Xilinx ISE WebPack). Note; these are big downloads (several GB each).

Quartus supports many different design file types that can be used to create a design. Which one should I choose? I looked at 3 options; schematic, Verilog, and VHDL.


If you are used to designing logic circuits with discrete logic chips, this is probably the easiest way to get started. That’s certainly what I found.


VHDL is a hardware description language.  According to wikipedia ( it is was developed in the 80s at the behest of the US Dept of Defense. It was infulenced by Ada and Pascal.


Verilog is another hardware description language. It has a syntax similar to C and was also developed in the 80s. (see for more details)

After some investigation on the web, I decided that I would try Verilog, since it has a c-like syntax and I’m used to C.

What am I going to design? I had a couple of ideas; some glue logic for a 8-bit computer (that’s why I got the XC9572XL , as it has 5V tolerant inputs); and a simple 4-bit CPU.

Before I tackle these, I wanted to validate my choice of design input by building a simple design in each of Schematic, VHDL and Verilog. I chose a Hex to 7-segment decoder as the test. Here is the block diagram drawn in Quartus II.


It consists of a 3 quad d-type flip/flops or latches which are driven by 4 common input pins and 3 clock pins. Each latch output drives a hex to seven-segment decoder. The decoder outputs then drive LED displays. Each hex to seven-segment decoder is designed using a different input file (schematic, VHDL, Verilog)

Next time I’ll look at the detail of each hex seven-segment decoder.

Sensor network

Posted: November 4, 2013 in IOT

After partial success with 433MHz transmitters and a custom Manchester encoded library, I’ve decided to switch to using NRF24L01+ modules.

These are 2.4GHz, which in theory have a more limited indoor range. My testing so far shows I can reach from the study to the far end of the garden, which is though 3 walls.

So, I’m going to build a number of sensors using Arduino Pro Mini boards, with a Raspberry pi to connect to the network.

The RF24 modules are much easier to use, and can connect directly to the rpi (no need for accurate timing as with the Manchester endoding).

The disadvantage is the number of pins required to connect : 4 SPI, + CSN + IRQ (optional)

This rules out the ATTiny85 (unless I multiplex the pins and/or don’t connect any external sensors)

But the Arduino Pro mini boards are now very cheap.

Cost of pro mini + RF24 is less than 10AUD


Posted: November 4, 2013 in IOT, Linux

Building LIRC for DP USB IR Toy


How I built LIRC with USB IR Toy support

matt@desktop:~$ git clone git://
Cloning into 'lirc'...
remote: Counting objects: 13436, done.
remote: Compressing objects: 100% (3474/3474), done.
remote: Total 13436 (delta 10403), reused 12735 (delta 9826)
Receiving objects: 100% (13436/13436), 2.60 MiB | 534 KiB/s, done.
Resolving deltas: 100% (10403/10403), done.
matt@desktop:~$ cd lirc
matt@desktop:~/lirc$ wget
--2013-09-13 21:07:57--
Resolving (, 2a01:1e8:e100:27c::2
Connecting to (||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19871 (19K) [text/plain]
Saving to: 'lirc-0.9.0-usb_irtoy.patch'
100%[==================================================>] 19,871 58.8K/s in 0.3s
2013-09-13 21:07:58 (58.8 KB/s) - 'lirc-0.9.0-usb_irtoy.patch' saved [19871/19871]
matt@desktop:~/lirc$ patch -p1 < lirc-0.9.0-usb_irtoy.patch
patching file
Hunk #2 succeeded at 446 (offset -1 lines).
Hunk #3 succeeded at 680 (offset -1 lines).
Hunk #4 succeeded at 1394 (offset -1 lines).
patching file daemons/hw-types.c
patching file daemons/hw_usbirtoy.c
patching file
patching file
matt@desktop:~/lirc$ ./
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./config.guess'
libtoolize: copying file `./config.sub'
libtoolize: copying file `./install-sh'
libtoolize: copying file `./'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in installing `./compile' installing `./missing'
daemons/ installing `./depcomp' installing `./INSTALL'
Creating ...
matt@desktop:~/lirc$ ./configure --with-driver=usb_irtoy --without-x --with-tty=/dev/usbirtoy
matt@desktop:~/lirc$ ./configure --with-driver=usb_irtoy --without-x --with-tty=/dev/usbirtoy
checking for a BSD-compatible install... /usr/bin/install -c
. config.status: executing libtool commands
Your hardware does not require a special LIRC kernel module.
You will have to use the suitable kernel driver to access /dev/usbirtoy.
Now enter 'make' and 'make install' to compile and install the package.
matt@desktop:~/lirc$ make
matt@desktop:~/lirc$ sudo make install
matt@desktop:~$ cat /etc/udev/rules.d/60-usb_irtoy.rules
SUBSYSTEM=="tty",KERNEL=="ttyACM*",ATTRS{manufacturer}=="Dangerous Prototypes", ATTRS{product}=="CDC Test", ATTRS{serial}=="00000001",SYMLINK+="usbirtoy"