adc: rework the example to remove rms and mean value.

Signed-off-by: Francisco Gil <francisco.gilmartinez@digi.com>
This commit is contained in:
Francisco Gil 2017-11-23 13:45:23 +01:00
parent 68f3f0f815
commit 58469e08da
3 changed files with 3 additions and 14 deletions

View File

@ -4,7 +4,7 @@ Digi APIX ADC Sample Application
Sample application to access and manage ADC channels using the Digi APIX library. Sample application to access and manage ADC channels using the Digi APIX library.
The application enables one ADC channel on the board. After that, the application The application enables one ADC channel on the board. After that, the application
takes periodic samples and calculates the rms and mean value of the samples batch. takes periodic samples and prints the raw value and the value in mv.
The ADC lines used in the sample are mapped as follows in the Digi Boards: The ADC lines used in the sample are mapped as follows in the Digi Boards:
- **CCIMX6 SBC**: PMIC_ADCIN1 (GPIO Connector Pin 1). - **CCIMX6 SBC**: PMIC_ADCIN1 (GPIO Connector Pin 1).

View File

@ -32,8 +32,6 @@ static adc_t *adc;
struct adc_sampling_cb_data { struct adc_sampling_cb_data {
adc_t *adc; adc_t *adc;
int total_value;
int total_value_rms;
int number_of_samples; int number_of_samples;
}; };
@ -143,8 +141,6 @@ static int adc_sampling_cb(int sample, void *arg)
struct adc_sampling_cb_data *data = arg; struct adc_sampling_cb_data *data = arg;
float sample_mv = 0; float sample_mv = 0;
data->total_value += sample;
data->total_value_rms += powf(sample, 2);
data->number_of_samples--; data->number_of_samples--;
sample_mv = ldx_adc_convert_sample_to_mv(data->adc, sample); sample_mv = ldx_adc_convert_sample_to_mv(data->adc, sample);
@ -193,8 +189,6 @@ int main(int argc, char *argv[])
} }
cb_data.number_of_samples = number_of_samples; cb_data.number_of_samples = number_of_samples;
cb_data.total_value = 0;
cb_data.total_value_rms = 0;
/* Register signals and exit cleanup function */ /* Register signals and exit cleanup function */
atexit(cleanup); atexit(cleanup);
@ -220,10 +214,5 @@ int main(int argc, char *argv[])
sleep(1); sleep(1);
} }
printf("The mean value of the samples is: %d mV\n",
cb_data.total_value/number_of_samples);
printf("The RMS value of the samples is: %.2f mV\n",
sqrt(cb_data.total_value_rms/number_of_samples));
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -68,7 +68,7 @@ the number of address bytes.
<name>Digi APIX ADC Sample</name> <name>Digi APIX ADC Sample</name>
<description> <description>
Sample application to access and manage ADC channels using the Digi APIX library. Sample application to access and manage ADC channels using the Digi APIX library.
The application enables one ADC channel on the board. After that, the application takes periodic samples and calculates the rms and mean value of the samples batch. The application enables one ADC channel on the board. After that, the application takes periodic samples and prints the raw value and the value in mv.
</description> </description>
<path>apix-adc-example</path> <path>apix-adc-example</path>
<platforms> <platforms>