Tuesday, November 1, 2011

Nexys 2/Spartan 3E LED blinker and counter

Here's a verilog project I coded for the Nexys 2/Spartan 3E - a simple LED counter and multiplexed 7 segment display counter.

Download project

Monday, October 31, 2011


FT232H - High speed USB 2.0 interface. Can communicate via high speed parallel FIFO interface at up to 40MBytes/s. Should be very easy to interface to an FPGA or MCU.

Friday, October 7, 2011

pSRAM memory test for the Nexys 2

This is a very simple pSRAM memory test for the Nexys 2 with the Spartan 3E 500 FPGA. Simply writes and reads back the memory.

Note that the RAM chip on the Nexys 2 board is the MT45W8MW16BGX in a BGA package.

module Main(
 input wire clk,
 output wire [7:0] Led,
 input wire [3:0] btn,
 output wire MemOE,
 output wire MemWR,
 output wire RamAdv,
 output wire RamCS,
 output wire RamClk,
 output wire RamLB,
 output wire RamUB,
 output wire [23:1] MemAdr,
 inout wire [15:0] MemDB

reg [31:0] state = 0;
reg [7:0] rLed;

reg rMemOE = 1;
reg rMemWR = 1;
reg [15:0] rMemDB;
reg [23:1] rMemAdr;

//Static assignments
assign RamCS = 0; //chip select is always low (enabled)
assign RamClk = 0; //clk is disabled in asynchronous mode
assign RamAdv = 0; //address valid can always be pulled low in asynchronous mode
assign RamLB = 0; //lower byte is enabled
assign RamUB = 0; //upper byte is enabled

//Register assignments
assign MemOE = rMemOE;
assign MemWR = rMemWR;
assign MemDB[15:0] = rMemDB[15:0];
assign MemAdr[23:1] = rMemAdr[23:1];

assign Led[7:0] = rLed[7:0];

always @(posedge clk)
 if(btn[0])      //btn[0] is reset/write
  state <= 0;
 else if(btn[1])    //btn[1] is read
  state <= 50;
 else if(btn[2])    //btn[2] just toggles Led[7]
  rLed[7] <= ~rLed[7]; 
 else begin
   0: begin
    rMemAdr <= 23'b0;  //set address to 0
    rMemDB <= 16'h0505;  //write 0x0505 to the data bus
    rMemWR <= 0;   //pull write enable low to write the data
    state <= 10;
   10: begin
    rMemWR <= 1;   //pull write enable to high again
   50: begin
    rMemDB <= 16'bzzzzzzzzzzzzzzzz;  //set the data bus to high impedance
    rMemOE <= 0;      //pull output enable low to start a read
    state <= 60;
   60: begin
    rLed[3:0] <= MemDB[7:0];   //set the LEDs to show the data
    state <= 70;
   70: begin
    rMemOE <= 1;      //pull output enable high again


Thursday, September 29, 2011

UBW32 Generic USB demo

I ported and cleaned up the generic USB demo from the Microchip application libraries. The project is designed to work with the UBW32.

  • UBW32 or any other pic32 microcontroller board.
  • PICKIT/ICD/REALICE to program your board, or a linker script to load with the USB bootloader.

Download the project and compile/flash the firmware onto your chip. Open the USB/Device - LibUSB - Generic Driver Demo host program for your operating system. Attach your device to the host and connect.

PIC32 Timer1 example code

The following code snippet opens and uses Timer1 as an interrupt. In your initialization sequence:
//Open Timer1 with 1:8 prescaler (80MHz -> 10MHz), with period of 10, therefore tick = 1MHz.
OpenTimer1(T1_ON | T1_PS_1_8 | T1_SOURCE_INT, 10);
ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2);
And the interrupt handler:
void __ISR(_TIMER_1_VECTOR, ipl2) _Timer1Handler(void) {
	//Your code

PIC32 pin change interrupt

The following is a quick snippet for interrupt on change pin
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) {            
	mPORTDRead(); //Need to read the port (see PIC32 datasheet)
	//Your code...

And, in your initializing code:

mCNOpen(CN_ON | CN_IDLE_CON, CN13_ENABLE | CN14_ENABLE | CN15_ENABLE, CN_PULLUP_DISABLE_ALL); //See plib documentation and PIC32 datasheet

Monday, September 26, 2011

Crimping a modular connector without a cimp tool

So it turns out that the guy at the local electronics store near the university is too damn cheap to lend me a crimp tool for literally 10 seconds, and would rather charge me $5 to merely crimp a header onto the end of a cable. So I decided to crimp the modular header (for ICD) onto a the cable myself. I decided to instead use a flat ribbon cable (like the computer IDE cable) since they're thinner and much more flexible than the 6 wire telephone cable I bought. The wire-to-wire pitch is slightly larger than for a normal telephone type (6p6c) cable so you can't insert it directly, but if you pull the individual wires apart to about 5mm from the end, and then put them in, it works out well. Crimping without a tool was a snap - took only about a minute with nothing more than a flat head screwdriver to push in the tab as well as each of the contacts.

Friday, September 23, 2011

Simple USB Hello World for PIC32 (UBW32)

Here's a simple USB Hello World program that I wrote/modified/set up for the PIC32 (specifically UBW32 board, but any PIC32 will run it). It's a very quick, minimal, bare bones project, with minimal comments and clutter, formatted nicely.

Download project



1. Open the project in MPLAB (I'm using 8.76 with C32 v2.01).
2. Go to Build Options (green button on toolbar)
3. Go to Directories -> Include Search Path and edit the MAL line to your Microchip Applications Library Include folder. Go to Library Search Path and edit the line to your C32 libraries folder.
4. If you are NOT using the UBW32 board, edit HardwareProfile.h for your board (LEDs, etc). Also make sure to select your specific chip from Configure -> Select device...
5. Compile and program your board with a PICKIT/ICD/REAL ICE. This package does NOT support the bootloader because I use a REAL ICE to program my board, although you could probably very easily load it from the UBW32 bootloader by compiling it with the procdefs.ld file from the HelloWorldUSB package from the UBW32 website.
6. When the board is running the program, open a terminal program on the host computer (for example, Termite on Windows, or the "screen" command line tool on Linux/Mac OS X). Type something. You should see text sent back on the terminal.

Friday, September 16, 2011

Constant current source/sink

A very accurate MOSFET current source/sink I designed.

Number of MOSFETs is variable. I designed this for load testing, so the circuit is using 4 MOSFETs to be able to dissipate more power. As can be seen on the bottom graph (green), it works well down to very low voltages due to the use of MOSFETs instead of BJTs.

Sunday, March 6, 2011

FPGA first post

I've been looking into FPGAs.


Development boards:
Papilio One (250K gates)
Basys 2 (100K/250K gates)

Much more information to come as I find it.