Skip to content

Commit

Permalink
ADC driver report back vref alone with sample count (#14136)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update src/drivers/drv_adc.h

Co-Authored-By: David Sidrane <[email protected]>

* Introduce BOARD_ADC_POS_REF_V

Co-authored-by: David Sidrane <[email protected]>
  • Loading branch information
SalimTerryLi and davids5 authored Feb 21, 2020
1 parent e0d6f94 commit 77a9135
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions boards/aerotenna/ocpoc/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return atoi(buffer);
}

float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V;
}

uint32_t px4_arch_adc_dn_fullcount()
{
return 1 << 12; // 12 bit ADC
Expand Down
5 changes: 5 additions & 0 deletions boards/beaglebone/blue/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
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()
{
return 1 << 12; // 12 bit ADC
Expand Down
1 change: 1 addition & 0 deletions boards/beaglebone/blue/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

// ADC channels:
#define ADC_CHANNELS (1 << 5)
#define BOARD_ADC_POS_REF_V (1.8f)

#define ADC_BATTERY_VOLTAGE_CHANNEL 5
#define ADC_BATTERY_CURRENT_CHANNEL ((uint8_t)(-1))
Expand Down
5 changes: 5 additions & 0 deletions boards/emlid/navio2/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
return atoi(buffer);
}

float px4_arch_adc_reference_v()
{
return BOARD_ADC_POS_REF_V;
}

uint32_t px4_arch_adc_dn_fullcount()
{
return 1 << 12; // 12 bit ADC
Expand Down
1 change: 1 addition & 0 deletions boards/emlid/navio2/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
// A4 - ADC2 (ADC port)
// A5 - ADC3 (ADC port)
#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_CURRENT_CHANNEL 3
Expand Down
4 changes: 4 additions & 0 deletions platforms/common/include/px4_platform_common/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
#define ADC_3V3_SCALE (2.0f) // The scale factor defined by HW's resistive divider (Rt+Rb)/ Rb
#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
#define BOARD_ADC_POS_REF_V_FOR_CURRENT_CHAN (3.3f) // Reference voltage for reading out the current channel
#endif
Expand Down
6 changes: 6 additions & 0 deletions platforms/nuttx/src/px4/nxp/imxrt/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
result = rR0(base_address);
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()
{
return 0;
Expand Down
5 changes: 5 additions & 0 deletions platforms/nuttx/src/px4/nxp/kinetis/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
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()
{
return 1 << (ADC_SC1_ADCH_TEMP >> ADC_SC1_ADCH_SHIFT);
Expand Down
5 changes: 5 additions & 0 deletions platforms/nuttx/src/px4/nxp/s32k1xx/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
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()
{
return 1 << (ADC_SC1_ADCH_TEMP >> ADC_SC1_ADCH_SHIFT);
Expand Down
5 changes: 5 additions & 0 deletions platforms/nuttx/src/px4/stm/stm32_common/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
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()
{
return 1 << 16;
Expand Down
5 changes: 5 additions & 0 deletions platforms/nuttx/src/px4/stm/stm32h7/adc/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
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()
{
return 1 << 16;
Expand Down
8 changes: 7 additions & 1 deletion src/drivers/drv_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
* 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
*/
Expand All @@ -93,4 +100,3 @@ uint32_t px4_arch_adc_temp_sensor_mask(void);
uint32_t px4_arch_adc_dn_fullcount(void);

__END_DECLS

0 comments on commit 77a9135

Please sign in to comment.