Open nordic-piks opened 3 days ago
@wkhadgar Please have a look on that.
Please have a look on that.
Greatly noticed, will take on look on that and make the refered fixes!
@nordic-piks I would argue that moving the rogue values of adc_dt_spec
like resolution
and vref_mv
to adc_channel_cfg
would be a good move, but the implications are at large scale, so not sure if it's the best choice here. As of now, fixed the issue by creating an auxiliary array of vrefs, since it's an exclusively local change and easier to maintain.
@anangl @decsny What are your thoughts on this?
@nordic-piks I would argue that moving the rogue values of
adc_dt_spec
likeresolution
andvref_mv
toadc_channel_cfg
would be a good move, but the implications are at large scale, so not sure if it's the best choice here. As of now, fixed the issue by creating an auxiliary array of vrefs, since it's an exclusively local change and easier to maintain.
I like your choice! Already tested with HW (with internal ref), working fine.
Describe the bug
Looking at: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/drivers/adc/adc_sequence/src/main.c#L85C11-L85C32
Function
adc_raw_to_millivolts
is used with value which is a enum (passed as a first argument)channel_cfgs[channel_index].reference
https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/adc.h#L95With values:
https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/adc.h#L77
However
adc_raw_to_millivolts
expects as a first arguments millivolts value:https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/adc.h#L878
Which lead to incorrect conversion from adc readings into millivolts for this sample.
Expected behavior Possible solution would be to obtain correct reference value as in
adc_raw_to_millivolts_dt
: https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/adc.h#L916C1-L920C3however, with this approach only ADC_REF_INTERNAL can be handled easily. Other values, especially external reference are handled in adc_dt with
vref_mv
definition, but such is missing atadc_channel_cfg
.Impact Local, only this sample is affected.
Environment (please complete the following information):