Changing ADC Sampling Rate on Pixhawk6C

Hi Everyone,

I’m trying to repurpose the RSSI_IN port on my Pixhawk 6C Mini to be a general purpose ADC input. However the sampling rate is too low to accomplish what I’m trying to do. However I’m having some issues getting this to work.

Researching around, I’ve identified the steps that’s needed to get this working:

  • Update ./libraries/AP_IOMCU/iofirmware/analog.cpp:adc_init() to use a lower sample time, I.e. ADC_SAMPLE_13P5
  • Build the IO processor firmware using ./Tools/scripts/build_iofirmware.py
  • Flash the IO processor with bin/iofirmware_lowpolh

My questions is this:

  • Is there a way to up the sampling rate, without needing to modify the firmware?
  • Is there a way to flash the IO processor without the need for an external SWD debugger?
    (The Pixhawk6C Mini IO debugger is exposed via testpoints on the PCB, rather then a dedicated JST port)
  • Are there any other pins on the flight controller that can be repurposed to read in a 3.3V ADC signal?
  • Can anyone confirm if this is the (only) line within analog.cpp that needs to be changed?
ADC1->SMPR2 = ADC_SMPR2_SMP_AN4(ADC_SAMPLE_28P5) | ADC_SMPR2_SMP_AN5(ADC_SAMPLE_28P5);

Thanks for any feedback and / or suggestions

How about the actual ADC ports in the board?

I can’t remap the ADC_1 lines, as those are currently used to monitor the battery.

However for the ADC_3 line, I think its only used internally or something, as I can’t find any [documentation]( Pixhawk 6C Mini Ports - Holybro Docs) that links them to an exposed port.

(They are mapped to the following on the FMU)

(Additionally, they’re disabled by default on the firmware, and have to be enabled)

Not saying I can help, but answers to these might help others to help you.

  • What do you need to sample that needs some high rate?
  • What makes you think the ADC sampling rate is too low?

I’m migrating away from the Pixhawk 2.4.8 flight controller, which has two dedicated ADC port that samples at 10 ms.

Attached to the ADC port is a variable resistor that measures the angle at which the motor is currently positioned at. Given the high RPM of the motor, and the precision I need to monitor it at, I would like to bring the sampling rate down to 10 ms, as to limit the changes needed when migrating.