Assignments

Week 6 – Embedded Programming

Assignment

Group assignment
  • Use the test equipment in your lab to observe the operation of an embedded microcontroller.
Individual assignment
  • Simulate a circuit.
  • Use an EDA tool to design an embedded microcontroller system using parts from the inventory, and check its design rules for fabrication.
  • Extra credit: Try another design workflow.
  • Extra credit: Design a case.

Group Assignment – Reflection

During the group assignment, I gained practical experience using laboratory test equipment to analyze real embedded systems behavior. Working with the oscilloscope helped me observe signals in real hardware (power rails, GPIO outputs, PWM waveforms) and understand the relationship between code and electrical response. Troubleshooting the LED test reinforced the importance of voltage drops, current limitation, and real circuit conditions.

Group assignment image 1
Group assignment image 2
Group assignment image 3

Oscilloscope – Siglent SDS 1102CML

An oscilloscope is used to visualize electrical signals over time. Unlike a multimeter, it shows the waveform, so we can analyze amplitude, frequency, period, duty cycle, and timing behavior. This is key for debugging embedded systems and confirming the output matches the program.

Oscilloscope photo
Oscilloscope DC example

The model used was the Siglent SDS 1102CML. It is useful for digital signals (HIGH/LOW), PWM signals, and verifying correct timing and stability in microcontroller outputs.

Waveforms
PWM 50%

Test 1 – Voltage Measurements (Oscilloscope)

The board was powered by USB (5V). The onboard regulator provides a stable 3.3V rail for the microcontroller. Measuring the 3V3 pin confirmed correct regulation (3.3V).

Measuring 3.3V rail
Probe points

Then we measured a GPIO header related to GPIO 1 and got around 2.9V. This happens because the GPIO was also driving an LED load, producing a small voltage drop at that point, while the main 3.3V rail remained stable.

GPIO 2.9V reading
LED load on GPIO

Test 2 – PWM Duty Cycle and LED Behavior

We tested PWM at 25%, 50%, 75%, and 100% to see how duty cycle affects brightness (average power delivered to the LED).

25%: dimmer (ON for a short time).

PWM 25% 1
PWM 25% 2

50%: brighter (ON for half the period).

PWM 50% 1
PWM 50% 2

75%: close to max brightness.

PWM 75% 1
PWM 75% 2

100%: constant HIGH (acts like DC).

PWM 100% 1
PWM 100% 2

LED - Diode Test and Signal Analysis

The multimeter was set to diode mode to verify several LEDs. Most illuminated, confirming polarity and basic functionality. One red LED did not turn on as expected, so we checked conditions more carefully.

Diode test setup

LED Forward Voltage by Color

LEDs have a forward voltage (Vf) depending on color/material. Red/orange/yellow often work around 2.0–2.2V, while blue/white usually need 2.8–3.7V. Even if voltage is enough, the LED may not light if current is too low. A series resistor is required to keep current safe and stable.

LED Vf infographic

Individual Assignment


I designed a custom embedded microcontroller board using an EDA tool, including the XIAO SAMD21, resistors, LED, push button, and power connections. I completed the schematic, arranged components in the board layout, performed manual routing, and ran DRC checks to solve soldermask and clearance errors. I also customized the board shape and verified the design using a 3D preview before fabrication.

EDA work 1
EDA work 2

This circuit was first tested as a simulation. It represents the initial concept of my board, where a push button is used as an input and an LED as an output. The simulation helped me validate the connections and logic before moving to the PCB design with the XIAO SAMD21.

DC power supply connected to oscilloscope

Simulation Exercises

These simulations were done first to confirm how the microcontroller reads inputs and controls outputs. It helped avoid mistakes before designing the final PCB.

Exercise 1 – Push Button Controlling an LED

Basic test: when the button is pressed, the LED turns ON; when released, it turns OFF.


const int led = 9;
const int boton = 10;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(boton, INPUT);
}

void loop() {
  int estado = digitalRead(boton);

  if (estado == HIGH) {
    digitalWrite(led, HIGH);
  } else {
    digitalWrite(led, LOW);
  }
}
Simulation 1

Exercise 2 – Displaying Button State on an I2C LCD

Added an I2C LCD to show the button state and LED state. This demonstrates I2C communication and user feedback on a display.


#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int led = 9;
const int boton = 10;

LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {
  pinMode(led, OUTPUT);
  pinMode(boton, INPUT);

  lcd.init();
  lcd.backlight();
}

void loop() {
  int estado = digitalRead(boton);
  digitalWrite(led, estado);

  lcd.setCursor(0,0);
  lcd.print("Boton: ");
  lcd.print(estado ? "ON " : "OFF");

  lcd.setCursor(0,1);
  lcd.print("LED: ");
  lcd.print(estado ? "ON " : "OFF");

  delay(100);
}
I2C LCD OFF
I2C LCD ON

Exercise 3 – Potentiometer Controlling LED Brightness

Used a potentiometer as an analog input. The read value is mapped to PWM to change LED brightness.


const int led = 9;
const int pot = A0;

void setup() {
  pinMode(led, OUTPUT);
}

void loop() {
  int valor = analogRead(pot);
  int brillo = map(valor, 0, 4095, 0, 255);
  analogWrite(led, brillo);
}
Potentiometer simulation

Custom PCB Shape Design (Mjolnir)

I created a custom PCB outline inspired by Mjolnir. The decorative lines are part of the visual design, while all electronic components remain inside the functional area.

Mjolnir outline

Components used: XIAO SAMD21 (main microcontroller), LED (output indicator), push button (user input), R1 (current limit for LED), R2 (button stability / avoid floating), and power nets (5V, 3V3, GND).

Before layout
After layout

Design Rule Check (DRC)

When running DRC, warnings appeared because some decorative lines were not connected to any net. The tool reads them like traces, so it reports them as “not connected”.

DRC warnings list

After confirming the real circuit connections were correct (LED + button + power), the warning list was cleared using Clear All.

Clear all in rules

3D Visualization

Finally, I used the 3D view to confirm the final size and check that the components fit well inside the outline.

3D PCB view

Initial PCB Design and Issues

My first idea was a larger board to use leftover copper (less waste). But I changed to a smaller board because the first version still removed too much copper during milling.

I had two main problems: (1) I confused some pin header assignments, and (2) while labeling nets, I accidentally deleted one label, which caused missing connections.

Initial schematic

PCB Layout and Detected Errors

Because of the wrong pin mapping and the missing label, the PCB showed airwires (unrouted connections) and multiple DRC messages. These errors basically mean: “there are nets that should be connected, but they are not routed or not recognized”.

PCB errors / airwires

Correcting the PCB Connections

I fixed the pin assignments and restored the missing net label. After that, I routed the traces again until all required nets were connected properly.

Corrected routing

Dimension Verification

In the 3D environment, I measured the board to confirm the final dimensions and verify it fits fabrication constraints.

Measure 1
Measure 2

Final PCB Design

The final result is a compact development board that reduces copper waste while keeping all required connections for the XIAO and external headers.

Final PCB


Test – PWM Simulation and Signal Analysis

Power Supply Reference (DC Measurement)

Before analyzing PWM signals, I first connected a regulated DC power supply directly to the oscilloscope. The objective was to observe how a constant voltage behaves over time and use it as a reference for comparison.

When a stable DC voltage is applied, the oscilloscope displays a horizontal flat line because the voltage does not vary with time. Unlike PWM signals, which alternate between HIGH and LOW states, a DC signal remains constant.

DC power supply connected to oscilloscope

Arduino - LED Basic Circuit

I assembled a simple circuit using an Arduino Uno, a red LED, and a 200 Ω resistor connected in series. The LED was connected to a PWM digital pin and to GND through the resistor to limit current and protect the component.

I = (Vsource − Vf) / R

Arduino LED basic setup

Arduino - PWM Signal Measurement

Then, I connected the oscilloscope to the PWM output pin. The signal observed was a square wave switching between 0V and 5V.

The multimeter measured the average voltage of the PWM signal. The LED showed a forward voltage of approximately 2V, while the resistor controlled the current in the circuit.

Arduino PWM oscilloscope measurement

PWM Duty Cycle Analysis

PWM (Pulse Width Modulation) controls the average voltage delivered to a load by modifying the percentage of time the signal remains HIGH within one period.

Duty Cycle (%) = (Ton / T) × 100

Vavg = Duty × Vmax

25% Duty Cycle
analogWrite(ledPin, 64);

At 25%, the signal stays HIGH only one quarter of the period. The oscilloscope shows narrow pulses, and the LED appears dim because the average delivered energy is low.

25% duty cycle
50% Duty Cycle
analogWrite(ledPin, 128);

At 50%, HIGH and LOW durations are equal. The waveform shows symmetric pulses, and LED brightness increases because the average voltage is higher.

50% duty cycle
75% Duty Cycle
analogWrite(ledPin, 192);

At 75%, the HIGH portion dominates most of the period. The LED brightness is significantly stronger, and the oscilloscope shows wider pulses.

75% duty cycle
100% Duty Cycle
analogWrite(ledPin, 255);

At 100%, the signal becomes constant HIGH (pure DC). The oscilloscope displays a flat line at 5V, and the LED reaches maximum brightness.

100% duty cycle

Potentiometer Behavior (Variable Resistance)

When using the potentiometer, it acted as a variable resistor connected in series with the LED, modifying the total resistance of the circuit. As the potentiometer was adjusted (around 300 Ω), the resistance changed and directly affected the current flowing through the LED according to Ohm’s Law.

I = (Vsource − Vf) / Rtotal

When the resistance increases, the current decreases (LED dimmer). When the resistance decreases, the current increases (LED brighter). This confirms that LED brightness depends mainly on current, not directly on voltage.

Potentiometer affecting LED brightness

Potentiometer Test (Resistance and Voltage Range)

A potentiometer was tested to understand how its resistance changes with rotation and how it can be used either as a variable resistor or as a voltage divider.

Potentiometer setup on breadboard with multimeter
Potentiometer wiring setup for resistance measurement using a multimeter.

Resistance Measurement (Ohms)

When the wiper was rotated fully to one side, the measured resistance dropped close to 0 Ω. When rotated to the opposite extreme, the reading reached approximately 250 kΩ.

Potentiometer readings showing 0 ohms and 250 kilo-ohms
Minimum and maximum resistance readings while rotating the potentiometer.

At intermediate knob positions, values around 140 kΩ and 110 kΩ were observed, confirming continuous adjustment across its full range.

Intermediate potentiometer resistance readings
Intermediate resistance values measured at different potentiometer positions.

Voltage Divider Behavior (Max = 3.3 V)

When used as a voltage divider, the output at the wiper varies from 0 V up to the supply voltage. Since the system was supplied with 3.3 V, the maximum measured output was also 3.3 V.


Video Demonstration


Simulation – LED Voltage/Current vs Supply Voltage

A series of simulations were performed to observe how LED current and voltage behave when changing the power supply and resistor conditions.

Case 1 – 2×AA Batteries (≈3.0 V)

2xAA 3V - case A
2xAA 3V - case B

Case 2 – 3×AA Batteries (≈4.5 V)

3xAA 4.5V - case A
3xAA 4.5V - case B

Case 3 – Regulated Bench Supply (5.0 V)

Regulated 5V simulation
Regulated 5V: stable readings and controlled LED current.

Case 4 – High Voltage (30 V) Without Proper Current Limiting

30V overcurrent failure simulation
30V without proper current limiting: overcurrent and LED failure in simulation.

Case 5 – High Voltage (30 V) With Current Limiting (2 kΩ)

30V with 2k resistor simulation
30V + 2 kΩ: current reduced to safe values and LEDs operate normally.