Monday, December 10, 2007

RTL Visualiser

I'm in the midst of writing a Visualiser for Verilog RTL. It'll take in a Verilog description of a circuit design and produce the corresponding schematics. I hope it will be a joy to use, and produce 'nice' schematics.

Automatic Schematics

I've found that producing nice automatic schematics is difficult.

As for the App: so far, I have a very basic GUI running. It reads in and parses very basic verilog, builds the hierarchy tree and displays very basic schematics of very basic RTL, with very basic ratsnest type flightlines representing the block-to-block connections. It's all very basic. I've a nice recursive algorithm to place module instantiations in the x-axis, but y-axis placement is a whole other ball game. Y-Placement is not very basic. (At least as far as I can tell).

I've been fighting with the Y-Placement problem on-and-off for over 4 months, with no successful outcome. I want to see what I'm capable from a programming design point-of-view, so I have not yet consulted the interweb on how to solve it.

Genetic Algorithms

Another interest of mine is in Genetic Algorithms, so I threw one at it, to see if it could get some nice y-axis values to stick. The GA was s.l.o.w. (about a minute to place ~13 blocks - this is far from 'joy to use' territory), although there is room for some tuning to speed things up. And even though it successfully minimized net crossovers, it did not minimise them all. Also, things that should've been connected with a straight line weren't.

This led me to think about Genetic Algorithms and when it's a good idea to use them. But I never came to any conclusions, except to say that its probably a bad idea for this app. It's a bad idea for a few reasons.

First of all, there's the speed issue. I'm not convinced that even if I farmed the GA out to a 'C' routine, that I'd get through enough genotypes and generations in a GUI-friendly timeframe to get a nice schematic. And since the length of the genome depends directly on the number of things I have to find a y-axis number for, the GA slows down exponentially as this size increases. With the added complication of having to find heuristics to determine what population size and how many generations to run the GA for per genome size, it all just gets too much to deal with.

Another issue with running a GA here is that there's no guarantee that you'll always hit a genome with 'maximum' fitness (ie no crossovers if there needn't be, etc). And due to the nature of the algorithm, you can't get consistent schematics for the same RTL for each GA run if you can't consistently hit the fitness maxima.

The fitness functions used for the GA seems to take up the most programming time. And, how in hell do you write a fitness function for 'nice schematics'? To produce nice schematics, I think it's necessary to minimize net crossovers and ensure that modules are not drawn over the top of each other. It also seems to be important to minimize the gradient (sum of the gradients) of the connections. I have included these measures in the fitness function, and have even tried tweaking the weighting given to each, but all to not much avail.

So?

So I've gone back to basics, and am going to try to draw simple 2 & 3 gate circuits to see if I can get a handle on automatic schematics. Wish me luck...

Monday, August 27, 2007

BEDROOMNET: Subversion & Samba

As I mentioned on a previous post, one of the projects I have on the go is an RTL Visualiser. As I want this to be cross-platform, I suppose I had better test it on a few platforms. To this end, I set up a small local network where my mintLinux desktop could talk to my XP laptop. The idea was to host a Subversion repository on the desktop, where I'd be doing most of the development, and use a mix of Samba, Subversion and TortoiseSVN to get the XP laptop to access the repo.

Samba

Out of the box (and with a crossover cable) the desktop could read shared folders on the laptop, but the laptop couldn't see the desktop. So after installing Samba, running the Network Setup Wizard on the laptop and sharing a few folders on both machines, things were running well. I think I disabled the password stuff on Samba because I still haven't figured out how to add accounts - I don't need them anyway for this network. I'll poke about on it a bit more once I fork out for an internet connection.

Subversion

Getting this running was fairly easy too. First I installed Subversion on the desktop and set up a repository on an ext3 partition. Then I installed TortoiseSVN on the laptop - a SVN client program which hooks into Windows explorer and gives extra SVN command options when you right-click on a folder or file. After this, I easily checked out the SVN repo on the laptop and ran my RTL Visualiser (Version 0.1!) successfully on the laptop!

I couldn't check any changes in though. But after adding a user and a password to the repo's passwd file and enabling password authentication, I was soon checking stuff into the desktop repo from the laptop.

At the end of the day...

All in all I'm fairly happy with this setup, and it wasn't too difficult to set up after doing a bit of digging around in the Subversion docs.

Tuesday, August 21, 2007

LinuxMint

Distros and Me

As mentioned in my last post, I had a rotten time trying to find a linux distro that suited me straight out of the box. I suppose this is a big ask, but the reasoning behind it is that I know I'm going to want to try out tons of distros, but I don't want to have to go thru the hassle of configuring it to suite each time. I suppose I'm going to have to settle on one distro for "everyday use" and leave the other ext3 partition on my harddrive for my new distro fixes. I've settled on LinuxMint (MintLinux??) 'cos I like the codec support and the themes and I like the fact that it can use the Ubuntu repos.

NVIDIA Drivers

I hate freedom, and I want my NVIDIA drivers. My Linux box remains unconnected to the net, which makes it a pain to install the NVIDIA drivers on LinuxMint. Luckily, I stumbled across an easy fix for installing NVIDIA drivers. It requires a Ubuntu Fiesty CD (which matches LinuxMint Cassandra), which I got with a linux magazine...

* Fire up Synaptic and disable all the repositories pointing to the web.
* Select 'Add a CDROM' and insert the Ubuntu CD when prompted.
* Close Synaptic.
* Open Restricted Driver Manager.
* Enable NVIDIA Drivers, which now it grabs from the CD drive.
* (Reboot? - I can't remember exactly)

OpenOffice

I've spotted a few funnies with the locale settings when using OpenOffice. I selected Dublin, Ireland as my timezone (locale?) when installing LinuxMint. I'm also assuming that the language packs that are installed depend on the locale in some logical way. But unfortunately I had to manually install the help files and the dictionaries for OpenOffice. It looks like the installer was looking for 'English (Ireland)' for example and could not find it, but it did not revert to 'English (UK)' or 'English (US)' and instead installed nothing. I suppose what I'm getting at is that it'd be nice if there was some kind of graceful fallback for OpenOffice Help and Dictionary files.

Tuesday, July 17, 2007

Linux: Codecs, Proprietary Drivers & Hassle

I'm currently playing around with linux distros trying to find one that suites me. I've a collection of coverdisks from linux mags, and I'm to-ing and fro-ing, installing the various flavours on my new computer. But I'm finding it *very* frustrating.

Vista

First of all, the box came with Vista pre-installed. And whatever else can be said about micros~1 - Vista looks great! But I like my command line, so I reduced the Vista partition; created a few new ones and installed Ubuntu 7.04.

Ubuntu vs Media

My first impressions was that Ubuntu looks fairly ugly - or maybe 'old' is a better word - compared to Vista. Ubuntu catches up with the 3D desktop effects, and after installing NVIDIA's proprietary drivers from the "Restricted Drivers" tool, everything was running smoothly.

That was until I tried to play MP3's and the video tutorials from the guitar mag coverdisks I've lying around. Unsucessfully - although in fairness Vista doesn't play MPEG4's or MOVs out of the box either. I've no internet connection at home, so I can't use the automatic download tools to fetch the codecs. Hunting around on the net gave me no clues on what packages to download - and even if I fire up Synaptic and ask it to write a download script I've still no idea what to ask it to download.

LinuxMint vs Drivers

Then I heard of LinuxMint with it's bundled codecs. So I ordered it from On-Disk and was pleased to see it arrive after only 4 days or so. I much prefer the colour scheme, but again, things like the (IMHO) very poor icons make it look a bit rusty. The mintMenu is fairly cool and friendlier that Ubuntu's two-panel approach. But LinuxMint doesn't come with the *&^%£€<¹!¡ NVIDIA drivers!!


I'm going to have to stop being such a tight-arse and get my home computer wired up to the web. Or wait until NVIDIA open-source their drivers...

Friday, June 1, 2007

Getting SQLite Working

Steps I needed to go through to be able to use SQLite in my python programs. This was on my linux box, I haven't tried it on my micros~1 laptop...
  1. Download python2.5 and compile. This has the sqlite3 module built in - but it's only a wrapper!
  2. Download and compile sqlite3. Initial trials bombed out when looking for 'tcl.h'. I don't need TCL bindings, so a quick look on the sqlite wiki says to 'configure --disable-tcl'. This seemed to do the trick.
  3. As Python only includes the wrapper for sqlite, I needed to run the setup.py script again so that Python knows where to find the sqlite executable. I needed to hack the setup.py because I'm not installing sqlite in the usual place.
    To do this, I searched setup.py for sqlite3 and added the sqlite build directory path to sqlite_inc_paths - it'll pick up sqlite3.h here. Then, I added os.path.join(sqlite_incdir, '.libs') to the sqlite_dirs_to_check list - my libraries were linked into bld/.libs
  4. Running Python again and doing a 'import sqlite3' is quiet - which means no errors! Job done.

Wednesday, May 30, 2007

Projects

I've a few projects I'd like to do:

  • USB Audio Interface
    • for hooking up my guitar to my computer
    • using those fancy PICs
  • A darts scoring system
    • Just to use those *HUGE* LEDs
    • Would suite my mates' "Bar and Darts" room.


Projects in the works

  • RTL visualiser
    • Python and wxWidgets
    • inspired by Nova's Debussy

Projects I've recently completed:

  • Multi-Zone Lighting Controller for a friend's new gaff.
    • PICs, keypads and high-voltages!

My Code vs the PIC16F871 Linker Script

Just wasted a day trying to port some PIC code over from a PIC16F684 to a 16F871. It was all down to the linker script, and my hazy understanding of where the linker tries to place data. First a few basic facts about the directives for specifying relocatable memory blocks:

  • UDATA: Uninitialised data which is placed in sections defined as "DATABANK" in the linker scripts. These sections are 'banked' memory locations, so you have to be careful to select the correct bank before accessing the data at these memory locations.

  • UDATA_SHR: Uninitialised shared data which is placed in sections defined as "SHAREBANK" in the linker scripts. These sections are 'unbanked', which means you don't need to care too much which bank you've selected when using these data locations. The data accessed at this location is the same across all banks.

The All-Important Linker Script

My assembler code is split across a few files, with some of the files defining a few variables in UDATA blocks. This was all cool when I was targeting the code to the 18F684, but when I targeted it to the 16F871, I got the error message:

Error - section '.udata' can not fit the section.  Section '.udata' length=0x00000012

After some vigorous interweb searching, I finally hit on the answer - the 16F871 linker script doesn't define any DATABANK sections! The linker had nowhere to put my UDATA.

The Fix

Instead of hacking the linker file, which I was tempted to do, I changed all my UDATA blocks to UDATA_SHR. One of my files had UDATA and UDATA_SHR blocks, so I had to edit this 'cos you're only allowed one block of each type per file.

Now it links like a dream! Needless to say, there are now copious comments in the code...

References: