Question about lpcom and ADC switching configuration

hi

I configured the battery voltage detection using an event of lpcom, and after the event, lpcomp is converted to ADC to measure the voltage.

( lpcomp -> adc -> lpcom )

I configured the code as shown below and tested it, and it works well. Please review to see if there are any problems.

adc()

{

 nrf_drv_lpcomp_disable();

BatVoltage()

nrf_drv_lpcomp_enable();

}





int32_t BatVoltage( void )
{
int32_t BAT_output = 0;
uint8_t channel = 0;
nrf_saadc_value_t buf_adc;

nrf_saadc_channel_config_t aread = {

.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
.resistor_n = NRF_SAADC_RESISTOR_DISABLED,
.gain = NRF_SAADC_GAIN1_6,
.reference = NRF_SAADC_REFERENCE_INTERNAL,
.acq_time = NRF_SAADC_ACQTIME_40US,
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
.burst = NRF_SAADC_BURST_DISABLED, ///< Burst mode configuration.
.pin_p = NRF_SAADC_INPUT_AIN2,
.pin_n = NRF_SAADC_INPUT_DISABLED
};

nrf_saadc_channel_init( channel, &aread );
nrf_saadc_resolution_set(SAADC_RESOLUTION_VAL_10bit);

memset( &buf_adc, 0, sizeof(buf_adc) );
nrf_saadc_buffer_init( &buf_adc, 1 );
nrf_saadc_oversample_set( NRF_SAADC_OVERSAMPLE_DISABLED );
nrf_saadc_continuous_mode_disable();

nrf_saadc_enable();
while( !nrf_saadc_enable_check() ){}

nrf_saadc_task_trigger( NRF_SAADC_TASK_START );
while( !nrf_saadc_event_check( NRF_SAADC_EVENT_STARTED ) ) {}
nrf_saadc_event_clear( NRF_SAADC_EVENT_STARTED );

nrf_saadc_task_trigger( NRF_SAADC_TASK_SAMPLE );
while( !nrf_saadc_event_check( NRF_SAADC_EVENT_RESULTDONE ) ) {}
nrf_saadc_event_clear( NRF_SAADC_EVENT_RESULTDONE );

nrf_saadc_task_trigger( NRF_SAADC_TASK_STOP );
while( !nrf_saadc_event_check( NRF_SAADC_EVENT_STOPPED ) ) {}
nrf_saadc_event_clear( NRF_SAADC_EVENT_STOPPED );

return buf_adc;

}

 thank

Parents Reply Children
No Data
Related