| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #ifndef HLW8110_H
- #define HLW8110_H
- #include <stdint.h>
- #define CONST_2_23 8388608
- #define CONST_2_22 4194304
- #define CONST_2_31 2147483648
- #define CONST_F 3579545
- #define HLW_REG_SYSCON 0x00
- #define HLW_REG_EMUCON 0x01
- #define HLW_REG_EMUCON2 0x13
- #define HLW_REG_HFConst 0x02
- #define HLW_REG_PstartPA 0x03
- #define HLW_REG_PstartPB 0x60
- #define HLW_REG_PAGain 0x05
- #define HLW_REG_PBGain 0x06
- #define HLW_REG_PSGain 0x11
- #define HLW_REG_PhaseA 0x07
- #define HLW_REG_PhaseB 0x08
- #define HLW_REG_PAOS 0x0a
- #define HLW_REG_PBOS 0x0b
- #define HLW_REG_PSOS 0x12
- #define HLW_REG_RmsIAOS 0x0e
- #define HLW_REG_RmsIBOS 0x0f
- #define HLW_REG_IBGain 0x10
- #define HLW_REG_DCIA 0x14
- #define HLW_REG_DCIB 0x15
- #define HLW_REG_DCU 0x16
- #define HLW_REG_SAGCYC 0x17
- #define HLW_REG_SYSLVL 0x18
- #define HLW_REG_OVLVL 0x19
- #define HLW_REG_OIALVL 0x1a
- #define HLW_REG_OIBLVL 0x1b
- #define HLW_REG_OPLVL 0x1c
- #define HLW_REG_PFCnt_PA 0x20
- #define HLW_REG_PFCnt_PB 0x21
- #define HLW_REG_Angle 0x22
- #define HLW_REG_Ufreq 0x23
- #define HLW_REG_RmsIA 0x24
- #define HLW_REG_RmsIB 0x25
- #define HLW_REG_RmsU 0x26
- #define HLW_REG_PF 0x27
- #define HLW_REG_E_PA 0x28
- #define HLW_REG_E_PB 0x29
- #define HLW_REG_PowerA 0x2c
- #define HLW_REG_PowerB 0x2d
- #define HLW_REG_PowerS 0x2e
- #define HLW_REG_EMUStatus 0x2f
- #define HLW_REG_PeakIA 0x30
- #define HLW_REG_PeakIB 0x31
- #define HLW_REG_PeakU 0x32
- #define HLW_REG_InstanIA 0x33
- #define HLW_REG_InstanIB 0x34
- #define HLW_REG_InstanU 0x35
- #define HLW_REG_InstanP 0x3c
- #define HLW_REG_InstanS 0x3d
- #define HLW_REG_WaveIA 0x36
- #define HLW_REG_WaveIB 0x37
- #define HLW_REG_WaveU 0x38
- #define HLW_REG_IE 0x40
- #define HLW_REG_IF 0x41
- #define HLW_REG_RIF 0x42
- #define HLW_REG_SysStatus 0x43
- #define HLW_REG_RmsIAC 0x70
- #define HLW_REG_RmsIBC 0x71
- #define HLW_REG_RmsUC 0x72
- #define HLW_REG_PowerPAC 0x73
- #define HLW_REG_PowerPBC 0x74
- #define HLW_REG_PowerSC 0x75
- #define HLW_REG_EnergyAC 0x76
- #define HLW_REG_EnergyBC 0x77
- typedef struct _HLW
- {
- uint16_t u;
- uint16_t i;
- uint16_t pf;
- uint16_t f;
- uint16_t c;
- int32_t RMSU;
- uint16_t RMSUC;
- int32_t RMSIA;
- uint16_t RMSIAC;
- int32_t RMSIB;
- uint16_t RMSIBC;
- uint16_t UF;
- uint32_t t_v1;
- uint32_t t_v2;
- uint32_t t_i1;
- uint32_t t_i2;
- uint32_t t_f;
- uint32_t t_p;
- uint32_t t_pf;
- uint32_t t_c;
- int32_t RMSU_v1;
- int32_t RMSIA_i1;
-
- float KU;
- uint16_t DU;
- float KIA;
- uint16_t DIA;
- float KF;
-
- } HLW;
- typedef void (*HLW8110_TRANS_FUN)(uint8_t *, uint32_t);
- void hlw8110_set_trans_fun(HLW8110_TRANS_FUN fun);
- void hlw8110_read(uint8_t reg);
- void hlw8110_write(uint8_t reg, uint8_t *data, uint8_t len);
- void hlw8110_enable_write();
- void hlw8110_disable_write();
- void hlw8110_set_channel_A();
- void hlw8110_set_channel_B();
- void hlw8110_reset();
- void hlw8110_ac_config();
- uint8_t hlw8110_unpack_UF(HLW *hlw, uint8_t *data, uint32_t len);
- uint8_t hlw8110_unpack_RMSU(HLW *hlw, uint8_t *data, uint32_t len);
- uint8_t hlw8110_unpack_RMSUC(HLW *hlw, uint8_t *data, uint32_t len);
- uint8_t hlw8110_unpack_RMSIA(HLW *hlw, uint8_t *data, uint32_t len);
- uint8_t hlw8110_unpack_RMSIAC(HLW *hlw, uint8_t *data, uint32_t len);
- uint8_t hlw8110_unpack_RMSIB(HLW *hlw, uint8_t *data, uint32_t len);
- uint8_t hlw8110_unpack_RMSIBC(HLW *hlw, uint8_t *data, uint32_t len);
- void hlw8110_read_UF();
- void hlw8110_read_RMSU();
- void hlw8110_read_RMSUC();
- void hlw8110_read_RMSIA();
- void hlw8110_read_RMSIAC();
- void hlw8110_read_RMSIB();
- void hlw8110_read_RMSIBC();
- void hlw8110_cal(HLW *hlw);
- void hlw8110_cal_v1(HLW *hlw, uint32_t t);
- void hlw8110_cal_v2(HLW *hlw, uint32_t t);
- void hlw8110_cal_i1(HLW *hlw, uint32_t t);
- void hlw8110_cal_i2(HLW *hlw, uint32_t t);
- void hlw8110_cal_f(HLW *hlw, uint32_t t);
- #endif
|