Skip to content

Commit

Permalink
DRIVERS: AD7193: AD7193_ConvertToVolts() returns now milivolts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbogdan committed Jul 11, 2013
1 parent 51553e8 commit f03d8f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Renesas/RL78G14/PmodAD5/PmodAD5.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ void main(void)

while(1)
{
/* Select unipolar operation and ADC's input range to +-2.5V. */
AD7193_RangeSetup(1, AD7193_CONF_GAIN_1);
/* Select bipolar operation and ADC's input range to +-2.5V. */
AD7193_RangeSetup(0, AD7193_CONF_GAIN_1);

/* Select channel AIN1(+) - AIN2(-).*/
AD7193_ChannelSelect(AD7193_CH_0);
Expand All @@ -135,20 +135,20 @@ void main(void)
result = AD7193_SingleConversion();
ST7579_String(2, 0, "CHANNEL 0:", 0);
ST7579_String(3, 0, "RAW: ", 0);
ST7579_String(4, 0, "1RD: [V]", 0);
ST7579_String(4, 0, "1RD: [mV]", 0);
ST7579_HexNumber(3, 30, result, 0);

/* The value of the voltage reference on PmodAD5 is 2.5V by default. */
voltage = AD7193_ConvertToVolts(result, 2.5);
ST7579_FloatNumber(4, 30, voltage, 3, 0);
ST7579_FloatNumber(4, 24, voltage, 2, 0);

/* Continuous reads. */
result = AD7193_ContinuousReadAvg(10);
voltage = AD7193_ConvertToVolts(result, 2.5);
ST7579_String(5, 0, "RAW: ", 0);
ST7579_String(6, 0, "AVG: [V]", 0);
ST7579_String(6, 0, "AVG: [mV]", 0);
ST7579_HexNumber(5, 30, result, 0);
ST7579_FloatNumber(6, 30, voltage, 3, 0);
ST7579_FloatNumber(6, 24, voltage, 2, 0);

/* Read the temperature. */
degreesC = AD7193_TemperatureRead();
Expand Down
6 changes: 3 additions & 3 deletions drivers/AD7193/AD7193.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ float AD7193_TemperatureRead(void)
}

/***************************************************************************//**
* @brief Converts 24-bit raw data to volts.
* @brief Converts 24-bit raw data to milivolts.
*
* @param rawData - 24-bit data sample.
* @param vRef - The value of the voltage reference used by the device.
Expand All @@ -343,11 +343,11 @@ float AD7193_ConvertToVolts(unsigned long rawData, float vRef)

if(currentPolarity == 0 ) // Bipolar mode
{
voltage = (((float)rawData / (1ul << 23)) - 1) * vRef / currentGain;
voltage = 1000 * (((float)rawData / (1ul << 23)) - 1) * vRef / currentGain;
}
else // Unipolar mode
{
voltage = ((float)rawData * vRef) / (1ul << 24) / currentGain;
voltage = 1000 * ((float)rawData * vRef) / (1ul << 24) / currentGain;
}

return voltage;
Expand Down

0 comments on commit f03d8f0

Please sign in to comment.