Browse Source

px4io: return raw ADC value for current

we don't know how to scale it as we have no info on what sensor is
attached. As we are returning a uint16_t it is better to let the FMU
sort it out or we'll just lose precision.
sbg
Andrew Tridgell 12 years ago
parent
commit
44015d6915
  1. 4
      src/modules/px4iofirmware/protocol.h
  2. 16
      src/modules/px4iofirmware/registers.c

4
src/modules/px4iofirmware/protocol.h

@ -115,7 +115,7 @@ @@ -115,7 +115,7 @@
#define PX4IO_P_STATUS_ALARMS_PWM_ERROR (1 << 6) /* PWM configuration or output was bad */
#define PX4IO_P_STATUS_VBATT 4 /* battery voltage in mV */
#define PX4IO_P_STATUS_IBATT 5 /* battery current in cA */
#define PX4IO_P_STATUS_IBATT 5 /* battery current (raw ADC) */
/* array of post-mix actuator outputs, -10000..10000 */
#define PX4IO_PAGE_ACTUATORS 2 /* 0..CONFIG_ACTUATOR_COUNT-1 */
@ -155,8 +155,6 @@ @@ -155,8 +155,6 @@
#define PX4IO_P_SETUP_PWM_ALTRATE 4 /* 'high' PWM frame output rate in Hz */
#define PX4IO_P_SETUP_RELAYS 5 /* bitmask of relay/switch outputs, 0 = off, 1 = on */
#define PX4IO_P_SETUP_VBATT_SCALE 6 /* battery voltage correction factor (float) */
#define PX4IO_P_SETUP_IBATT_SCALE 7 /* battery current scaling factor (float) */
#define PX4IO_P_SETUP_IBATT_BIAS 8 /* battery current bias value */
#define PX4IO_P_SETUP_SET_DEBUG 9 /* debug level for IO board */
/* autopilot control values, -10000..10000 */

16
src/modules/px4iofirmware/registers.c

@ -138,8 +138,6 @@ volatile uint16_t r_page_setup[] = @@ -138,8 +138,6 @@ volatile uint16_t r_page_setup[] =
[PX4IO_P_SETUP_PWM_ALTRATE] = 200,
[PX4IO_P_SETUP_RELAYS] = 0,
[PX4IO_P_SETUP_VBATT_SCALE] = 10000,
[PX4IO_P_SETUP_IBATT_SCALE] = 0,
[PX4IO_P_SETUP_IBATT_BIAS] = 0,
[PX4IO_P_SETUP_SET_DEBUG] = 0,
};
@ -516,12 +514,14 @@ registers_get(uint8_t page, uint8_t offset, uint16_t **values, unsigned *num_val @@ -516,12 +514,14 @@ registers_get(uint8_t page, uint8_t offset, uint16_t **values, unsigned *num_val
/* PX4IO_P_STATUS_IBATT */
{
unsigned counts = adc_measure(ADC_VBATT);
unsigned scaled = (counts * r_page_setup[PX4IO_P_SETUP_IBATT_SCALE]) / 10000;
int corrected = scaled + REG_TO_SIGNED(r_page_setup[PX4IO_P_SETUP_IBATT_BIAS]);
if (corrected < 0)
corrected = 0;
r_page_status[PX4IO_P_STATUS_IBATT] = corrected;
/*
note that we have no idea what sort of
current sensor is attached, so we just
return the raw 12 bit ADC value and let the
FMU sort it out, with user selectable
configuration for their sensor
*/
r_page_status[PX4IO_P_STATUS_IBATT] = adc_measure(ADC_IN5);
}
SELECT_PAGE(r_page_status);

Loading…
Cancel
Save