ina3221: correct the update_interval value
Subsystems (2)
PATCH 1/1 ina3221: correct the update_interval value
As per the INA3221 datasheet the samples value should not be considered while calculating the update_interval value. Section 8.4.2.2 from datasheet says - "The conversion-time settings, along with the programmable-averaging mode, enable the INA3221 to optimize available timing requirements in a given application. For example, if a system requires data to be read every 2 ms with all three channels monitored, configure the INA3221 with the conversion times for the shunt- and bus-voltage measurements set to 332 μs"
As per above only conversion time and number of channels are required to set the update_interval value. Correcting the same in the driver.
--- Documentation/hwmon/ina3221.rst | 3 +-- drivers/hwmon/ina3221.c | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-)
Documentation/hwmon/ina3221.rst +1 -2
@@ -61,10 +61,9 @@ samples Number of samples using in the averaging mode. update_interval Data conversion time in millisecond, following: - update_interval = C x S x (BC + SC) + update_interval = C x (BC + SC) * C: number of enabled channels - * S: number of samples * BC: bus-voltage conversion time in millisecond * SC: shunt-voltage conversion time in millisecond
drivers/hwmon/ina3221.c +1 -3
@@ -183,11 +183,9 @@ static const int ina3221_avg_samples[] = {static inline u32 ina3221_interval_ms_to_conv_time (u16 config,int interval) {u32 channels =hweight16 (config & INA3221_CONFIG_CHs_EN_MASK); -u32 samples_idx =INA3221_CONFIG_AVG (config); -u32 samples = ina3221_avg_samples[samples_idx];/* Bisect the result to Bus and Shunt conversion times */ -return DIV_ROUND_CLOSEST (interval *1000 /2 , channels * samples); +return DIV_ROUND_CLOSEST (interval /2 , channels); }/* Converting CONFIG register value to update_interval in usec */
Signature · 1 line
2.17.1
Quoted 41 lines · Ninad Malwade
As per the INA3221 datasheet the samples value should not be considered while calculating the
update_intervalvalue. Section 8.4.2.2 from datasheet says - "The conversion-time settings, along with the programmable-averaging mode, enable the INA3221 to optimize available timing requirements in a given application. For example, if a system requires data to be read every 2 ms with all three channels monitored, configure the INA3221 with the conversion times for the shunt- and bus-voltage measurements set to 332 μs"As per above only conversion time and number of channels are required to set the
update_intervalvalue. Correcting the same in the driver.Signed-off-by Ninad Malwade <[email protected]>--- Documentation/hwmon/ina3221.rst | 3 +-- drivers/hwmon/ina3221.c | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-)Documentation/hwmon/ina3221.rst +1
-2@@ -61,10 +61,9 @@ samples Number of samples using in the averaging mode. update_interval Data conversion time in millisecond, following: - update_interval = C x S x (BC + SC) + update_interval = C x (BC + SC) * C: number of enabled channels - * S: number of samples * BC: bus-voltage conversion time in millisecond * SC: shunt-voltage conversion time in milliseconddrivers/hwmon/ina3221.c +0
-0
drivers/hwmon/ina3221.c static const int ina3221_avg_samples[] = { · line 188
Quoted 9 lines
drivers/hwmon/ina3221.c +1
-3@@ -183,11 +183,9 @@ static const int ina3221_avg_samples[] = {static inline u32 ina3221_interval_ms_to_conv_time (u16 config,int interval) {u32 channels =hweight16 (config & INA3221_CONFIG_CHs_EN_MASK); -u32 samples_idx =INA3221_CONFIG_AVG (config); -u32 samples = ina3221_avg_samples[samples_idx];/* Bisect the result to Bus and Shunt conversion times */ -return DIV_ROUND_CLOSEST (interval *1000 /2 , channels * samples); +return DIV_ROUND_CLOSEST (interval /2 , channels);
Why do you drop the * 1000 multiplication factor? That seems to be there to account for the input "interval" being specified in ms whereas the values in ina3221_conv_time[] are in us. Isn't this new code going to give us values that are in the wrong unit?
Thierry
Guenter Roeck
maintainerQuoted 10 lines · Ninad Malwade
As per the INA3221 datasheet the samples value should not be considered while calculating the
update_intervalvalue. Section 8.4.2.2 from datasheet says - "The conversion-time settings, along with the programmable-averaging mode, enable the INA3221 to optimize available timing requirements in a given application. For example, if a system requires data to be read every 2 ms with all three channels monitored, configure the INA3221 with the conversion times for the shunt- and bus-voltage measurements set to 332 μs"
Quoted 5 lines
As per above only conversion time and number of channels are required to set the
update_intervalvalue. Correcting the same in the driver.Signed-off-by Ninad Malwade <[email protected]>
As a bug fix, this patch should come before any functional changes.
Quoted 26 lines
--- Documentation/hwmon/ina3221.rst | 3 +-- drivers/hwmon/ina3221.c | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-)Documentation/hwmon/ina3221.rst +1
-2@@ -61,10 +61,9 @@ samples Number of samples using in the averaging mode. update_interval Data conversion time in millisecond, following: - update_interval = C x S x (BC + SC) + update_interval = C x (BC + SC) * C: number of enabled channels - * S: number of samples * BC: bus-voltage conversion time in millisecond * SC: shunt-voltage conversion time in milliseconddrivers/hwmon/ina3221.c +0
-0
drivers/hwmon/ina3221.c static const int ina3221_avg_samples[] = { · line 188
Quoted 9 lines
drivers/hwmon/ina3221.c +1
-3@@ -183,11 +183,9 @@ static const int ina3221_avg_samples[] = {static inline u32 ina3221_interval_ms_to_conv_time (u16 config,int interval) {u32 channels =hweight16 (config & INA3221_CONFIG_CHs_EN_MASK); -u32 samples_idx =INA3221_CONFIG_AVG (config); -u32 samples = ina3221_avg_samples[samples_idx];/* Bisect the result to Bus and Shunt conversion times */ -return DIV_ROUND_CLOSEST (interval *1000 /2 , channels * samples); +return DIV_ROUND_CLOSEST (interval /2 , channels);
Same question as Thierry: Why drop the multiplication ?
Guenter
Quoted 3 lines
drivers/hwmon/ina3221.c +0
-0}/* Converting CONFIG register value to update_interval in usec */