Design Idea
Microcontroller's DAC provides code analysis
Scope plus DAC gives insight into software code.
By Dave Bordui, Cypress Semiconductor, Heathrow, FL; Edited by Brad Thompson -- EDN, 4/14/2005
Finding out where your microcontroller's firmware spends most of its time can be a tedious task when you use a conventional in-circuit emulator and breakpoint techniques. Other such tasks include discovering why a state machine doesn't work as you intended and where your code goes during real-time operation or during an error condition. Classic debugging methods can also become cumbersome when you attempt to observe error states or debug a program-flow problem. Fortunately, a technique that takes advantage of a feature that many microcontrollers now include offers a simple debugging aid that allows designers to easily monitor these and other operations.
The technique uses the DAC in microcontrollers such as Cypress Microsystems's PSoC (programmable-system-on-chip) family (Figure 1). These devices provide a microcontroller core and an array of mixed-signal building blocks that includes true DACs that can deliver fixed dc levels. Other types of DACs that deliver pulse-width-modulated outputs are unsuitable for this application. To use this technique, you create firmware "state constants" that represent operating states of your design. If your code structure comprises a state machine or contains a large "switch/case" statement, then you have already defined these constants. Otherwise, you can easily add the constants as needed.
Once you define the constants, you enable a DAC and configure it to drive one of the microcontroller's unused analog output pins. Then, you write the state constant to the DAC whenever the firmware enters a particular location. If you use an 8-bit DAC, you can also monitor the value of any 8-bit variable. Next, you connect an oscilloscope's vertical input to the DAC's output pin and observe its output voltage, which the instrument displays as a characteristic waveform that represents the firmware's operation. If your oscilloscope includes measurement cursors, you can easily determine which portion of the firmware is executing simply by measuring the DAC's dc output voltage at a given time.
You can define state constants to highlight certain conditions. For example, by reserving all state constants' values greater than 127 for error states, you can set the oscilloscope's horizontal sweep generator to trigger at a level that indicates an error. As a precaution, make sure that the microcontroller's DAC operates within its allowable update-rate range.
Check out our Best of Design Ideas section!















