Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ADE7912.h
00001 #ifndef ADE7912 00002 #define ADE7912 00003 00004 #include "stm32h7xx_hal.h" 00005 #include "stdlib.h" 00006 00007 // ADE7912 registers addresses 00008 #define ADE7912_IWV_REG_ADDRESS 0x00 00009 #define ADE7912_V1WV_REG_ADDRESS 0x08 00010 #define ADE7912_V2WV_REG_ADDRESS 0x10 00011 #define ADE7912_ADC_CRC_REG_ADDRESS 0x20 00012 #define ADE7912_CTRL_CRC_REG_ADDRESS 0x28 00013 #define ADE7912_CNT_SNAPSHOT_REG_ADDRESS 0x38 00014 #define ADE7912_CONFIG_REG_ADDRESS 0x40 00015 #define ADE7912_STATUS0_REG_ADDRESS 0x48 00016 #define ADE7912_LOCK_REG_ADDRESS 0x50 00017 #define ADE7912_SYNC_SNAP_REG_ADDRESS 0x58 00018 #define ADE7912_COUNTER0_REG_ADDRESS 0x60 00019 #define ADE7912_COUNTER1_REG_ADDRESS 0x68 00020 #define ADE7912_EMI_CTRL_REG_ADDRESS 0x70 00021 #define ADE7912_STATUS1_REG_ADDRESS 0x78 00022 #define ADE7912_TEMPOS_REG_ADDRESS 0xC0 00023 00024 // ADE7912 bits of CONFIG register 00025 #define ADE7912_CONFIG_BIT_CLKOUTENB 1 << 0 00026 #define ADE7912_CONFIG_BIT_PWRDWNENB 1 << 1 00027 #define ADE7912_CONFIG_BIT_TEMPENB 1 << 3 00028 #define ADE7912_CONFIG_ADC_FREQ_1K 0x0 << 4 00029 #define ADE7912_CONFIG_ADC_FREQ_2K 0x1 << 4 00030 #define ADE7912_CONFIG_ADC_FREQ_4K 0x2 << 4 00031 #define ADE7912_CONFIG_ADC_FREQ_8K 0x3 << 4 00032 #define ADE7912_CONFIG_ADC_FREQ ADE7912_CONFIG_ADC_FREQ_8K 00033 #define ADE7912_CONFIG_BIT_SWRST 1 << 6 00034 #define ADE7912_CONFIG_BIT_BW 1 << 6 00035 00036 // ADE7912 bits of STATUS0 register 00037 #define ADE7912_STATUS0_BIT_RESET_ON 1 << 0 00038 #define ADE7912_STATUS0_BIT_CRC_STAT 1 << 1 00039 #define ADE7912_STATUS0_BIT_IC_PROT 1 << 2 00040 00041 // ADE7912 bits of STATUS1 register 00042 #define ADE7912_STATUS1_BIT_VERSION 0x7 << 0 00043 #define ADE7912_STATUS1_BIT_ADC_NA 1 << 3 00044 00045 // ADE7912 transmite modes 00046 #define ADE7912_READ_MODE 0x04 00047 #define ADE7912_BRUSH_READ_MODE 0x04 00048 #define ADE7912_WRITE_MODE 0x00 00049 00050 #define ADE7912_DALAY_TIME 2 00051 #define ADE7912_WAITING_TIME 5 * ADE7912_DALAY_TIME 00052 00053 #define ADE7912_TEMPGAIN_WITH_3K3_BW 8.72101e-5f 00054 #define ADE7912_TEMPGAIN_WITH_2K_BW 8.21015e-5f 00055 #define ADE7912_CONST_TEMPOS 306.47f 00056 00057 #define ADE7912_IWV_TRANSLATE_COEF 5.87344e-9f 00058 #define ADE7912_VWV_TRANSLATE_COEF 9.39369e-8f 00059 00060 struct ADE7912_BrushRead_Data 00061 { 00062 int32_t IWV; 00063 int32_t V1WV; 00064 int32_t V2WV; 00065 uint16_t ADC_CRC; 00066 uint8_t STATUS0; 00067 uint16_t CNT_SNAPSHOT; 00068 }; 00069 00070 struct ADE7912_Inst 00071 { 00072 SPI_HandleTypeDef *spi; 00073 uint8_t phasesEnable[4]; 00074 GPIO_TypeDef *CS_ports[4]; 00075 uint16_t CS_pins[4]; 00076 struct ADE7912_BrushRead_Data *phasesData[4]; 00077 uint8_t version[4]; 00078 float tempos[4]; 00079 float tempGain[4]; 00080 GPIO_TypeDef *DReadyPort; 00081 uint16_t DReadyPin; 00082 IRQn_Type EXTIinterrupt; 00083 }; 00084 00085 00086 00087 enum ADE7912_Phases 00088 { 00089 PHASE_A = 0, 00090 PHASE_B, 00091 PHASE_C, 00092 COM 00093 }; 00094 00095 enum ADE7912_DataUpdateFreq 00096 { 00097 F_8KHZ, 00098 F_4KHZ, 00099 F_2KHZ, 00100 F_1KHZ 00101 }; 00102 00103 enum ADE7912_Bandwidths 00104 { 00105 BW_3K3HZ, 00106 BW_2KHZ 00107 }; 00108 00109 enum ADE7912_CLKOUT_Functionality 00110 { 00111 CLKOUT, 00112 DREADY 00113 }; 00114 00115 struct ADE7912_Phase_Settings 00116 { 00117 GPIO_TypeDef *CS_port; 00118 uint16_t CS_pin; 00119 enum ADE7912_DataUpdateFreq freq; 00120 enum ADE7912_Bandwidths bandwidth; 00121 enum ADE7912_CLKOUT_Functionality clkoutFunc; 00122 }; 00123 00124 00125 00126 void ADE7912_UpdateData(struct ADE7912_Inst *ade); 00127 00128 struct ADE7912_Inst* New_ADE7912(SPI_HandleTypeDef *spi); 00129 00130 void ADE7912_PhaseInit(struct ADE7912_Inst *ade, struct ADE7912_Phase_Settings *settings, enum ADE7912_Phases phase); 00131 void ADE7912_EnablePhase(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00132 void ADE7912_DisablePhase(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00133 void ADE7912_ResetPhase(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00134 00135 void ADE7912_SetDataUpdateFreq(struct ADE7912_Inst *ade, enum ADE7912_Phases phase, enum ADE7912_DataUpdateFreq freq); 00136 void ADE7912_SetPwrConverterEnabled(struct ADE7912_Inst *ade, enum ADE7912_Phases phase, bool enabled); 00137 void ADE7912_SetTempEnabled(struct ADE7912_Inst *ade, enum ADE7912_Phases phase, bool enabled); 00138 void ADE7912_SetBandwidth(struct ADE7912_Inst *ade, enum ADE7912_Phases phase, enum ADE7912_Bandwidths bandwidth); 00139 void ADE7912_SetCLKOUTFunctionality(struct ADE7912_Inst *ade, enum ADE7912_Phases phase, enum ADE7912_CLKOUT_Functionality functionality); 00140 00141 void ADE7912_LockConfigurationRegisters(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00142 void ADE7912_UnlockConfigurationRegisters(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00143 00144 uint8_t ADE7912_GetADCVersion(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00145 float ADE7912_GetVoltage(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00146 float ADE7912_GetCurrent(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00147 float ADE7912_GetTemp(struct ADE7912_Inst *ade, enum ADE7912_Phases phase); 00148 00149 #endif
Generated on Thu Jul 14 2022 00:56:52 by
1.7.2