Tuesday, March 24, 2009

Simple TWI / I2C communication with AVR ATMega8 and TC1321 DAC

I wanted to set up and test the D/A-converter TC1321 with a AVR, but had no previous knowledge of TWI. These are my experiences:

To make things easier I used a AVR with built in TWI function. I got a little confused on this subject when I read on AVR Freaks that for example the ATTiny26 had TWI function. Actually the microprosessors with a lowercase "y" in the comparison chart has USI which can be used for TWI. The uppercase "Y" for TWI indicates that the uC has built in TWI functionality. With such uCs you can include the to get some free predefined twi-codes.

To connect to a TWI device you need to connect the SCL and SDA lines to the uC. For ATMega8 it is PC4 (SDA) and PC5 (SCL). You then need to connect each of these via a pullup resistor to the source voltage (5V). For this connection I used two 220 ohm resistors.



So to sum up: I found it easier than I thought to interface the TC1321. Reading through descriptions that others have made describing both reading and writing to a slave (EEPROM etc) was not necessary when the only thing I wanted was to send data.

I found it easier than I had thought to communicate with the TC1321. First you need to set up the SCL-clock rate. You can calculate the TWBR with this formula:
TWBR=(fCPU/fSCL-16)/(2*4^TWPS)

So if you run your uC at fCPU=8MHz and you want fSCL=100kHz and try to use a prescaler TWPS=0 you get TWBR=(8e6/100e3-16)/(2*4^0)=32. So you start by setting:

TWPS=0;
TWBR=32;
To send data to the TC1321 you can use two protocols: 1-byte format (8-bits) and 2-byte format (10-bits). The progress of sending data is made in a sequence like this:

1-byte format:
START
SLA+W
COMMAND
DATA
STOP

2-byte format:
START
SLA+W
COMMAND
DATA
DATA
STOP

In between every sending you check the status codes by looking at TW_STATUS. The SLA+W is actually only the slave adress, 0x90.

Here are some functions that can be used to send data to the TC1321:


So to sum up: I found it easier than I thought to interface the TC1321. Reading through descriptions that others have made describing both reading and writing to a slave (EEPROM etc) was not necessary when the only thing I wanted was to send data.

Sunday, March 01, 2009

Mini review of "The 4-hour work week" by Timothy Ferris




I came across this book as I was looking for material before having a inspirational lecture about mathematics to new high school students. I ended up having a lecture of why you should embrace learning different things and the importance of knowing a little about most things in life. This is actually what Timothy Ferris was looking for when he decided to break out of his 9-5 traditional work as an employer ("slave" in his words) and start managing his own future. He wanted to work less, earn more and spend the extra time and money he had for traveling and enjoying life while he still was young and able to live it.

The book is a blue print on how to [D]efine your goals in life ("dreamlines"), [E]liminate time wasting and start focusing on realizing those goals (by using Pareto's principle and Parkinson's law), [A]utomate your business (by using outsourcing and the wonders of computers) and [L]iberating yourself from current work and the life you are living.

I really liked the book: It gave me a kick in the butt to start focusing on progressing towards my most important goals. Even though the internet business modell is perfect for people having a big home market, many of the tips are quite transferrable to everyone wanting to start up something new.

I am not dreaming about traveling the world throughout my life anymore, but I still would prefer having more time for hobbies and family. I think this book gave me gigant leaps towards achieving this.

Thursday, February 26, 2009

Flux welder (FCAW) converted to MIG (GMAW)

I got a nice welder from my wife Sunniva this christmas that was flux core only. After reading a bit about welding I decided to check if it was possible to convert my welder to MIG with gas shielding (Argon or Argon/CO2). This is attractive since you could make much nicer welds, poisonous fumes are minimized and you should in theory be able to weld both stainless steel and aluminium.

After opening up the torch I found that it contained a gas valve that had a threaded hole. I bought a small bottle gas kit for a different welder, made threads on the straight part of the quick coupling and bought a longer nylon tube for the quick coupling with the same diameter. Now I am able to do both flux core and gas shielded welding.

Wednesday, February 25, 2009

Error with CDrom in xp (Code 32) finally fixed

As an action oriented man it is a little bit embarrassing to admit that I have had problems using my hp laptop cdrom drive for several years now. I have not done anything about it since I thought it was a hardware problem and data can nowadays allways be transferred in other ways (usb, wifi).

Yesterday I got surprised when I saw that I was able to boot from an ubuntu linux cd without problems. When I on top of that saw that no virtual cdrom drives (virtual clonedrive, magicdisc) were working either I was determined to fix what now was a windows problem.

I saw that all cdrom drives were registered as active in windows device manager, but all had an exclamation sign suggesting something was wrong. When looking in properties I got the following error:

(Norwegian)
En driver(tjeneste) for denne enheten er deaktivert. En alternativ driver kan gi samme funksjonalitet. (Kode 32)


(English)
A driver for this device was not required, and has been disabled (Code 32)The first suggestion was that I should include CTFMON.exe in the startup, but this did not change anything.


I finally found Microsoft's Q314060 showing me how to fix the problem:


Step 1: Start Registry Editor

Start Registry Editor.

Step 2: Delete the UpperFilters registry entry

  1. In Registry Editor, expand My Computer, and then expand HKEY_LOCAL_MACHINE.
  2. Expand SYSTEM, and then expand CurrentControlSet.
  3. Expand Control, and then expand Class.
  4. Under Class, click {4D36E965-E325-11CE-BFC1-08002BE10318}.
  5. In the details pane of Registry Editor, on the right side, click UpperFilters.

    Note You may also see an UpperFilters.bak registry entry. You do not have to remove that entry. Click UpperFilters only.
    • If you see the UpperFilters registry entry in the details pane of Registry Editor, go to step 6.
    • If you do not see the UpperFilters registry entry, you still might have to remove the LowerFilters registry entry. To do this, go to "Step 3: Delete the LowerFilters registry entry."
  6. On the Edit menu, click Delete.
  7. Click Yes when you receive the following message:
    Are you sure you want to delete this value?
The UpperFilters registry entry is removed.

Step 3: Delete the LowerFilters registry entry

  1. In the details pane of Registry Editor, on the right side, click LowerFilters.

    Note You might see a LowerFilters.bak registry entry. You do not have to remove that entry. Click LowerFilters only.

    If you do not see the LowerFilters registry entry, unfortunately this content is unable to help you any more. Go to the "Next Steps" section for information about how you can find more solutions or more help on the Microsoft Web site.
  2. On the Edit menu, click Delete.
  3. Click Yes when you receive the following message:
    Are you sure you want to delete this value?
    The LowerFilters registry entry is removed.
  4. Exit Registry Editor.

Step 4: Restart your computer


Thursday, February 19, 2009

Mini review of "The renaissance soul" by Margaret Lobenstine




I had this book on my wish list since I picked up the title when reading comments to the blog post "The Top 5 Reasons to Be a Jack of All Trades" from Tim Ferris' blog. I was happy when receiving this as a christmas gift and started reading it immediately. During my recent vacation to the Canaries I got the chance to finish the book. Here are my personal impressions of the book:

  • I was expecting to learn a practical time management system from the book. Time management is covered in 22 pages and is not very practical in my opinion. Margaret basicly says that you should put down up to four focal points, calculate how much time you have left for them and put them in your calendar. I don't like using the calendar when it's not necessary. I rather put up my most important tasks for a day and try to finish them. These are all prioritized according to my focal points. This makes you focused, but still flexible. I picked up this tip from "zen to done" from Zen habits.
  • The book is written more like a novel than a practical guide. It is full of stories of clients that Margaret succesfully helped out after coaching them.
  • The title is "The renaissance soul", but I didn't expect the author to use this phrase as much as she does. OK, so the test said that I am a renaissance soul - this does not make me some special, rare creature that should behave differently than any others. Most people need some kind of structural aid to be effective in their day to day work.
  • Even though I didn't like the book very much I found some metaphors quite good: A) When trying to find which focal points to pick then think of them as ice-cream that you can pick a four-flavor sampler from and change whenever you like. B) When faced with a situation involving change you are like a lobster breaking out of it's shell in order to grow: First the shell is a thin membrane without protection and you fear this before you leave your original cozy shell. You later realize that your new shell is bigger and harder and more protective than the old shell.

Friday, January 30, 2009

iPhone VPN connection to Vista is now working

Something strange happened the other day. I haven't used the iPhone VPN connection since the post was written because I had no use for it. Now I wanted to try it again. This time I got access to all the other ip adresses that were previously hidden for me. I tested this from work so I know I wasn't locally connected. Three things were changed since the last time I tried: The iPhone got new firmware (2.2.1), the wireless network administration was changed from RALink to Windows and Windows Vista probably got some new updates. That's really strange, but oh so cool!

Tuesday, January 20, 2009

Nondestructive cooling for Dreambox DM800 HD


I got sick and tired of the Dreambox DM800 HD locking up all the time and read several places that this was due to heating problems. This happens especially when you run HD channels.

The Dreambox DM800 HD does not contain a fan, so I decided to include one myself. I did not want to destroy anything or cut any wires so I started looking at different pins/connectors that I could connect a fan to. Two options were candidates: the header next to the Broadcom cpu (JTAG header?) and the power supply to the internal SATA harddrive that I have got. Neither were easy to find any good information as to what voltage they had or if they could source sufficient current. I decided to use the same trick that everyone else are using: Connect to the USB port.

I found an old 12V cpu fan that I salvaged from an old computer and stripped the wires. I had a spare USB male to USB female cable that I removed the shielding from, cut the red and black wires, stripped them and connected them to the wires for the fan. Now the fan was running ok. The wires for the fan now goes nicely through the hole where the eSATA connector earlier was connected.

The USB 2.0 standard gives a maximum current of 100mA. At 5V this would be 0.5W. My fan was supposed to draw 1.5W at 12V, but the DM800 has no problem running it. It even seemed to have no problem booting up the first time I connected the power plug.
Posted by Picasa