Published on: May 26, 2011
Track every Watt(TEW) is one of the new Open Hardware based project which I am working on for the past few weeks. Track Every Watt is a pluggable device which can be used to measure power consumed by an electrical appliance. The device to be measured is connected to the TEW which has an LCD display which shows power consumed and also some additional information. TEW was inspired from Kill A Watt which is a device that can only measure devices with voltage rating 110V. TEW has a voltage rating of 230V and this is the reason why I started this project.
Track Every Watt can display additional information such as Voltage(V), Current(A), Watts(W), Volt-Amp(VA), Frequency(Hz), Power Factor(PF), Kilo Watt Hour(KWH), Time Elapsed. It uses an Analog Devices Energing Metering IC ADE7763. There is also an application note AN-564 for this IC.
Published on: March 12, 2011
Two years before I had designed a mini development board for AT90USB162. There was a small mistake in that board. It didn’t have the 1MFD capacitor connected across the UCAP (PIN 27) and ground. Because of that the board was not detected while connected via USB. Last month I thought of repairing that board and do some USB projects. I ordered samples of ATMEGA32U2 from ATMEL. Thanks ATMEL for the samples.
Today I did a small hacking on the board. I added the capacitor as needed by USB. Now the board is working fine. There came the next problem. GCC-AVR version which I had, didn’t support ATMEGA32U2. Also for loading the hex into the controller, I used the dfu-programmer. Since I had installed it from the Ubuntu repository, dfu-programmer was of older version and it also didn’t support ATMEGA32U2.
After a few Google search, I found that if you compile for AT90USB162, the hex generated is supported by ATMEGA32U2. So I wrote the C code and compiled it for AT90USB162. Next task was to make the dfu-programmer to work. The only solution was to get the latest code and compile it. Below shown is the way to compile the dfu-programmer from source
$ mkdir dfu-programmer<br />
$ svn co https://dfu-programmer.svn.sourceforge.net/svnroot/dfu-programmer/trunk/ dfu-programmer<br />
$ cd dfu-programmer/dfu-programmer<br />
$ ./bootstrap.sh<br />
$ ./configure<br />
Once installed, flashing the controller is very easy. First we have to bring the controller into USB bootloader mode. For that first press and hold the RESET button. Then press and hold the HWB button. Now release the RESET button and then release the HWB button. This will bring the controller into USB bootloader mode. Now we can issue the following instructions to flash the controller.
$ dfu-programmer atmega32u2 erase<br />
$ dfu-programmer atmega32u2 flash blink.hex<br />
$ dfu-programmer atmega32u2 reset
This is an Open Hardware project and I will soon post the schematic and PCB layout once adding the missing capacitor in the old design. Below shown is the snap shot of the board.
Published on: February 13, 2011
Please don’t forget to read this post before coming here.
For the newly developed Phoenix-MDK, I suggested few hardware modifications. Among them was the hardware modification for resetting the Phoenix-MDK through software i.e the user doesn’t have to press the reset button on the board to load a new program. I copied the design of software resetting from Arduino project.
The plan was to reset the controller using two pins i.e there was a pin (RTS) coming from the FTDI chip connected via a 100Kohm resistor to the reset pin of the ATMega32 and also a pin (DTR) from FTDI chip connected via a 100Kohm resistor to the PD2 pin of ATMega32. The two 100Kohm resistor was for current limit. So when the user wants to flash a software, he has to hold the PD2 down (because bootloader will wait for code from serial port only if this pin is low), send LOW pulse on RESET. Then Avrdude loads the code, take PD2 high and then send a Reset pulse again.
When I checked the Arduino design, they were only using the RESET pin to load the software using Avrdude. Arduino bootloader loaded the code in the following manner – Send a reset pulse. The bootloader will wait for the software from serial port . If the data is coming, then they will write the flash memory using that data or else they will jump to the main code. The greatest advantage over here was of using only one pin (DTR) of the FTDI chip to load the software.
I adapted the same design to the Phoenix-MDK. Now The other pin (RTS) need not be used i.e the DTR pin of FTDI chip was connected to the RESET pin of ATMega32 via 100nF capacitor. So we saved one pin (PD2) of ATMega32 which is not used in the new design.
The below python code can flash code to Phoenix-MDK (written by Pramode).
import serial, time<br />
import os, sys<br />
fd = serial.Serial(port='/dev/ttyUSB0', baudrate=19200)<br />
print fd<br />
cmd = 'avrdude -b 19200 -P /dev/ttyUSB0 -pm32 -c stk500v1 -U ' + sys.argv<br />
1) Save the above code as load.py
2) Write the code which you want to run on ATMega32 and Compile the code using avr-gcc.
avr-gcc -mmcu=atmega32 -Os filename.c__
3) Convert a.out to hex file
avr-objcopy -j .text -j .data -O ihex a.out a.hex
4) Load the hex to Phoenix-MDK
python load.py a.hex
Update: I will soon upload the pics of newly developed Phoenix-MDK .
Published on: February 13, 2011
Today I got a chance to do some hacks on Phoenix-MDK. There was a need of a bootloader for this board. Along with that, we should be able to program the board without hitting any reset switch. The first thing which came into my mind was the arduino boards. They had all the above mentioned features. So I started understanding how the arduino board works, which boot loader is used inside, how reset can be triggered through software etc.
The bootloader used in arduino’s are the optiboot which has a very small footprint (around 512kb) and it was using the serial protocol STK500 for its communication. So I took the optiboot and made some modifications. But it failed. I don’t know where I went wrong and also I bricked one ATMega32 chip.
I had one more ATMega32 chip with me. But this time I was really careful not to brick again a chip. It was really hard to find a bootloader. After a long search I found this page which really helped me a lot – http://wiki.edwindertien.nl/doku.php?id=software:bootloaders
The bootloader can be obtained from http://wiki.edwindertien.nl/lib/exe/fetch.php?media=software:atmegaboot-32.zip. Phoenix-MDK uses 8MHz crystal. So I had to modify a line in the makefile which contains the clock frequency to AVR_FREQ = 8000000L . Thats all. I gave a make and got the hex file.
Below are the steps for flashing the bootloader and using it.
1) Flashing the bootloader using parallel programmer
flashing the hex:
avrdude -c dapa -patmega32 -U flash:w:ATmegaBOOT_168_atmega32.hex
flashing the fuse:
avrdude -c dapa -patmega32 -U lfuse:w:0xff:m -U hfuse:w:0xda:m
2) Testing the bootloader
avrdude -b 19200 -P /dev/ttyUSB0 -pm32 -c stk500v1 -n
This should give a proper response.
3)Uploading a hex file using the serial bootloader
avrdude -b 19200 -P /dev/ttyUSB0 -pm32 -c stk500v1 -U flash:w:a.hex
For the above code to work on Phoenix-MDK, I also had to do some hardware hack. Now the DTR pin is connected to the reset pin so that reset can be done by software. I have to find a software way to reset the chip.
Published on: November 21, 2010
This is my LPC2148 (ARM 7) test bench setup.
The LPC2148 header board was bought from Rhydo Labz. You cannot directly power up and start to use. It lacks communication interface. To flash the controller, you need a serial port or a JTAG port. Since this board doesn’t have these port connectors, you need to solder them. So it might be hard for a newbie.
Instead of this board, you can try the BlueBoard which has all the port connectors. I will recommend this for a newbie. I hope that board is worth for its price.
The next thing which you need is a power supply to power the board. You can build your own power supply (If someone needs to know how to build a power supply, I will write a tutorial. But please put a comment in this post saying that you need the tutorial.) ,or you can buy 5V DC power supply (adapters).
Once the board is powered up, it can start to execute your code in its memory. But a fresh controller wont be having any code in its memory to execute. You need a programmer to load the code into its memory. But the LPC series controllers have built-in serial boot-loaders. These boot-loaders can get the code from the serial port and write into its flash memory. So you don’t need a programmer.
To program the controller using the serial boot-loader, you just need to connect the controller to the host PC and the host PC needs to run a serial programmer software. You can get a lot of serial programmer software for LPC controllers. Some of them are
So thats all. Power up the board and connect the serial port to the controller. Run the serial programmer software in the PC. You controller will execute the code flashed into its memory.
But wait. From where you can get the hex file to flash into its memory? Its simple. You just need a cross-compiler. To the cross-compiler, you just need to feed your C source file. It will compile and give you *.out files, which later can be converted into *.hex files.
I will soon try to post a wiki page about how to compile and flash the code into the memory.