application: minor, rename channels to adc_channels to avoid confusion with signal channels
This commit is contained in:
parent
1facc923c3
commit
57bfbbecd1
|
@ -53,7 +53,7 @@ static uint32_t boot_time = 0;
|
||||||
|
|
||||||
#define TARGET_CHANNEL 1 /**< PA1/ADC1_IN1 used to measure target voltage */
|
#define TARGET_CHANNEL 1 /**< PA1/ADC1_IN1 used to measure target voltage */
|
||||||
#define SIGNAL_CHANNEL 2 /**< PA2/ADC1_IN2 used to measure signal voltage */
|
#define SIGNAL_CHANNEL 2 /**< PA2/ADC1_IN2 used to measure signal voltage */
|
||||||
const uint8_t channels[] = {ADC_CHANNEL17, ADC_CHANNEL(TARGET_CHANNEL), ADC_CHANNEL(SIGNAL_CHANNEL)}; /**< voltages to convert (channel 17 = internal voltage reference) */
|
const uint8_t adc_channels[] = {ADC_CHANNEL17, ADC_CHANNEL(TARGET_CHANNEL), ADC_CHANNEL(SIGNAL_CHANNEL)}; /**< voltages to convert (channel 17 = internal voltage reference) */
|
||||||
|
|
||||||
#define SIGNAL_PD_PIN PA3 /**< pin to pull signal low for voltage measurement */
|
#define SIGNAL_PD_PIN PA3 /**< pin to pull signal low for voltage measurement */
|
||||||
#define SIGNAL_PU_PIN PA4 /**< pin to pull signal to target voltage (controlling gate of pMOS) */
|
#define SIGNAL_PU_PIN PA4 /**< pin to pull signal to target voltage (controlling gate of pMOS) */
|
||||||
|
@ -153,12 +153,12 @@ static uint32_t port2rcc(uint32_t port)
|
||||||
*/
|
*/
|
||||||
static float* measure_voltages(void)
|
static float* measure_voltages(void)
|
||||||
{
|
{
|
||||||
static float voltages[LENGTH(channels)]; // to store and return the voltages
|
static float voltages[LENGTH(adc_channels)]; // to store and return the voltages
|
||||||
|
|
||||||
// read lid temperature using ADC
|
// read lid temperature using ADC
|
||||||
ADC_SR(ADC1) = 0; // reset flags
|
ADC_SR(ADC1) = 0; // reset flags
|
||||||
uint16_t adc_values[LENGTH(channels)];
|
uint16_t adc_values[LENGTH(adc_channels)];
|
||||||
for (uint8_t i = 0; i < LENGTH(channels); i++) {
|
for (uint8_t i = 0; i < LENGTH(adc_channels); i++) {
|
||||||
adc_start_conversion_regular(ADC1); // start conversion (using trigger)
|
adc_start_conversion_regular(ADC1); // start conversion (using trigger)
|
||||||
while (!adc_eoc(ADC1)); // wait until conversion finished
|
while (!adc_eoc(ADC1)); // wait until conversion finished
|
||||||
adc_values[i] = adc_read_regular(ADC1); // read voltage value (clears flag)
|
adc_values[i] = adc_read_regular(ADC1); // read voltage value (clears flag)
|
||||||
|
@ -854,7 +854,7 @@ void main(void)
|
||||||
adc_set_single_conversion_mode(ADC1); // ensure continuous mode is not used (that's not the same as discontinuous)
|
adc_set_single_conversion_mode(ADC1); // ensure continuous mode is not used (that's not the same as discontinuous)
|
||||||
adc_eoc_after_each(ADC1); // set EOC after each conversion instead of each group
|
adc_eoc_after_each(ADC1); // set EOC after each conversion instead of each group
|
||||||
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28CYC); // use at least 15 cycles to be able to sample at 12-bit resolution
|
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28CYC); // use at least 15 cycles to be able to sample at 12-bit resolution
|
||||||
adc_set_regular_sequence(ADC1, LENGTH(channels), (uint8_t*)channels); // set channel to convert
|
adc_set_regular_sequence(ADC1, LENGTH(adc_channels), (uint8_t*)adc_channels); // set channel to convert
|
||||||
adc_enable_temperature_sensor(); // enable internal voltage reference
|
adc_enable_temperature_sensor(); // enable internal voltage reference
|
||||||
adc_power_on(ADC1); // switch on ADC
|
adc_power_on(ADC1); // switch on ADC
|
||||||
sleep_us(3); // wait t_stab for the ADC to stabilize
|
sleep_us(3); // wait t_stab for the ADC to stabilize
|
||||||
|
|
Loading…
Reference in New Issue