08 July, 2013

Verilog coding style

Recently I was asked by some HDL beginners about a coding style for Verilog. This was the first time I actually had to think about my reasons for certain style choices from the point of view of beginners, usually I only discuss coding style with other experienced HDL coders. The exercise produced some interesting results.

https://github.com/jeras/verilog_coding_style

20 March, 2013

Giant Point of View with the Oculus Rift and a drone

There is one application of the Oculus Rift I would like to see, lets call it the Giant Point of View of GPOW. The basic principle is to capture an image with a 3D camera (or two cameras) with objectives far apart (further apart then the distance between eyes), and then observe the video stream (or recording) using the Oculus Rift. If the cameras were placed on a drone like a quad-copter flying through a city. Watching the video could feel like a first person Godzilla rampage.

The parallax effect is increased, giving the observer an enhanced perception of depth. In practice everything (trees, buildings, cars, people) should look small, ant the observer should feel like a giant.

The idea comes from XKCD, but there is also an old military technology (binoculars with objective lenses far apart) based on the same principle. I remember it from some old communist era military education school book, but I was not able to find any examples with a quick search on Google. The closest I could get to were "periscope binoculars".

20 February, 2011

Experimenting with Verilator (counter)

Verilator is a open source Verilog HDL simulator. It is very fast since it translates Verilog code into optimized C++. But it as also quiet different from other Verilog simulators like Icarus Verilog and commercial ones, it only supports synthesizable RTL language constructs.

This are my first successful Verilator experiments. I was looking for a counter example, but was not able to find one, so I decided to write one myself and publish it. The instructions are for Ubuntu.

First write a verilog RTL counter. This example has two registers, one running at clock posedge, the other on negedge. I just wished to check if using both clock edges still qualifies as synthesizable RTL.


module counter #(
  parameter WIDTH = 8
)(
  // system signals
  input  wire             clk,
  input  wire             rst,
  // counter signas
  input  wire             cen,  // counter enable
  input  wire             wen,  // write enable
  input  wire [WIDTH-1:0] dat,  // input data
  output reg  [WIDTH-1:0] o_p,  // output value (posedge counter)
  output reg  [WIDTH-1:0] o_n   // output value (negedge counter)
);


always @ (posedge clk, posedge rst)
if (rst) o_p <= {WIDTH{1'b0}};
else     o_p <= wen ? dat : o_p + {{WIDTH-1{1'b0}}, cen};


always @ (negedge clk, posedge rst)
if (rst) o_n <= {WIDTH{1'b0}};
else     o_n <= wen ? dat : o_n + {{WIDTH-1{1'b0}}, cen};


endmodule


Than write a C++ testbench. C++ is used for the bench since non synthesizable Verilog features would be needed to write a proper Verilog bench. Anoter option would be to use SystemC, but due to licensing issues it is very difficult to get a package for Linux distributions. The bench will toggle the clock and provide input values.


#include "Vcounter.h"
#include "verilated.h"
#include "verilated_vcd_c.h"


int main(int argc, char **argv, char **env) {
  int i;
  int clk;
  Verilated::commandArgs(argc, argv);
  // init top verilog instance
  Vcounter* top = new Vcounter;
  // init trace dump
  Verilated::traceEverOn(true);
  VerilatedVcdC* tfp = new VerilatedVcdC;
  top->trace (tfp, 99);
  tfp->open ("counter.vcd");
  // initialize simulation inputs
  top->clk = 1;
  top->rst = 1;
  top->cen = 0;
  top->wen = 0;
  top->dat = 0x55;
  // run simulation for 100 clock periods
  for (i=0; i<20; i++) {
    top->rst = (i < 2);
    // dump variables into VCD file and toggle clock
    for (clk=0; clk<2; clk++) {
      tfp->dump (2*i+clk);
      top->clk = !top->clk;
      top->eval ();
    }
    top->cen = (i > 5);
    top->wen = (i == 10);
    if (Verilated::gotFinish())  exit(0);
  }
  tfp->close();
  exit(0);
}


Now run the next script or copy-paste line by line into the command line.


#!/bin/sh


# cleanup
rm -rf obj_dir
rm -f  counter.vcd


# run Verilator to translate Verilog into C++, include C++ testbench
verilator -Wall --cc --trace counter.v --exe counter_tb.cpp
# build C++ project
make -j -C obj_dir/ -f Vcounter.mk Vcounter
# run executable simulation
obj_dir/Vcounter


# view waveforms
gtkwave counter.vcd counter.sav &


The script will automatically launch GTKWave and open the waveform.







Release for sockit_owm

1-wire (onewire) master written in Verilog HDL sockit_owm has been released.

The source code is available here:

RTL features:
  • small RTL, should fit into a CPLD
  • Avalon MM bus, Wishbone compatible with a simple adapter
  • timed reset, presence, write/read bit transfers
  • overdrive
  • power supply (strong pull-up)

Altera SOPC Builder integration

Altera Nios II EDS integration:
  • port of the 1-wire open domain kit version 3.10b
  • interrup driven or polling driver
  • uCOS-II support (only partially tested)

Detailed documentation is provided inside the package. Please read it, it covers almost anything, that can be said about the project.

The module was developed using open source tools (Icarus Verilog, GTKWave) but it was tested on the Terasic DE1 board (a demo for the board is included in the package).

13 August, 2010

How to convert an USB to RS232 adapter into an USB to 1-wire adapter

What hardware do you need:
  1. USB to RS232 cable with a case that can be opened (for example the USB-SERIAL-4 from ST-LAB)
  2. UART to 1-wire converter DS2480B from Maxim (samples are available)
  3. some wires, soldering station, external connector, ...
  4. some 1-wire or iButton slaves
The USB to RS232 cable is usually composed of a USB to UART chip and an 5V to RS232 level converter. With the cable I used the UART was PL2303 or the newer PL-2303HX (datasheet), depending on the cable version. The RS232 chip was SP213EH or ZT213AE, depending on the cable version, but the chips have compatible pinouts, probably also compatible with MAX232 chips.

I was able to get the cable schematic on a Chinese forum or cellphoneconnector.com, other cables are probably similar.



The next steps have to be performed to properly connect DS2480B to the UART chip:
  1. if you prefer not to remove the RS232 level converter, at least its outputs have to be disables, this can be done by lifting EN (pin 24) on the SP213 chip an connect it to GND instead of VDD
  2. glue DS2480B somewhere on the board
  3. connect GND, VDD (pins 1, 4) to power supply (I used the unmounted EEPROM pads)
  4. connect 1-W (pin 2) 1-wire signal and power to the external connector
  5. connect POL (pin 6) polarity signal and VPP (pin 5) programming voltage to VDD
  6. connect the UART TXD output (pin 1 on PL2303) to DS2480B TXD input (pin 7)
  7. connect the UART RXD input (pin 5 on PL2303) to DS2480B RXD input (pin 8)
Optionally you can also connect I2C SCL and SDA (accessible on pads reserved for the EEPROM) to the external connector. I did not test I2C, but there are some online instructions on how to use it.

Regarding the software, I used OWFS. I had to compile it since there are no Ubuntu/Debian packages available. I might add some details in a later post.

06 November, 2005

Science Technology Philosophy Aesthetics

I have to study so I as usually do everything else. This time I created my first blog.

I am going to write about science:
- artificial life
- evolution vs. inteligent design
technology:
- open source software
philosophy and aesthetics...

IzI