← Back to Lab Hub RP2040 Analog Signal Processing Lab

Analog Input (ADC) to PWM Output Signal Processing

Converting Continuous Voltage (0.0V - 3.3V) to 16-Bit Register Values & PWM Output

⚡ Mechatronic Signal Flow & Conversion Principles
1. Analog Sensing (ADC): The potentiometer acts as a variable voltage divider, supplying a smooth analog voltage between 0.0V and 3.3V to RP2040 pin ADC0 (GP26). MicroPython converts this to a 16-bit register value (`0` to `65535`).
2. PWM Output Modulation: The software reads the ADC register and directly feeds that 16-bit value into `pwm.duty_u16(val)`, driving an output device (like an LED or motor driver) on GP15.

ADC In (GP26): 0 - 3.3V → 0 - 65535 PWM Out (GP15): duty_u16(val) → 0% - 100%
🎛️ Potentiometer Hardware Control
Analog Input Voltage: 1.65 V
📈 Analog Input Voltage Trace (ADC In - GP26)
📉 Output Duty Cycle Waveform (PWM Out - GP15)
🐍 Live MicroPython Signal Processing Loop
from machine import ADC, PWM, Pin
import time

# Configure ADC Input and PWM Output Pins
pot = ADC(Pin(26)) # GP26 / ADC0
led = PWM(Pin(15)) # GP15 Output
led.freq(1000) # Set 1 kHz PWM Frequency

# Processing Loop
while True:
  raw_adc = pot.read_u16() # Read 16-bit register
  led.duty_u16(raw_adc) # Set PWM Duty Cycle
  time.sleep_ms(10)

# Live Register Status:
  Raw ADC Register: 32768
  PWM Duty Cycle: 50.0%