@@ -476,3 +476,82 @@ def set_calibration_16V_400mA(self): # pylint: disable=invalid-name
476
476
self .bus_adc_resolution = ADCResolution .ADCRES_12BIT_1S
477
477
self .shunt_adc_resolution = ADCResolution .ADCRES_12BIT_1S
478
478
self .mode = Mode .SANDBVOLT_CONTINUOUS
479
+
480
+ def set_calibration_16V_5A (self ):
481
+ # Calibration which uses the highest precision for
482
+ # current measurement (0.1mA), at the expense of
483
+ # only supporting 16V at 5000mA max.
484
+
485
+ # VBUS_MAX = 16V
486
+ # VSHUNT_MAX = 0.08 (Assumes Gain 2, 80mV)
487
+ # RSHUNT = 0.02 (Resistor value in ohms)
488
+
489
+ # 1. Determine max possible current
490
+ # MaxPossible_I = VSHUNT_MAX / RSHUNT
491
+ # MaxPossible_I = 4.0A
492
+
493
+ # 2. Determine max expected current
494
+ # MaxExpected_I = 5.0A
495
+
496
+ # 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
497
+ # MinimumLSB = MaxExpected_I/32767
498
+ # MinimumLSB = 0.0001529 (uA per bit)
499
+ # MaximumLSB = MaxExpected_I/4096
500
+ # MaximumLSB = 0.0012207 (uA per bit)
501
+
502
+ # 4. Choose an LSB between the min and max values
503
+ # (Preferrably a roundish number close to MinLSB)
504
+ # CurrentLSB = 0.00016 (50uA per bit)
505
+ self ._current_lsb = 0.1524 # in milliamps
506
+
507
+ # 5. Compute the calibration register
508
+ # Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
509
+ # Cal = 26869 (0x68f5)
510
+
511
+ self ._cal_value = 26869
512
+
513
+ # 6. Calculate the power LSB
514
+ # PowerLSB = 20 * CurrentLSB
515
+ # PowerLSB = 0.001 (1mW per bit)
516
+ self ._power_lsb = 0.003048
517
+
518
+ # 7. Compute the maximum current and shunt voltage values before overflow
519
+ #
520
+ # Max_Current = Current_LSB * 32767
521
+ # Max_Current = 1.63835A before overflow
522
+ #
523
+ # If Max_Current > Max_Possible_I then
524
+ # Max_Current_Before_Overflow = MaxPossible_I
525
+ # Else
526
+ # Max_Current_Before_Overflow = Max_Current
527
+ # End If
528
+ #
529
+ # Max_Current_Before_Overflow = MaxPossible_I
530
+ # Max_Current_Before_Overflow = 0.4
531
+ #
532
+ # Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
533
+ # Max_ShuntVoltage = 0.04V
534
+ #
535
+ # If Max_ShuntVoltage >= VSHUNT_MAX
536
+ # Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
537
+ # Else
538
+ # Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
539
+ # End If
540
+ #
541
+ # Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
542
+ # Max_ShuntVoltage_Before_Overflow = 0.04V
543
+
544
+ # 8. Compute the Maximum Power
545
+ # MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
546
+ # MaximumPower = 0.4 * 16V
547
+ # MaximumPower = 6.4W
548
+
549
+ # Set Calibration register to 'Cal' calcutated above
550
+ self ._raw_calibration = self ._cal_value
551
+
552
+ # Set Config register to take into account the settings above
553
+ self .bus_voltage_range = BusVoltageRange .RANGE_16V
554
+ self .gain = Gain .DIV_2_80MV
555
+ self .bus_adc_resolution = ADCResolution .ADCRES_12BIT_1S
556
+ self .shunt_adc_resolution = ADCResolution .ADCRES_12BIT_1S
557
+ self .mode = Mode .SANDBVOLT_CONTINUOUS
0 commit comments