1. Home
  2. Docs
  3. How-To
  4. Use ADC Ports in Hexabitz Modules to Read Analog Signals

Use ADC Ports in Hexabitz Modules to Read Analog Signals

⚙️ Introduction:

Hexabitz modules provide dedicated ADC (Analog-to-Digital Converter) ports for direct analog signal acquisition from external sensors (temperature, pressure, light, etc.), enabling precision environmental monitoring and intelligent system development through 12-bit conversion.

Key features:
⚠️ Not all ports support ADC – Verify with module’s factsheet
✅ Port combinations:
Depending on the module layout and availability, you can read up to four analog signals using one of the following combinations:

  • P2 and P3 (Top and Bottom sides).
  • P2 and P1 (Top and Bottom sides).

⚙️ How to Use the ADC Feature?

  1. Selecting the ADC Port

Before reading any signal, you must select the port to be used for ADC using the following API:

BOS_Status ADCSelectPort(uint8_t ADC_port);

  1. Reading Analog Voltage

Once the port is selected, you can read the analog value using the following API:

BOS_Status ReadADCChannel(uint8_t Port, ModuleLayer_t side,float *adcVoltage);

  • Port: Selected ADC port (e.g: P2).
  • side: TOP or BOTTOM connection layer.
  • adcVoltage: Stores voltage in volts (range: 0.0V – 3.3V).

Note: The value will range between 0.0 mV and 3300 mV, corresponding to the input signal level.

⚠️ Critical Notes:

  • Reference voltage = 3.3V (signals must not exceed this)

  • For signals >3.3V, implement a voltage divider ⚡ 

  1. Reading Voltage Percentage

BOS_Status GetReadPercentage(uint8_t port,ModuleLayer_t side,float *precentageadcVoltage);

  • precentageadcVoltage: A pointer to store the resulting voltage value as a percentage.
  1. Deinitializing ADC Channel

BOS_Status ADCDeinitChannel(uint8_t port);

Disables ADC functionality on specified port to conserve resources.

⚙️ Implementation Examples

  • STM32CubeIDE Program

/* Definition of global variables */
float adcVoltage1 = 0;
float adcVoltage2 = 0;
float adcVoltagePercentage1 = 0;
float adcVoltagePercentage2 = 0;
  /* Select ADC ports */
   ADCSelectPort(P1);
   ADCSelectPort(P2);
  /* put your code here, to run repeatedly. */
  while(1){
    /* Read analog voltages (in volts) */
   ReadADCChannel(P1, TOP, &adcVoltage1);
    ReadADCChannel(P2, BOTTOM, &adcVoltage2);
   /* Read analog values as percentages */
   GetReadPercentage(P1, TOP, &adcVoltagePercentage1);
    GetReadPercentage(P2, BOTTOM, &adcVoltagePercentage2);
   /* Example condition: Deinitialize P1 if voltage on P2-top
      is above 2200mV */
    if (adcVoltage1 > 2200.0f) {
      ADCDeinitChannel(P1);
    }
     
   }
}

  • Terminal Programs (e.g., MobaXterm)
    Execute ADC commands directly via serial interface.

 

How can we help?