Monday, January 30, 2012

Sign extension in VHDL

Okay, I am using VHDL at my new job, and haven't used it in years.  I was trying to sign extend basic logic circuits and it was driving me crazy.  Finally I found this, and it seems like it works:

Input signal to sign extend was
 
wimax_out       :in  std_logic_vector(15 downto 0); -- output of wimax modulator



in the architecture area...


-- sign extent input to 18-bits
wimax_sign_ext_18                             <= wimax_out(15) & wimax_out(15) & wimax_out;

-- sign extend to 48-bit C input
wimax_sign_ext_48(47 downto 16)     <= (others => wimax_out(15));
wimax_sign_ext_48(15 downto 0)       <= wimax_out;


So concating works (&) and the others => work, at least according to modelsim and the 'signed decimal' signals.  I am willing to bet other methods work, or perhaps work more properly, but I do not care

Verilog all the way




Thursday, January 12, 2012

FPGA Timing

All right, I keep forgetting how FPGA timing works, so I'm writing it down here so I don't have to continue to search the internet

There are four main time periods we care about dealing with FPGA timing: Tclk, Tsu, Th, and Tco.


  • Tclk is the period of the clock the registers in question are synchronous to.
  • Tsu (Setup time) is the amount of time before the edge trigger of a register that the data must be settled on the input of the register
  • Th (Hold time) is the amount of time after the edge trigger of a register that the data must remain stable on the input of the register
  • Tco (Clock to output time)  is the amount of time from the edge trigger of the register to when the newly latched data is available as an output.

FPGA Timing Diagram Example

Here is an attached picture of three registers on the same clock, with the above time periods
From this we can see the amount of time a signal has to get from one register to another register in an FPGA is defined as
Time Skew = (Tclk - Tco - Tsu)

Skew is eaten into by delay that is a function of the speed of light, the trace material dielectric, the width of the trace, and probably something else I am forgetting.

These rules hold true in SDR or DDR -- we just care about the data with respect to the appropriate edge.  It can get more complicated with Center Aligned data or Edge Aligned, or dealing with external interfaces to the FPGA, but the main rule applies:

Data has to be there a certain amount of time before and after the sampling edge (Tsu and Th), and will take a certain amount of time before being available as an output (Tco), and is constrained by the clock period (Tclk) and the laws of physics.

Friday, October 21, 2011

Truecrypt and Debian

Future self - the Truecrypt installer will complain about (gksudo:21149): GLiB-CRITICAL **: g_str_has_prefix: assertion 'str != NULL' failed
Press Enter to exit...

If you try and install it via the downloaded installer.  What you should do is run the installer, and select 'Extract'.

Truecrypt Installation


It will dump a tar.gz into /tmp.

Extract that, and a folder called 'usr' will appear.  Copy that folder where-ever you want.  Inside BIN will be the truecrypt files.

You may need to play with permissions.

Sunday, October 16, 2011

Samba, Debian, and Windows 7

I have a headless linux computer I use mainly as a file server, but also as a bit of an open source science toy.  I can start a ssh / VNC to it from anywhere in the house.  Until recently, it was running Ubuntu 11.04.  I attempted an upgrade to 11.10, but something went wrong and it left the system in a less than optimal state.

That's all right though, I was looking for an excuse to simplify it to straight Debian.   The Debian install went well, though I noticed I took for granted many of the packages that came installed by default in Ubuntu. (make anyone?)  A few apt-gets fixed all of that, though, and I was left with the last headache I remembered:  properly configuring samba to work with my Windows 7 computer.

"This shouldn't be hard", I thought remotely.

The best walkthrough I found was on http://www.unixmen.com/linux-tutorials/1524-standalone-samba-in-debian-squeeze - I simplified it a bit, since I'm okay with home users having access to their own directories.

My path went something like this:


  1.  Make my Windows 7 workgroup name WORKGROUP by clicking start, right clicking "Computer", and hitting "properties" 
  2. Install samba on the Debian computer with 'sudo apt-get install libcupsys2 samba samba-common'
  3. I don't care about domain name for my simple setup, and I make sure my default workgroup is titled WORKGROUP during setup
  4. After completion, sudo edit /etc/samba/smb.conf and uncomment the line 'security=user'
  5. Under the [homes] section, add "valid users = my_username"
  6. change the "read_only" from YES to NO to enable writing
  7. save, quit, and restart samba with a sudo /etc/init.d/samba restart
  8. FINALLY, remember that samba doesn't have access to your Linux login....so you must set the samba password for your username separately via 'sudo smbpasswd -a username'
At this point, you should be able to access the linux home directory, from windows, by typing in the network IP address into the path of a window...such as
\\192.168.1.9 and login with your user name and samba password

Tada




Saturday, August 27, 2011

Another Note to Self

In Android, to get things to center properly, use the android:gravity tag in the Layout surrounding it....


<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center">
 
<Button   android:text="Add"
          android:id="@+id/button_dialog_set"
          android:textStyle="bold"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          >
</Button>
<Button   android:text="Cancel"
          android:id="@+id/button_dialog_cancel"
          android:textStyle="bold"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          >
</Button>
</LinearLayout>


Produces two buttons, centered, next to each other

Tuesday, August 23, 2011

GNU Octave plots

Because I can't afford Matlab, I have been experimenting with GNU Octave on my Linux computer.  It is very expandable via free packages, and seems more command line based.

Anyway, this entire post is to remind myself that you can capture plots via the 'print command' and the following syntax:

print -djpg filename.jpg ....it took a while to understand the help print command, and that you are specifying the 'device' via the print -dFILETYPE_OR_DEVICE syntax

In conclusion, here are some plots of the LMS algorithm converging on a static, unknown system:

Elements Converging

Error Converging

Thursday, August 18, 2011

Garden Success and Failure


Delicious, if small, carrots

Because in my mind, I'm preparing for the apocalypse, I started a garden.  It was a mildly successful mixture of the following:

  • peppers
  • onions
  • carrots
  • pumpkins
  • zucchini
  • lettuce
  • spinach
  • herbs
  • tomatoes

Spot the grasshopper

In review, there are some lessons learned:




1: Pumpkins and Squash have flowers that bloom for maybe 1.5 hours a day, and if they aren't pollinated, they die

2: BUGS oh the bugs.  Everyone is out to eat my vegetables.  Constant vigilance is required, inspecting all leaves for eggs or other abnormal signs

3: Spacing is important....one garden is full of tomato plants, zucchini, and some wildflowers.  A little too much, with no room to grow

4: Carrots grow to be as big as they can go deep.  I guess this made sense in retrospect.



Oh well, there is always fall crop