Skip to content

Electronics Design

This week’s Group Assignment was about using the test equipment in our lab to observe the operations of a microcontroller. We had access to both a multimeter, a logic analyzer and an oscilloscope, which we used to take the measurements. With the multimeter and the oscilloscope we measured the operation of a PWM signal from the “Fade” sample program in the Arduino library. So that you can save yourself the search if you want to copy us, below is the code we used.

/*
  Fade

  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.

  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
  are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
*/

int led = 9;         // the PWM pin the LED is attached to
int brightness = 0;  // how bright the LED is
int fadeAmount = 5;  // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

On the hardware side, we used a simple circuit with an LED and a series resistor and connected it to the digital PIN 9 of an Arduino Mega. Here are some illustrations of our measurement circuits. On the left is the current measurement in series that we made with the multimeter. On the right is the parallel voltage measurement, where we measured simultaneously with a multimeter and oscilloscope - accordingly, we connected two voltmeters in parallel.

In contrast, here is another picture of the practical setup, which unfortunately does not show the wiring so clearly.

This brings us to the results and what the measurements show. Starting with the voltage measurement, a comparison between the oscilloscope and multimeter shows that the multimeter has a significant delay. To better recognize this, it may be useful to stop the video briefly. This is particularly useful at moments when the LED is briefly off.

What we see on the oscilloscope is the typical behavior of a PWM signal, which oscillates between 0 V and about 4.5 V. PWM is a technique in which a digital signal changes rapidly between high and low, with the ratio of on to off time (duty cycle) controlling the effective power or voltage.

Our video shows the typical square wave on the oscilloscope. This method is often used to control motors, LEDs and other electronic components.

When measuring the current, we noticed that the displayed current value was not constant, but changed regularly. This is probably due to the sampling rate of the multimeter, which is not synchronized with the fast PWM frequency.

The fluctuations show that conventional multimeters are only of limited use for such signals, as they record different instantaneous values depending on the time of measurement. This highlights the need for an oscilloscope or special measuring devices for precise analysis of PWM currents.

The logic analyzer was hooked up to the Arduino via the TX pin and GND and basically captured the signal that was sent to the serial monitor in the Arduino IDE.

We used the following code that we found in this Sparkfun tutorial to make the controller talk gibberish, which made the captured signal a little less boring:

void setup() {
  // put your setup code here, to run once:
  randomSeed(analogRead(A0));
  Serial.begin(random(1, 115200)); // Set the baud rate to a random value between 1 and 115200 bps
}

void loop() {
  Serial.println(millis()); // Print the time
  delay(250);
}

To get an actual result we had to set the logic analyzer’s input pin to listen for a UART signal.

Then we could hit the analyzer’s SMPL button to capture about 5 seconds worth of signals.