This page is here to host some of my projects that I have decided to release to public domain. Feels free to download them and use them. Let me know if you find any of my work is useful. Have fun. ^_^
For some visual experience, please visit my picture library!
To contact me, my e-mail is at the bottom of the page.
Nov 7, 2009 Simple Delta Sigma DAC
Ever have a need to output analog signal from a FPGA? Here is a simple solution that can be used
to output audio quality sound from FPGA. Best of all, only 1 pin is required per audio channel.
June 20, 2009 Building a poorguy's LCR bridge
Ever have a need to measure capacitance or inductance accuractly but can't spend the money to buy
an expensive equipment? Here is a way to build a cheap LCR bridge for under $10.
March 11, 2009 A simple 32 bit Floating point adder core
A simple floating point adder that is used to demostrate how floating point math works. The
design is pure combinatorial with no pipelining. It would not be hard to add pipeline support to
the core. Only basic simulation testing has been done, so you should not trust the output of this
core. This is mainly an execise to show how the math core works, not currently intended to be
used in real project.
Febrary 22, 2009 A simple 32 bit DSP core
A simple DSP core that is designed for implementation of filters. The core is mostly intended to
use the limited multipliers in the FPGA more efficiently by time sharing the resource. The result
is by using 4 multiplier resource, it is possible to do multi-order filters at audio frequency.
November 3, 2008 USB audio project
This is my Digital Audio interface project. The objective of this project is to build a fundation
where future digital audio project can be build upon. The simple project has a USB interface to
accept raw digital audio data. An audio grade DAC to convert the digital audio sample to audio
stream to be connected to the speakers. In the middle there are several FIFO and a sample rate
converter that can be adapted into various uses.
October 19, 2008 psramfifo.v
This is a module I found to be very useful myself, thus I posted it here to share it with anyone
who can make use of it. This is a simple module that controlls the PSRAM on the Nexys / Nexys2
FPGA development board from Digilent and use it as a simple FIFO. Minimal number of connections
are required to controll the entire FIFO. The FIFO is configured as 8M x 16bits. I found it is
the simplest way to put the PSRAM chip on the board into good use. Discription for connections
can be found in the source file itself. The code is adapted from the PSRAM controller used in the
digital camera project.
USBinf.v
This is another project that I found to be quite useful. I've used this as the fundation for many
of my own projects. The module translate the Digilent EPP like interface to an 8 bit wide
Wishbone interface and with 16 bit address. The module exposes 3 address on the EPP line.
0 - Lower address byte (write only)
1 - Upper address byte (write only)
3 - Data byte (read and write)
With this module, I can use the PC as the microprocessor of the SoC design. Although the link
speed is not as fast as I would like, and there is no interrupt support (Other than using the
serial interface on Nesys2 board as the interrupt source, more of that to come), the ease of
working with software directly on the PC is a clear advantage for many simple projects.
June 8, 2008
Transistor FM radio. FM radio
A simple FM radio using only 2N3904 NPN trnasistors as active components.
Mar 30, 2008
Linux driver for Digilent USB interface. This is a driver that works with the Digilent USB
interface found on Nexys and
Nexys2
FPGA development board created by Digilnet. Unfortunally Digilent did not provide a Linux
driver. I can see the FPGA board combine with a ultralight laptop such as
ASUS EeePC can be a powerful combo that is highly suited for
data acquisition, data processing and system control. Thus, it is only reasonable that I gone
ahead and hack up a driver for the interface. The driver is written for 2.6 kernel. The driver
is designed to work with sysfs. Three attribute file are created per device.
epp_addr contain
the address information. epp_data is the file you can read or write to put or get a single byte
from the interface. The data appear on these two attribute files are human readable and is in
decimel format. bulk_data is a binary interface that allow large amount of data to be transfered
into a signle address. Note, due to OS limitation, the block size is limited to 4096 bytes. This
somehow limits the performance of the interface to roughly 3Mbyte/sec. There is no limitation as
to how much total data that can be transfered. I recommand using dd to access this interface.
There are a few bugs to the driver I still have to work them out. First, two vendor request must
be sent before any transfer can take place. For some reason, these two request always fail.
Although the failure of these transferes do not appear to have any impact on the data transfer
operation. Second, I do see the bulk transfer fail once in a while. I'm still not sure what is
causing this.
Although this driver is not consider complete, I'm putting it up as I'm sure people can find some
good use of it. To compile the file, simply extract the tarball and hit make follow by insmod.
The usual location where the interface is found is under /sys/bus/usb/drivers/digilent_usb/
Unfortunally, one function this driver do not support is the JTAG programming of the onboard
logics. digilent.tar.gz
Mar 10, 2008
Hacking the PV2 disposable digital camera - Sensor hack. MY PV2 CMOS sensor
This is a project to extract the data from the CMOS image sensor from the PV2 digital camera.
Jan 5, 2008
Got a ink-jet printer that is lying around and you don't have any good use for it? Why not build
an emergency radio out of it? Hacking a cheap ink-jet printer
Jan 5, 2008
Quick and dirty implementation of a PIC microprocessor. The ISA can be modified to other 8-bit
accumulator based ALU design. I use PIC ISA becase I know the ISA well and didn't bother to
create my own ISA. pic_base.v Main file that implemented the processor core pic_pack.zip Set of files the you can run it through Xilinx ISE and
run it on Nexys development board
Nov 23, 2007
Simple servo controller using PIC microcontroller:
This is a simple servo controller design. The PC is connected to the microprocessor through
the good old RS232 port. The microcontroller can control up to two servo. ServoControl-1.ASM Servo controller
Oct 6, 2007
File related to the development using Digilent Nexys board: LED_7seg.v Driver for the 7 segment LED ezReg.exe Modification to the PC side demo code to allow easier
shell scripting
May 1, 2007
My RFID reader project. The project is to read the RFID tags produced by HID. Although the tag
is designed to work with a carrier frequency of 125KHz, I made a mistake and designed the whole
thigh with 150kHz carrier. It works just fine though. The communication with PC is done through
the serial port as usual. The baudrate is 57600 for this project, crystal is 12MHz. PA0 and PA2
is used for incoming data. PB1 and PB2 is UART connection. PB3 has 150KHz carrier frequency
output. Primary command is '3' for full data decode. More detail will follow soon. Reader_1.ASM Link to my RFID document web page
IP blocks for the Spartan 3E starter kit:
The is the big project I've been working on for a long time, I intended to release these IP blocks
each module at a time. Eventually, all the IP block will be assembled together to use the full
feature of the Spartan 3E starter kit.
DDR-SDRAM/ADC/DAC Demo project. Posted Mar. 3rd, 2007
This is a stand along project to demonstrate the usage of the onboard ADC/DAC/DDR-SDRAM. With the
combination of these three compoenets, what is a good project? How about a digital audio
recorder? Sure sounds good to me!
The project uses the ADC to sample a sterio audio stream and can play it back using the DAC. Only
12bit audio is sampled, this is due to the limitation of the onboard DAC, although the data stored
in the DDR-SDRAM is 14bit. The ADC is a bit noisy for audio application, but for a demonstration, it works
fine. Sampling rate is set at 40KHz, which stores about 7 minutes of audio.
Control is done though the push buttons. North = Clock reset, South = Stop, East = Record, West =
Play and Rot-center = Clear memory and set the gain of the ADC. Center button must be pressed
upon boot-up to ensure the gain of the ADC is set correctly.
The input audio should be 3Vp-p with center voltage of 3.3V/2 = 1.65V.
The output audio is also 3Vp-p with center voltage of 1.65V. Total system gain is set to 1x,
although this is adjustable through code update. Recorder Project Files
Simple ASCII display controller. Posted Apr. 5th, 2007
The idea behind this project is to produce a really simple controller for the ASCII LCD that
is attached to the S3E starter kit. The controller sends command and data to the LCD to display
simple message without the aid of a microcontroller. The entire controller is implemented
in a single state machine. The main function of the controller is to send either data/command
to the LCD display, insert delay between each transmission and stop the display when the text
stream is finished displaying. Currently supporting only a single message. Display Controller Project Files
SPI to Wishbone block. Posted Nov. 12, 2006
The idea is to use inexpensive MPU outside of the FPGA to control all the function and act as the
brain of the system. Although softcore MPU works quite well for FPGA, it takes some effort to
integrate it. External MPU is well understood and easy to use and program. The interface
selected is SPI bus, which gives decent performance with the use of only 4 wires. J1, J2 and J4 on
the starter kits can each accept an SPI bus, makes it very easy to interface with. mpu_spi.v and the document to go with it
spi.svg spi.c An example driver for the spi to wishbone block.
Updated Feb. 25, 2007 mpu_spi_32.v - A 32 bit version of the SPI to Wishbone
translator
NOR FLASH memory controller block. Posted Nov. 12, 2006
The block allows the onboard Intel FLASH memory to be accessable on the Wishbone bus. Since the
implementation of the Wishbone bus is only 8 bit only, this block is designed to work only with
8 bit mode. This block allows the reading and writing of the FLASH memory. nor_flash.v and the document to go with it
nor_flash.svg norFlash.c An example driver for the NOR flash.
Dual modulus clock divider block. Posted Dec. 9, 2006
This is a clock divider module that can be use to generate a output clock that is slower than the
incoming clock source. One nice advantage of the dual modulus clock divider is it can divide the
souce clock frequency by a non-integer value. The down side is the generated clock will have
certain amount of jitter. Basic design concept referenced from an article in EDN. Issue 20, 2006,
pp. 65. DualModDiv.v and the calculation table to go with it
ClockCalc.ods
Quick and dirty UART block. Posted Dec. 13, 2006
This is a very simple UART that only have a single stage buffer. An external FIFO block can be
attached to form a full functional UART. This simple UART was designed to output debug message
and accpet simple command from the PC without the aid of a microcontroller. UART.v
Project base on Spartan 3E starter kit:
SPDIF decoder, output using onboard D2A chip. Posted Nov 24, 2006
The project receive the SPDIF data input from pin A6 and output the decoded audio to the onboard
D2A. The onboard D2A only support up to 12bit, so there is a loss of quality. No polishing of
the data is done, so only flat-top sampling is used, distortion at high frequency is expected.
But than, this is only a proof of concept project.
The SPDIF receiver is quite sensitive to distortion in incoming signal. TTL output from CD player
works great, output from 75ohm coxal source will need the signal boosted. No error checking is
implemented.
Next step in this project is to build a more robust de-serializer which is less sensitive to clock
jitter. SPDIF.zip.
Update Nov 25, 2006
New version of the bit clock extraction routine. This version can detect the offset from 50% duty
cycle and correct for this non-ideality. The deserializer routine is now a seperate module for
easy integration into other projects. An check sum calculator has been added. Error counter can
be viewed from the output LED to see if the input data stream is clean. Error in data will not
cause the sample to be dropped though. SPDIF2.zip.
Hacking the PV2 disposable digital camera. Posted Sep. 16, 2006 MY PV2 page
Mp3 Player buid with STA015T decoder with AT89C51RB2 as microcontroller. Posted Dec 16, 2004
This is my second MP3 player build around the MP3 decoding chip from ST. This perticular design is aim for a portable system. However, the D/A chip used require 5V power supply, so a dual voltage inverter is required to boost the voltage from 2 AA cell to both 3.3V and 5V. The power supply has not been designed yet. Currently, this design is working with bitstream up to 192kbit with SD memory and 128kbit with MMC. View Schematic Download Firmware View picture View Another picture
Enumeration Code for Cypress EZ-USB chip. Posted Dec 10, 2004
This project uses the popular EZ-USB chip by Ancher Chiip which is bought out by Cypress as the fundation to create other projects. Download Enumeration.zip
Temperature recoding device. Posted Oct 11, 2004
This project uses 16F628A as the microprocessor, TC-77 for temperature sensing and 24LC64 as storage device. The objective is to create a low power temperature recoding device. The entire device consumes 400uA of current. The power is supplied by a standard battery pack (3.6V) for cordless phone. Lower power comsumption is possible if the shutdown code is implemented for the TC-77 temperature sensor, however, due to the time limitation, it is not available in this version of the code.
There are many command implemented in this code. The key command is 6, which stop the data capture routine. Command 3 which dump out the data in hex format. The data can be captured using any serial terminal software such as miniterm or hyperterm. Command 9 clear the entire EEPROM and write 0xff into all the cell. This helps to mark where the data capture ends. Download TempBase.asm View the schematic View the completed project
Version 2 released. Posted May 16, 2005
New update to increase the download speed. This is done though the use of a higher speed crystal for the main clock. 32KHz crystal is still used for timer 1. Sleep instruction is issued one minutes after the device is activated to conserve battery power (Although most of the power is actually consumed by the temperature sensor, can be eliminated though the use of shutdown mode for the temperature sensor, which is still not implemented. Several of the connection to the EEPROM is changed in this design. Please refer to the source code description for connection information until the schematic is released. Download TempBaseV2.asm
USB Full speed node fundation code. Posted Feb 1, 2004
A quick schematic is available - View
Updated Feb 10, 2004 - Updated to include standard device requests
USBbase.asm
Driver code for this device MyUSB_driver.c
This code is designed to work with PIC16 series processor and the USB interface chip USBN9603 and USBN9604 from National Semiconductor. The code provide a fundation for which further development for USB can be developed upon. The connection between the microprocessor and the USB controller is through the serial interface.
Implemented feature:
Endpoint 0, IN/OUT Bulk endpoint 1
Device request: Set address, Get descriptor, set configuration(partially)
Todo: Finish implement all the device requests.
This code is tested on Linux kernel 2.4.20. and is able to enumerate to a new address and exchange descriptor information.
The driver code create a file (myusb) in the /proc directory and you can read and write to the USB device by writing and reading the file.
Here is a picture of the interface board: View image
Updated Sep 25, 2004 - Fixed bugs that cause error during enumeration
USBbase2.asm
I found several bugs that prevents the device from enumerating properly. Those bugs are fixed now. Thare are still
a lot of debug message inside the code, which makes the code slight hard to read. Those code will be removed once
all the bugs has been fixed. Currently, there are still some bugs prevents the device from being enumerated properly
when connected though a hub. The IN1 pipe is also broken.
TODOs: Fix the bug and to rewrite the enumeration process so it is non-blocking
Updated Oct 6, 2004 - Fixed bugs that prevent the device from enumerated properly under WindowsXP
USBbase3.asm
This updated firmware will work under Windows and Linux. Tested with both UHCI and OCHI controller. Also tested with the use of a USB hub. Bug with the IN1 pipe is also fixed.
Enabled pipe includes EP1-OUT and EP1-IN. OUT1 will accept any packet and display them through the serial terminal. The IN1 will send a string TEST follow by a number increase by one everytime a IN packet is sent.
The enumeration code is now non-blocking.
New feature added: Vendor request 10-IN. This will send two byte of data fixed to 0x0100 and will accept wValue. The low byte of the wValue will be used to set the output on PortA.
Remote control for Nikon Camera. Posted Apr 26, 2004
Should work with D70, Pronea S, Nuvis S, Nuvis S2000, Nuvis V and F65/N65/N75. Code is compatable with ML-L3.
There are two version of the code, one for PIC12C508, which is what I intented to use due to the compact size. However, I later found the PIC12C508 does not work well with 3.0 volt of power coming from Lithium cells. PIC16C84 works fine with the low voltage.
The range of the remote is about 4 meters with a IR diode set to 30mA(Series resistance of 39ohm).
Code for the PIC12C508 version.
Code for the PIC16C84 version.
These code can be easily ported to other processor and different frequency. However, I thought a clock frequency of 4Mhz is easier to obtain.
The IR code is extracted from the database file provided by Nate's website
iWire bus open specification. Posted Jan 12, 2004
iWire bus was designed as a free standard for communication between several PIC processors. This is a software defined bus, therefore, it does not require any hardware support to work with this bus. The only hardware requirement is two free I/O lines. The bus was designed as a method of exchanging data on a data capturing system.
iWire bus specification: 1wire Specification.pdf
iWire bus Master code: MasterPic.ASM
iWire bus Master code: MasterPicV2.ASM - Version 2.2
iWire bus Client code: 4TDRIVER_LCD.ASM
The sample Client code also contain my LCD library. The code should work with most LCD with Hitachi LM032L or compatable driver.
Updated July 11, 2004 - There are several bugs in the Master code that has been fixed. The error causes the serial communication to lost some bytes of data during high speed transfer. The newest version is 2.2 btdownloaddaemon.py
Posted Nov 12, 2003
Updated Nov 23, 2003 - Found some bug in the script that causes it to crash during verification phase. Fixed now
Note - The script is checked to confirm to work with version 3.4.2 of the BitTorrent client script.
Bittorrent is great for download large Linux distribution overnight, but if you want to serve the file overnight using a cron job when there are little to no internet useage, an error pops up. This is due the fact Bittorrent needs to write the output message to a terminal, which does not exist for cron job. Here is a simple solution:
This is a modified version of the btdownloaddeamon.py, a Unix Deamon verson of btdownloadheadless.py written by Shawn. The origional version is here
This modification makes it compatable with BitTorrent 3.3
Note: This modified version only works on UNIX system.
To install, download and install pylog (http://www.red-dove.com/python_logging.html)
Than run btdownloaddeamon.py as you would with btdownloadheadless.py. First_r3.asm
Posted Aug 30, 2003
This is my first project utilizing the new PIC16F628A microprocessor. This project is a LCD clock that runs on a
three volt battery. The entire project consumes less than 30uA of current.
Please visit My Passive LCD page for more information.
Schematic can be found heree16f628a.asm
Posted Aug 9, 2003
The new PIC16F628 is a powerful replacement for PIC16F84, and PIC16F628A is a new revision that is cheaper
and runs much faster. However, currently there is no support for PICSTART PLUS. I have run some test and
realized that you can program PIC16F628A using PIC16F628 mode, however, you can not erase the chip.
This small project is intended to overcome this limitation until Microchip release new firmware for PICSTART
PLUS. Note, the configuration word for PIC16F628A is slightly different, if you use code protect or internal
oscallator, please check with datasheet at Microchip's website.
Here is the schematic. Quality is not that great... gba_mb.asm
Posted March 19, 2003
This is a enhanced version GBA multiboot cable base on http://ajo.thinknerd.com/gba/.
The cable is fully compatable with the original multiboot cable, but with the ability to store a multiboot image file on a flash memory, so you can download multiboot image file without using a PC.
More information regarding on how to build the device when I find time to do so.
Note, there is a small bug in the firmware which require the microprocessor to be resetted few
times before it will start to download. I'll fix it as soon as I can find time.
Update: Current version is now 0.1.1, the fail to start to download bug has been fixed.
Note: The cable will not run normally in stand-along mode if the printer cable is attached. If you wish to download the code without using a PC, please remove the printer cable attached to the multi-boot cable.
The schematic is now available.
Update(Apr 13, 2003): Fixed several mistakes in the schematics and added the missing component values.
The PC side tool, this is only a development version, no userinterface has been implemented.
Update: I forget to remove a block of code that is commented out, which causes the software run in verification mode instead of writing the data to FLASH memory. It has been fixed now.
A picture of the cable is available here Sinewave.zip
Posted July 24, 2003
Need to test out your newly built multiboot cable but can't find a good application? Why not tryout my sinewave generator. This multiboot file turn your GBA into a portable sinewave generator utilizing GBA's sound system! Source included.
keypad.asm
Posted March 19, 2003
Want to connect your old SNES pad onto your PC and use it as an extra keyboard or gamepad?
This is the firmware for PIC16F84 processor which let you use it as a keyboard controller.
Most of the source file available on this website uses either the GPL or LGPL license. You can
find a copy of these license by click on the following link: LGPL /
GPLPage created with VIM Page last updated: May 1st, 2007
Email: rihuang ([at]) gmail (*dot*) com
This page is best viewed with Mozilla Firefox