ADC driver report back vref alone with sample count (#14136)

* Introduce "px4_arch_adc_reference_v"

* Revert "Introduce "px4_arch_adc_reference_v""

This reverts commit 93691fbbd55a1b8da8c190e225b318067d90399b.

* use structure to return sample count and vref at the same time

* Revert "use structure to return sample count and vref at the same time"

This reverts commit 9cfd1c173cda51495f766a3f678c2202d67725fd.

* Revert "Revert "Introduce "px4_arch_adc_reference_v"""

This reverts commit edb7f7603e4471163ffb0fc6fc62ad2e30336e91.

* fix missed reference

* remove unecessary channel specific vref

* Update src/drivers/drv_adc.h

Co-Authored-By: David Sidrane <David.Sidrane@Nscdg.com>

* Update src/drivers/drv_adc.h

Co-Authored-By: David Sidrane <David.Sidrane@Nscdg.com>

* Introduce BOARD_ADC_POS_REF_V

Co-authored-by: David Sidrane <David.Sidrane@Nscdg.com>
This commit is contained in:
SalimTerryLi 2020-02-21 22:52:46 +08:00 committed by GitHub
parent e0d6f94318
commit 77a9135036
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 54 additions and 1 deletions

View File

@ -92,6 +92,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return atoi(buffer); return atoi(buffer);
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V;
}
uint32_t px4_arch_adc_dn_fullcount() uint32_t px4_arch_adc_dn_fullcount()
{ {
return 1 << 12; // 12 bit ADC return 1 << 12; // 12 bit ADC

View File

@ -92,6 +92,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return atoi(buffer); return atoi(buffer);
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V; // 12-bit 1.8V ADC
}
uint32_t px4_arch_adc_dn_fullcount() uint32_t px4_arch_adc_dn_fullcount()
{ {
return 1 << 12; // 12 bit ADC return 1 << 12; // 12 bit ADC

View File

@ -61,6 +61,7 @@
// ADC channels: // ADC channels:
#define ADC_CHANNELS (1 << 5) #define ADC_CHANNELS (1 << 5)
#define BOARD_ADC_POS_REF_V (1.8f)
#define ADC_BATTERY_VOLTAGE_CHANNEL 5 #define ADC_BATTERY_VOLTAGE_CHANNEL 5
#define ADC_BATTERY_CURRENT_CHANNEL ((uint8_t)(-1)) #define ADC_BATTERY_CURRENT_CHANNEL ((uint8_t)(-1))

View File

@ -92,6 +92,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return atoi(buffer); return atoi(buffer);
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V;
}
uint32_t px4_arch_adc_dn_fullcount() uint32_t px4_arch_adc_dn_fullcount()
{ {
return 1 << 12; // 12 bit ADC return 1 << 12; // 12 bit ADC

View File

@ -73,6 +73,7 @@
// A4 - ADC2 (ADC port) // A4 - ADC2 (ADC port)
// A5 - ADC3 (ADC port) // A5 - ADC3 (ADC port)
#define ADC_CHANNELS (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) #define ADC_CHANNELS (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5)
#define BOARD_ADC_POS_REF_V (4.096f) // TODO: need confirmation
#define ADC_BATTERY_VOLTAGE_CHANNEL 2 #define ADC_BATTERY_VOLTAGE_CHANNEL 2
#define ADC_BATTERY_CURRENT_CHANNEL 3 #define ADC_BATTERY_CURRENT_CHANNEL 3

View File

@ -147,6 +147,10 @@
#define ADC_3V3_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb #define ADC_3V3_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
#endif #endif
#ifndef BOARD_ADC_POS_REF_V
#define BOARD_ADC_POS_REF_V (3.3f) // Default reference voltage for every channels
#endif
#ifndef BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN #ifndef BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN
#define BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN (3.3f) // Reference voltage for reading out the current channel #define BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN (3.3f) // Reference voltage for reading out the current channel
#endif #endif

View File

@ -186,6 +186,12 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
result = rR0(base_address); result = rR0(base_address);
return result; return result;
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V; // TODO: provide true vref
}
uint32_t px4_arch_adc_temp_sensor_mask() uint32_t px4_arch_adc_temp_sensor_mask()
{ {
return 0; return 0;

View File

@ -176,6 +176,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return result; return result;
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V; // TODO: provide true vref
}
uint32_t px4_arch_adc_temp_sensor_mask() uint32_t px4_arch_adc_temp_sensor_mask()
{ {
return 1 << (ADC_SC1_ADCH_TEMP >> ADC_SC1_ADCH_SHIFT); return 1 << (ADC_SC1_ADCH_TEMP >> ADC_SC1_ADCH_SHIFT);

View File

@ -179,6 +179,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return result; return result;
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V; // TODO: provide true vref
}
uint32_t px4_arch_adc_temp_sensor_mask() uint32_t px4_arch_adc_temp_sensor_mask()
{ {
return 1 << (ADC_SC1_ADCH_TEMP >> ADC_SC1_ADCH_SHIFT); return 1 << (ADC_SC1_ADCH_TEMP >> ADC_SC1_ADCH_SHIFT);

View File

@ -224,6 +224,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return result; return result;
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V; // TODO: provide true vref
}
uint32_t px4_arch_adc_temp_sensor_mask() uint32_t px4_arch_adc_temp_sensor_mask()
{ {
return 1 << 16; return 1 << 16;

View File

@ -304,6 +304,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return result; return result;
} }
float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V; // TODO: provide true vref
}
uint32_t px4_arch_adc_temp_sensor_mask() uint32_t px4_arch_adc_temp_sensor_mask()
{ {
return 1 << 16; return 1 << 16;

View File

@ -82,6 +82,13 @@ void px4_arch_adc_uninit(uint32_t base_address);
*/ */
uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel); uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel);
/**
* Get the ADC positive reference voltage
* N.B This assume that all ADC channels share the same vref.
* @return v_ref
*/
float px4_arch_adc_reference_v(void);
/** /**
* Get the temperature sensor channel bitmask * Get the temperature sensor channel bitmask
*/ */
@ -93,4 +100,3 @@ uint32_t px4_arch_adc_temp_sensor_mask(void);
uint32_t px4_arch_adc_dn_fullcount(void); uint32_t px4_arch_adc_dn_fullcount(void);
__END_DECLS __END_DECLS