@@ -592,7 +592,7 @@ ACS37800ERR ACS37800::readRMS(float *vRMS, float *iRMS)
592
592
}
593
593
594
594
// Read volatile register 0x21. Return the pactive and pimag.
595
- ACS37800ERR ACS37800::readRMSActiveReactive (float *pActive, float *pReactive)
595
+ ACS37800ERR ACS37800::readPowerActiveReactive (float *pActive, float *pReactive)
596
596
{
597
597
ACS37800_REGISTER_21_t store;
598
598
ACS37800ERR error = readRegister (&store.data .all , ACS37800_REGISTER_VOLATILE_21); // Read register 21
@@ -601,7 +601,7 @@ ACS37800ERR ACS37800::readRMSActiveReactive(float *pActive, float *pReactive)
601
601
{
602
602
if (_printDebug == true )
603
603
{
604
- _debugPort->print (F (" readRMSActiveReactive : readRegister (21) returned: " ));
604
+ _debugPort->print (F (" readPowerActiveReactive : readRegister (21) returned: " ));
605
605
_debugPort->println (error);
606
606
}
607
607
return (error); // Bail
@@ -628,9 +628,9 @@ ACS37800ERR ACS37800::readRMSActiveReactive(float *pActive, float *pReactive)
628
628
float power = (float )signedUnsigned.Signed ;
629
629
if (_printDebug == true )
630
630
{
631
- _debugPort->print (F (" readRMSActiveReactive : pactive: 0x" ));
631
+ _debugPort->print (F (" readPowerActiveReactive : pactive: 0x" ));
632
632
_debugPort->println (signedUnsigned.unSigned , HEX);
633
- _debugPort->print (F (" readRMSActiveReactive : pactive (LSB, before correction) is " ));
633
+ _debugPort->print (F (" readPowerActiveReactive : pactive (LSB, before correction) is " ));
634
634
_debugPort->println (power);
635
635
}
636
636
float LSBpermW = 3.08 ; // LSB per mW
@@ -643,12 +643,12 @@ ACS37800ERR ACS37800::readRMSActiveReactive(float *pActive, float *pReactive)
643
643
power /= 1000 ; // Convert from mW to W
644
644
if (_printDebug == true )
645
645
{
646
- _debugPort->print (F (" readRMSActiveReactive : pactive (W, after correction) is " ));
646
+ _debugPort->print (F (" readPowerActiveReactive : pactive (W, after correction) is " ));
647
647
_debugPort->println (power);
648
648
}
649
649
*pActive = power;
650
650
651
- // Extract pimag. Convert to Watts
651
+ // Extract pimag. Convert to VAR
652
652
// Note: datasheet says:
653
653
// "Reactive power output. This field is an unsigned 16-bit fixed
654
654
// point number with 16 fractional bits, where MaxPow = 0.704. To
@@ -661,9 +661,9 @@ ACS37800ERR ACS37800::readRMSActiveReactive(float *pActive, float *pReactive)
661
661
power = (float )store.data .bits .pimag ;
662
662
if (_printDebug == true )
663
663
{
664
- _debugPort->print (F (" readRMSActiveReactive : pimag: 0x" ));
664
+ _debugPort->print (F (" readPowerActiveReactive : pimag: 0x" ));
665
665
_debugPort->println (store.data .bits .pimag , HEX);
666
- _debugPort->print (F (" readRMSActiveReactive : pimag (LSB, before correction) is " ));
666
+ _debugPort->print (F (" readPowerActiveReactive : pimag (LSB, before correction) is " ));
667
667
_debugPort->println (power);
668
668
}
669
669
float LSBpermVAR = 6.15 ; // LSB per mVAR
@@ -675,14 +675,94 @@ ACS37800ERR ACS37800::readRMSActiveReactive(float *pActive, float *pReactive)
675
675
power /= 1000 ; // Convert from mVAR to VAR
676
676
if (_printDebug == true )
677
677
{
678
- _debugPort->print (F (" readRMSActiveReactive : pimag (VAR, after correction) is " ));
678
+ _debugPort->print (F (" readPowerActiveReactive : pimag (VAR, after correction) is " ));
679
679
_debugPort->println (power);
680
680
}
681
681
*pReactive = power;
682
682
683
683
return (error);
684
684
}
685
685
686
+ // Read volatile register 0x22. Return the apparent power, power factor, leading / lagging, generated / consumed
687
+ ACS37800ERR ACS37800::readPowerFactor (float *pApparent, float *pFactor, bool *posangle, bool *pospf)
688
+ {
689
+ ACS37800_REGISTER_22_t store;
690
+ ACS37800ERR error = readRegister (&store.data .all , ACS37800_REGISTER_VOLATILE_22); // Read register 22
691
+
692
+ if (error != ACS37800_SUCCESS)
693
+ {
694
+ if (_printDebug == true )
695
+ {
696
+ _debugPort->print (F (" readPowerFactor: readRegister (22) returned: " ));
697
+ _debugPort->println (error);
698
+ }
699
+ return (error); // Bail
700
+ }
701
+
702
+ // Extract papparent. Convert to VA
703
+ // Note: datasheet says:
704
+ // "Apparent power output magnitude. This field is an unsigned
705
+ // 16-bit fixed point number with 16 fractional bits, where MaxPow
706
+ // = 0.704. To convert the value (input power) to line power, divide
707
+ // the input power by the RSENSE and RISO voltage divider ratio
708
+ // using actual resistor values."
709
+ // Datasheet also says:
710
+ // "6.15 LSB/mVA for the 30A version and 2.05 LSB/mVA for the 90A version"
711
+
712
+ float power = (float )store.data .bits .papparent ;
713
+ if (_printDebug == true )
714
+ {
715
+ _debugPort->print (F (" readPowerFactor: papparent: 0x" ));
716
+ _debugPort->println (store.data .bits .papparent , HEX);
717
+ _debugPort->print (F (" readPowerFactor: papparent (LSB, before correction) is " ));
718
+ _debugPort->println (power);
719
+ }
720
+ float LSBpermVA = 6.15 ; // LSB per mVA
721
+ LSBpermVA *= 30.0 / _currentSensingRange; // Correct for sensor version
722
+ power /= LSBpermVA; // Convert from codes to mVA
723
+ // Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
724
+ // Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
725
+ float resistorMultiplier = (_dividerResistance + _senseResistance) / _senseResistance;
726
+ power *= resistorMultiplier;
727
+ power /= 1000 ; // Convert from mVAR to VAR
728
+ if (_printDebug == true )
729
+ {
730
+ _debugPort->print (F (" readPowerFactor: papparent (VA, after correction) is " ));
731
+ _debugPort->println (power);
732
+ }
733
+ *pApparent = power;
734
+
735
+ // Extract power factor
736
+ // Datasheet says:
737
+ // "Power factor output. This field is a signed 11-bit fixed point number
738
+ // with 10 fractional bits. It ranges from –1 to ~1 with a step
739
+ // size of 2^-10."
740
+
741
+ union
742
+ {
743
+ int16_t Signed;
744
+ uint16_t unSigned;
745
+ } signedUnsigned; // Avoid any ambiguity when casting to signed int
746
+
747
+ signedUnsigned.unSigned = store.data .bits .pfactor << 5 ; // Move 11-bit number into 16-bits (signed)
748
+
749
+ float pfactor = (float )signedUnsigned.Signed / 32768.0 ; // Convert to +/- 1
750
+ if (_printDebug == true )
751
+ {
752
+ _debugPort->print (F (" readPowerFactor: pfactor: 0x" ));
753
+ _debugPort->println (store.data .bits .pfactor , HEX);
754
+ _debugPort->print (F (" readPowerFactor: pfactor is " ));
755
+ _debugPort->println (pfactor);
756
+ }
757
+ *pFactor = pfactor;
758
+
759
+ // Extract posangle and pospf
760
+ *posangle = store.data .bits .posangle & 0x1 ;
761
+ *pospf = store.data .bits .pospf & 0x1 ;
762
+
763
+ return (error);
764
+ }
765
+
686
766
// Read volatile registers 0x2A and 0x2C. Return the vInst (Volts), iInst (Amps) and pInst (VAR).
687
767
ACS37800ERR ACS37800::readInstantaneous (float *vInst, float *iInst, float *pInst)
688
768
{
0 commit comments