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
solar-blogg
Electronics & Microcontrollers
Tuesday, November 1, 2011
Monday, October 31, 2011
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.
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 ); //Registers 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) begin 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 case(state) 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; end 10: begin rMemWR <= 1; //pull write enable to high again end 50: begin rMemDB <= 16'bzzzzzzzzzzzzzzzz; //set the data bus to high impedance rMemOE <= 0; //pull output enable low to start a read state <= 60; end 60: begin rLed[3:0] <= MemDB[7:0]; //set the LEDs to show the data state <= 70; end 70: begin rMemOE <= 1; //pull output enable high again end endcase end end endmodule
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.
Requirements:
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.
Requirements:
- 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); INTEnableSystemMultiVectoredInt();And the interrupt handler:
void __ISR(_TIMER_1_VECTOR, ipl2) _Timer1Handler(void) {
mT1ClearIntFlag();
//Your code
}
PIC32 pin change interrupt
The following is a quick snippet for interrupt on change pin
And, in your initializing code:
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) {
mPORTDRead(); //Need to read the port (see PIC32 datasheet)
mCNClearIntFlag();
//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 ConfigIntCN(CHANGE_INT_ON | CHANGE_INT_PRI_2); INTEnableSystemMultiVectoredInt();
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.
Subscribe to:
Posts (Atom)
