Embedded 8-bit microcontrollers have become ubiquitous today, especially in industrial, consumer, telecommunications, and automotive applications. Products that used to be based on simple mechanical (pulleys and levers) and electrical (switches and motors) designs now have microcontrollers at the heart of their operation. Chances are, if the product plugs into the wall or is battery operated, it has a microcontroller inside. Just take a look around the typical home or office. The inclusion of 8-bit embedded control doesn't only add competitive functionality. It usually improves electrical efficiency and reduces overall product cost, too.
These microcontroller unit-based products provide a new challenge: How does the embedded designer test the hardware and software of these designs? Since the key to debugging any electronic design is "seeing" the signals, engineers traditionally used the dual-channel oscilloscope as their workhorse instrument. While the dual-channel scope works fine for simpler electronic designs, it's not the best choice for the more complex microcontroller designs. Often, multiple analog and digital I/O signals must be monitored simultaneously.
Figure 1 shows a simplified block diagram of an embedded design based on an 8-bit microcontroller. There are three major blocks: the analog-to-digital converter (ADC), the microcontroller unit (MCU), and the digital-to-analog converter (DAC). Although shown as separate blocks in the figure, many of today's microcontrollers have converters embedded on the chip. Embedded systems usually monitor, or are driven by, some type of real-world analog-input phenomena such as sound, temperature, pressure, and so forth.
The MCU block is responsible for decision-making, timing, and generating a digital or analog response—or both. In an embedded system, analog signals tend to be much slower in frequency compared to the digital control signals in the microcontroller block.
One problem surfaces when testing microcontroller-based designs: How do you test and monitor the slow analog inputs and outputs, while monitoring the much faster digital control signals at the same time? For instance, how do you determine if the MCU's software generated the correct digital response based on the analog input? With a conventional dual-channel oscilloscope, it may be impossible to monitor both the analog and digital signals due to the extreme difference in timing required for each signal type. In addition, two channels can be very limiting. It's only possible to monitor one analog and one digital signal simultaneously, and logic triggering is usually not available on dual-channel oscilloscopes. Due to its slow speed, noise, or lack of definition, triggering on the analog signal may not be an option anyway.
Suppose the design engineer wants the scope to trigger when a sensor indicates that the temperature of an industrial furnace has dropped below 1500°C. To do this, the first step is to determine the level of the calibrated analog signal that corresponds to 1500°C. Compounding the triggering problem is the fact that the analog signal may be changing so slowly that a small amount of noise on the temperature sensor's output could trigger the scope prematurely.
A better solution may be to trigger on a particular digital response of the microcontroller corresponding to the 1500-degree temperature threshold. To overcome the temperature sensor noise problem, the microcontroller might have to be programmed to include hysteresis. However, triggering on a microcontroller output is not possible with a dual-channel scope. A four-channel scope is a better option for testing microcontroller-based designs because of the ability to monitor up to three digital I/O lines together with one analog input or output. In addition, many four-channel scopes are capable of establishing a trigger condition based on all four scope inputs. Unfortunately, even four channels aren't always enough to see what's going on in the system.
A Logic Analyzer?
Another measurement solution is a logic analyzer, maybe one with built-in scope capabilities. Most designers of 8-bit systems wouldn't consider this option for very long, though. The majority of 8-bit designs don't warrant the full digital-measurement power and complexity, not to mention the expense, of a full-blown logic analyzer. Logic analyzers usually have large numbers of acquisition channels (greater than 48), primarily intended to capture bus-based microprocessor signal activity. The typical 8-bit microcontroller doesn't even provide pins for its address and data buses. Also, when compared to the familiar scope, logic analyzers have slower updates and can be difficult to set up. It's often faster to just poke and probe with a dual-channel scope until the signal problems are found, rather than spend hours learning or re-learning how to set up the logic analyzer to capture a few additional signals.
Probably the best measurement solution for debugging 8-bit embedded systems is a hybrid scope/logic analyzer such as Hewlett-Packard's mixed-signal oscilloscope (MSO). These instruments look and run more like traditional scopes than logic analyzers. They're relatively easy to set up and are interactive, offering fast display update rates like those expected from a scope. Instruments like the MSO extend the features of the oscilloscope to include up to 16 logic channels tied to a scope time base. The additional logic channels not only add waveform-display capability, but also allow triggering of the scope on complex digital-logic conditions.
The following examples illustrate how logic triggering can enhance the viewing of complex MCU-based signals on an oscilloscope. Figure 2 shows a diagram of Parallax's BASIC Stamp II, an embedded-control module based on a Microchip PIC16C57 8-bit microcontroller. Easily programmed, the BASIC Stamp is often designed into various industrial and consumer products. Like many designs based on 8- and 16-bit microcontrollers, the hardware is simple. The signals generated by these designs, however, are often complex. In the first example, the BASIC Stamp II was programmed to generate a series of repetitive signals representing a variety of real-world embedded-control signals.
Figure 3 shows a repetitive capture—using an MSO—of 10 analog and digital I/O signals from the BASIC Stamp II MCU-based control module. The scope's two analog input channels (A1 and A2) captured a complex pulse-width-modulated (PWM) signal (top waveform) and an RC-filtered version of the same signal. The scope's logic inputs (0 through 7) acquired eight outputs from the MCU's RB0-RB7 I/O port. For this set of repetitive acquisitions, the oscilloscope was set up to trigger on a rising edge of channel 2 (the analog-filtered PWM signal). Note the multiple, phase-shifted images captured in this repetitive set of acquisitions. They're the result of not establishing unique trigger criteria based on the MCU's long, repetitive cycle time.
With most dual-channel oscilloscopes that provide only edge triggering, an unstable display of complex waveforms, similar to the top two shown in Figure 3, is about the best one could expect to achieve. But, if the MCU's program cycle time is known, most scopes offer the possibility of locking onto the signal more precisely by using trigger hold-off. Adjusting the hold-off, however, is not easy to do.
A better solution is to synchronize the scope's triggering on a known output pattern of the MCU's I/O port. This pattern may represent a specific temperature reading or the speed (revolutions per second) of an induction motor controlled by the PWM output. Figure 4 shows the same 10 waveforms captured earlier. But this time, the display of repetitive acquisitions is stable. This is the result of triggering the scope on a unique pattern condition that occurs only once in each cycle of the MCU's program code. With the 0.00 seconds delay indicated in the figure, the default trigger position point is at center screen. The selected pattern specification was set to trigger when a "high" occurred on analog channel 1 (A1) at the same time that F1 (hex) occurred on the lower eight bits of the logic inputs. The remaining nine inputs were specified as "don't cares" (X). Note that the actual trigger condition is specified as highs (H) and lows (L), rather than in true hexadecimal or binary (1s and 0s) format. As mentioned earlier, triggering on pattern conditions also is possible with many four-channel DSOs. But, a multiple-channel MSO provides even more flexibility in finding a specific word to trigger on, without the complexity of a logic analyzer.
Another alternative for triggering on complex signals of MCU-based systems is time-qualified triggering. Some scope manufacturers refer to this mode as pulse-width or glitch triggering. Whatever the name it's called by, the functionality is the same. Time-qualified triggering lets you set up the scope to trigger on a specific time duration of either a positive or negative pulse.
Figure 5 illustrates three time-qualified options for positive-going pulses only. The "Less Than" time qualifier can be handy for finding narrow glitches, hence the name—glitch triggering. For locating and triggering on long dropouts or latched conditions, the "Greater Than" time qualifier is the best bet. As for the "Within Range" time qualifier, it's advantage is that it can trigger on unique pulses within a serial pulse train.
MCU-based motor-control applications are good candidates for time-qualified triggering. The extremely noisy environment often found in motors makes triggering on an edge of an induction-motor drive signal almost impossible. The time-qualified triggering mode can establish a more stable trigger by synchronizing acquisition on a particular pulse of the PWM output signal. Plus, since each pulse of the PWM signal is phase-related to the ac-motor drive signal, this technique lets you synchronize the display on particular phases of the analog signal. (Note: The ac-motor drive signal is simply a low-pass, filtered version of the PWM pulse train.)
Triggering "Within Range"
The waveform display in Figure 6 shows an example of triggering on a unique PWM pulse using the "Within Range" (less than/greater than) time qualifier. In this example, the scope was set up to trigger on a positive pulse of channel A1 if it occurred for a duration greater than 14.50 µs but less than 15.50 µs.
The scope found and triggered repetitively on a 15.10 µs-wide pulse (shown expanded by the delayed time base in the lower portion of the scope's display). This pulse relates to a specific phase of the motor drive signal. As shown, using edge triggering on the ac-motor drive signal could have resulted in an unstable display because of the high level of noise picked up by the scope's A2 input.
What's next after exhausting all choices in attempting to establish a stable trigger point on a complex MCU-based signal? Perhaps the scope doesn't have a particular triggering feature, such as pattern or time-qualified triggering. Or, maybe the signals are too complex. There's another option. If the scope has sufficient acquisition memory, you can set up the instrument to capture a wide window of single-shot waveform information. Then, you can zoom in on any portion of the stored waveform. Since the waveform is stored, it will appear to be triggered. If the scope's memory is deep enough, effectively capturing "everything" from a single acquisition is possible.
Figure 7 exemplifies capturing a complex infrared (IR) signal generated from a microcontroller-based portable transmitter. Setting up a unique trigger condition to capture this signal is a difficult assignmentat best But, rather than trying to establish a complex condition to trigger on this signal, you may want to merelyhave the scope capture and display waveforms based on a simple edge-trigger condition.
However, this usually produces an unstable display. But all is not lost. To remedy this situation, merely scale the time base to ensure capturing a wide window. Then select the single-acquisition mode on your deep-memory scope to randomly digitize the complex signals. Once the signal is digitized, stored, and displayed on screen, it appears stable as seen in the figure. With the deep memory acquisition of this scope (1 Mbyte), the delayed time base (lower waveform) is used to zoom in on various segments of the complex IR signal. Again, the key to using this method of triggering—or, to be more exact, non-triggering—is sufficient acquisition memory.