CURRENT ISSUE

Contests

bottom corner

Feature Article



Issue #213 April 2008

Programmable Power
Build a Simple USB DAC
by Yoshiyasu Takefuji

Start | USB Communications | Firmware | MAX517 (DAC) Programming | Firmware, Software, & LIBUSB | Host Device Driver Installation | Testing | Sources & PDF

FIRMWARE

The avrusb protocol stack is embedded in the firmware of the USB device. It provides you with user-friendly APIs including the usbFunctionSetup function. The usbFunctionSetup function is used to send/receive data via USB between the host PC and the USB device (ATtiny45). The data mapping is detailed in Figure 2. Because usbFunctionRead and usbFunctionWrite are not used in this article, those functions are described at www.obdev.at/products/avrusb/index.html.

Photo 1
Figure 2 —This is parameter mapping between a host computer and a USB device using an ATtiny45 and a MAX517.

In AVR-USB, usbconfig.h plays a key role in firmware configuration. The USB configuration port is defined in Listing 1. usbconfig.h device descriptions are defined in Listing 2.

Two-byte data from the host is sent to the target USB device using usbFunctionSetup to initialize the MAX517 (two-wire, 8-bit DAC) and set the voltage of the D/A output. The first data byte sets the mode. The second data byte sets the voltage of the D/A output. A pulse stream from the ATtiny45 is sent to the MAX517 to program a DAC. WinAVR is used for compiling the described source program. PB1 and PB5 (reset) are used for the MAX517 two-wire programming setting. Once the reset pin is set up by writing the lfuse and hfuse, the conventional serial programmer can no longer write the ATtiny45’s flash memory because the reset function is disabled. To reactivate the ATtiny45’s reset pin for further programming, high-voltage serial programming must be used.

To compile the source program, type “make” in a Cygwin window or execute “Make All” on the programmer’s notepad in WinAVR. After a successful make operation, a da.hex file should be generated. A da.hex file is used to write the ATtiny45’s flash memory with the program writer. Modify WRITER=xxx in a makefile according to your own program writer. In a Cygwin window, type “make fuse” and “make hfuse” to update the fuse bytes (see Listing 3).

Previous | Next

 


bottom corner