Skip to content

Commit 5f5a534

Browse files
JordanYatesfabiobaltieri
authored andcommitted
tests: adc: adc_rescale: test adc_raw_to_microvolts_dt
Test that the output of `adc_raw_to_microvolts_dt` matches the output of `adc_raw_to_millivolts_dt` to the resolution of the latter. Signed-off-by: Jordan Yates <[email protected]>
1 parent c0ca636 commit 5f5a534

File tree

1 file changed

+18
-0
lines changed
  • tests/drivers/adc/adc_rescale/src

1 file changed

+18
-0
lines changed

tests/drivers/adc/adc_rescale/src/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static int test_task_voltage_divider(void)
5757
{
5858
int ret;
5959
int32_t calculated_voltage = 0;
60+
int32_t calculated_microvolts;
6061
int32_t input_mv = 1000;
6162
const struct voltage_divider_dt_spec adc_node_0 =
6263
VOLTAGE_DIVIDER_DT_SPEC_GET(ADC_TEST_NODE_0);
@@ -72,10 +73,15 @@ static int test_task_voltage_divider(void)
7273

7374
ret = adc_read_dt(&adc_node_0.port, &sequence);
7475
zassert_equal(ret, 0, "adc_read() failed with code %d", ret);
76+
calculated_microvolts = calculated_voltage;
7577

7678
ret = adc_raw_to_millivolts_dt(&adc_node_0.port, &calculated_voltage);
7779
zassert_equal(ret, 0, "adc_raw_to_millivolts_dt() failed with code %d", ret);
7880

81+
ret = adc_raw_to_microvolts_dt(&adc_node_0.port, &calculated_microvolts);
82+
zassert_equal(ret, 0, "adc_raw_to_microvolts_dt() failed with code %d", ret);
83+
zassert_equal(calculated_microvolts / 1000, calculated_voltage);
84+
7985
ret = voltage_divider_scale_dt(&adc_node_0, &calculated_voltage);
8086
zassert_equal(ret, 0, "divider_scale_voltage_dt() failed with code %d", ret);
8187

@@ -97,6 +103,7 @@ static int test_task_current_sense_shunt(void)
97103
{
98104
int ret;
99105
int32_t calculated_current = 0;
106+
int32_t calculated_microvolts;
100107
int32_t input_mv = 3000;
101108
const struct current_sense_shunt_dt_spec adc_node_1 =
102109
CURRENT_SENSE_SHUNT_DT_SPEC_GET(ADC_TEST_NODE_1);
@@ -112,10 +119,15 @@ static int test_task_current_sense_shunt(void)
112119

113120
ret = adc_read_dt(&adc_node_1.port, &sequence);
114121
zassert_equal(ret, 0, "adc_read() failed with code %d", ret);
122+
calculated_microvolts = calculated_current;
115123

116124
ret = adc_raw_to_millivolts_dt(&adc_node_1.port, &calculated_current);
117125
zassert_equal(ret, 0, "adc_raw_to_millivolts_dt() failed with code %d", ret);
118126

127+
ret = adc_raw_to_microvolts_dt(&adc_node_1.port, &calculated_microvolts);
128+
zassert_equal(ret, 0, "adc_raw_to_microvolts_dt() failed with code %d", ret);
129+
zassert_equal(calculated_microvolts / 1000, calculated_current);
130+
119131
current_sense_shunt_scale_dt(&adc_node_1, &calculated_current);
120132

121133
zassert_within(calculated_current, input_mv * 2, MV_OUTPUT_EPS,
@@ -137,6 +149,7 @@ static int test_task_current_sense_amplifier(void)
137149
{
138150
int ret;
139151
int32_t calculated_current = 0;
152+
int32_t calculated_microvolts;
140153
int32_t input_mv = 3000;
141154
const struct current_sense_amplifier_dt_spec adc_node_2 =
142155
CURRENT_SENSE_AMPLIFIER_DT_SPEC_GET(ADC_TEST_NODE_2);
@@ -152,10 +165,15 @@ static int test_task_current_sense_amplifier(void)
152165

153166
ret = adc_read_dt(&adc_node_2.port, &sequence);
154167
zassert_equal(ret, 0, "adc_read() failed with code %d", ret);
168+
calculated_microvolts = calculated_current;
155169

156170
ret = adc_raw_to_millivolts_dt(&adc_node_2.port, &calculated_current);
157171
zassert_equal(ret, 0, "adc_raw_to_millivolts_dt() failed with code %d", ret);
158172

173+
ret = adc_raw_to_microvolts_dt(&adc_node_2.port, &calculated_microvolts);
174+
zassert_equal(ret, 0, "adc_raw_to_microvolts_dt() failed with code %d", ret);
175+
zassert_equal(calculated_microvolts / 1000, calculated_current);
176+
159177
current_sense_amplifier_scale_dt(&adc_node_2, &calculated_current);
160178

161179
zassert_within(calculated_current, input_mv * 2, MV_OUTPUT_EPS,

0 commit comments

Comments
 (0)