🛠 Getting started with analog acquisition on HPM5100
Objectives
This tutorial guides you through configuring the integrated 16-bit SAR ADC on the HPM5100. Unlike many MCUs requiring external components for basic filtering or amplification, the HPM5100 integrates configurable operational amplifiers (PGA) and four 16-bit ADCs sampling up to 2 MSPS. The goal is to read a variable voltage (potentiometer or sensor output) and display it via the serial port.
Required Hardware
- HPM5100 development board
- USB-C cable for power and serial communication
- 10 kΩ potentiometer (or stable variable voltage source)
- Serial terminal software (PuTTY, Tera Term, or Arduino IDE)
- HPMicro SDK (v1.13.0+) installed on your PC
Steps
- Hardware Preparation: Connect the potentiometer wiper to an analog input pin (e.g., ADC0_IN0) on the HPM5100. Connect the other two pins to 3.3V and GND on the board. Ensure connections are secure.
- Project Setup: Open the HPMicro SDK and navigate to
examples/drv/adc. Copy the base example project to your workspace. Openmain.c.
- Peripheral Initialization: Code must initialize the ADC clock. The 400 MHz RISC-V core handles interrupts, but the ADC runs on its own clock domain. Verify the sampling frequency is set below 2 MSPS to ensure 16-bit accuracy.
- Channel Configuration: Select the channel corresponding to your physical pin. Enable software trigger mode for simplified reading in this first example.
- Reading Loop: In the
while(1)loop, useadc_get_channel_value()to read the raw value (0 to 65535 for 16 bits). Convert this value to voltage (0 to 3.3 V) using a simple proportion.
- Compile and Flash: Compile the project using
makeor your IDE. Connect the board via USB and start flashing.
Verification
Open the serial monitor at 115200 bauds. Turn the potentiometer: displayed values should vary linearly between 0 and 65535, and calculated voltage between 0.00 V and 3.30 V. Stable variation indicates noise is correctly filtered.
Further Reading
Explore using integrated PGAs to amplify small signals without external components, or configure hardware triggering via PWM modules for precise synchronization with motor control.