🛠 Getting started with analog acquisition on HPM5100

HPMicro HPM5100: 400 MHz RISC-V MCU with Integrated Analog Peripherals · debutant · Apprenez à configurer les convertisseurs ADC SAR 16 bits intégrés pour lire une tension analogique simple.

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

Steps

  1. 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.
  1. Project Setup: Open the HPMicro SDK and navigate to examples/drv/adc. Copy the base example project to your workspace. Open main.c.
  1. 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.
  1. Channel Configuration: Select the channel corresponding to your physical pin. Enable software trigger mode for simplified reading in this first example.
  1. Reading Loop: In the while(1) loop, use adc_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.
  1. Compile and Flash: Compile the project using make or 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.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials