Hello,
I'd like to implement an AD-Conversion in the PXP-Reporter demo. Therefore, I have implemented the following code in periph_init():
hw_gpio_set_pin_function(HW_GPIO_PORT_1, HW_GPIO_PIN_3, HW_GPIO_MODE_INPUT, HW_GPIO_FUNC_ADC); //ADC-Pin
静态gpadc_config cfg = {
.clock = HW_GPADC_CLOCK_INTERNAL,
.input_mode = HW_GPADC_INPUT_MODE_SINGLE_ENDED,
.input = HW_GPADC_INPUT_SE_P13,
.input_attenuator = true,
.oversampling = 1,
};
hw_gpadc_init(&cfg);
hw_gpadc_enable();
hw_gpadc_start();
Now, in the pxp_reporter_task, I check for this value every second like this:
unsigned int BattVoltAD = 0;
BattVoltAD = hw_gpadc_get_value();
hw_gpadc_start();
Unfortunately, the results are crap. It doesn't matter if I connect pin 1_3 to ground or to V33, the value jumps between 163 to 768. Am I missing something?
What is strange is that when I debug the code, it always hangs at sys_power_mgr.c -> pm_system_init() -> hw_gpadc_set_ldo_delay(0x0B);
Thanks in advance,
Philipp
As you are using the PXP Reporter demo then i assume the ADC adapter is in use i.e. the following is defined in custom_config_qspi.h:
#define dg_configGPADC_ADAPTER 1
If this is the case then i would recommend using the adapter to interface with the ADC, you can see how this is done by looking at the read_battery_level function in the file pxp_reporter_task.c. Take a look at the version of the function that gets included when dg_configUSE_SOC is not defined.