Manuel Caballero / LEM-HAIS
Committer:
mcm
Date:
Wed Sep 20 11:40:27 2017 +0000
Revision:
2:c865023c4b20
Parent:
1:3766b24dab80
Child:
3:6bc9b8543f13
The library was completed and tested, it works as expected.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 1:3766b24dab80 1 /**
mcm 1:3766b24dab80 2 * @brief LEM_HAIS.h
mcm 1:3766b24dab80 3 * @details Current transducer. For the electronic measurement of currents:
mcm 1:3766b24dab80 4 * DC, AC, pulsed..., with galvanic separation between the primary
mcm 1:3766b24dab80 5 * circuit and the secondary circuit.
mcm 1:3766b24dab80 6 * Function file.
mcm 1:3766b24dab80 7 *
mcm 1:3766b24dab80 8 *
mcm 1:3766b24dab80 9 * @return NA
mcm 1:3766b24dab80 10 *
mcm 1:3766b24dab80 11 * @author Manuel Caballero
mcm 1:3766b24dab80 12 * @date 19/September/2017
mcm 1:3766b24dab80 13 * @version 19/September/2017 The ORIGIN
mcm 1:3766b24dab80 14 * @pre NaN.
mcm 1:3766b24dab80 15 * @warning NaN
mcm 1:3766b24dab80 16 * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ).
mcm 1:3766b24dab80 17 */
mcm 1:3766b24dab80 18
mcm 1:3766b24dab80 19 #include "LEM_HAIS.h"
mcm 1:3766b24dab80 20
mcm 1:3766b24dab80 21
mcm 2:c865023c4b20 22 LEM_HAIS::LEM_HAIS ( PinName OUTPUT )
mcm 1:3766b24dab80 23 : _OUTPUT ( OUTPUT )
mcm 1:3766b24dab80 24 {
mcm 2:c865023c4b20 25 _LEM_HAIS_V_OFFSET = 0.0;
mcm 1:3766b24dab80 26 }
mcm 1:3766b24dab80 27
mcm 1:3766b24dab80 28
mcm 1:3766b24dab80 29 LEM_HAIS::~LEM_HAIS()
mcm 1:3766b24dab80 30 {
mcm 1:3766b24dab80 31 }
mcm 1:3766b24dab80 32
mcm 1:3766b24dab80 33
mcm 1:3766b24dab80 34
mcm 1:3766b24dab80 35 /**
mcm 1:3766b24dab80 36 * @brief LEM_HAIS_GetVoltage ( void )
mcm 1:3766b24dab80 37 *
mcm 2:c865023c4b20 38 * @details It performs a new voltage measurement.
mcm 1:3766b24dab80 39 *
mcm 1:3766b24dab80 40 * @param[in] VoltageDivider: If there is a voltage divider before the ADC pin ( if not VoltageDivider = 1 ).
mcm 1:3766b24dab80 41 * @param[in] ADC_Vref: Voltage reference for the ADC.
mcm 1:3766b24dab80 42 *
mcm 1:3766b24dab80 43 * @param[out] NaN.
mcm 1:3766b24dab80 44 *
mcm 1:3766b24dab80 45 *
mcm 2:c865023c4b20 46 * @return The actual voltage.
mcm 1:3766b24dab80 47 *
mcm 1:3766b24dab80 48 *
mcm 1:3766b24dab80 49 * @author Manuel Caballero
mcm 1:3766b24dab80 50 * @date 19/September/2017
mcm 1:3766b24dab80 51 * @version 19/September/2017 The ORIGIN
mcm 1:3766b24dab80 52 * @pre NaN.
mcm 1:3766b24dab80 53 * @warning NaN.
mcm 1:3766b24dab80 54 */
mcm 1:3766b24dab80 55 LEM_HAIS::Vector_LEM_HAIS_voltage_t LEM_HAIS::LEM_HAIS_GetVoltage ( float VoltageDivider, float ADC_Vref )
mcm 1:3766b24dab80 56 {
mcm 1:3766b24dab80 57 Vector_LEM_HAIS_voltage_t myAuxVoltage;
mcm 1:3766b24dab80 58
mcm 2:c865023c4b20 59
mcm 1:3766b24dab80 60 myAuxVoltage.OUTPUT_Voltage = VoltageDivider * _OUTPUT.read() * ADC_Vref;
mcm 2:c865023c4b20 61
mcm 1:3766b24dab80 62
mcm 1:3766b24dab80 63 return myAuxVoltage;
mcm 1:3766b24dab80 64 }
mcm 1:3766b24dab80 65
mcm 1:3766b24dab80 66
mcm 1:3766b24dab80 67
mcm 1:3766b24dab80 68 /**
mcm 1:3766b24dab80 69 * @brief LEM_HAIS_CalculateCurrent ( Vector_LEM_HAIS_voltage_t ,uint32_t )
mcm 1:3766b24dab80 70 *
mcm 2:c865023c4b20 71 * @details It calculates the actual current.
mcm 1:3766b24dab80 72 *
mcm 1:3766b24dab80 73 * @param[in] myVoltages: Both voltages, OUTPUT and Vref voltages.
mcm 1:3766b24dab80 74 * @param[in] myIPN: Primary Nominal rms Current.
mcm 2:c865023c4b20 75 * @param[in] Device_Vref: Device voltage reference.
mcm 1:3766b24dab80 76 *
mcm 1:3766b24dab80 77 * @param[out] NaN.
mcm 1:3766b24dab80 78 *
mcm 1:3766b24dab80 79 *
mcm 1:3766b24dab80 80 * @return The calculated current.
mcm 1:3766b24dab80 81 *
mcm 1:3766b24dab80 82 *
mcm 1:3766b24dab80 83 * @author Manuel Caballero
mcm 1:3766b24dab80 84 * @date 19/September/2017
mcm 1:3766b24dab80 85 * @version 19/September/2017 The ORIGIN
mcm 2:c865023c4b20 86 * @pre LEM_HAIS_GetVoltage function MUST be called first.
mcm 1:3766b24dab80 87 * @warning NaN.
mcm 1:3766b24dab80 88 */
mcm 2:c865023c4b20 89 LEM_HAIS::Vector_LEM_HAIS_current_t LEM_HAIS::LEM_HAIS_CalculateCurrent ( Vector_LEM_HAIS_voltage_t myVoltages, uint32_t myIPN, float Device_Vref )
mcm 1:3766b24dab80 90 {
mcm 1:3766b24dab80 91 Vector_LEM_HAIS_current_t myAuxCurrent;
mcm 1:3766b24dab80 92
mcm 1:3766b24dab80 93
mcm 2:c865023c4b20 94 myAuxCurrent.Current = ( 8.0 / 5.0 ) * ( ( myVoltages.OUTPUT_Voltage + _LEM_HAIS_V_OFFSET ) - Device_Vref ) * myIPN;
mcm 1:3766b24dab80 95
mcm 1:3766b24dab80 96
mcm 1:3766b24dab80 97
mcm 1:3766b24dab80 98 return myAuxCurrent;
mcm 1:3766b24dab80 99 }
mcm 2:c865023c4b20 100
mcm 2:c865023c4b20 101
mcm 2:c865023c4b20 102
mcm 2:c865023c4b20 103 /**
mcm 2:c865023c4b20 104 * @brief LEM_HAIS_SetAutoOffset ( float , float )
mcm 2:c865023c4b20 105 *
mcm 2:c865023c4b20 106 * @details It calculates the offset automatically ( at 0A current ).
mcm 2:c865023c4b20 107 *
mcm 2:c865023c4b20 108 * @param[in] Device_Vref: Device voltage reference.
mcm 2:c865023c4b20 109 * @param[in] VoltageDivider: If there is a voltage divider before the ADC pin ( if not VoltageDivider = 1 ).
mcm 2:c865023c4b20 110 * @param[in] ADC_Vref: Voltage reference for the ADC.
mcm 2:c865023c4b20 111 *
mcm 2:c865023c4b20 112 * @param[out] NaN.
mcm 2:c865023c4b20 113 *
mcm 2:c865023c4b20 114 *
mcm 2:c865023c4b20 115 * @return The actual offset volatge.
mcm 2:c865023c4b20 116 *
mcm 2:c865023c4b20 117 *
mcm 2:c865023c4b20 118 * @author Manuel Caballero
mcm 2:c865023c4b20 119 * @date 19/September/2017
mcm 2:c865023c4b20 120 * @version 19/September/2017 The ORIGIN
mcm 2:c865023c4b20 121 * @pre NaN.
mcm 2:c865023c4b20 122 * @warning This test has to be perfomed at 0A ( no current through
mcm 2:c865023c4b20 123 * the sensor at all ).
mcm 2:c865023c4b20 124 */
mcm 2:c865023c4b20 125 float LEM_HAIS::LEM_HAIS_SetAutoOffset ( float Device_Vref, float VoltageDivider, float ADC_Vref )
mcm 2:c865023c4b20 126 {
mcm 2:c865023c4b20 127 uint32_t i = 0;
mcm 2:c865023c4b20 128 float myVoltage = 0;
mcm 2:c865023c4b20 129
mcm 2:c865023c4b20 130
mcm 2:c865023c4b20 131 // Calculate the average, get a new measurement every 0.25s
mcm 2:c865023c4b20 132 for ( i = 0; i < CALIBRATION_AVERAGE; i++ ){
mcm 2:c865023c4b20 133 myVoltage += _OUTPUT.read();
mcm 2:c865023c4b20 134 wait ( 0.25 );
mcm 2:c865023c4b20 135 }
mcm 2:c865023c4b20 136
mcm 2:c865023c4b20 137 myVoltage /= ( float )CALIBRATION_AVERAGE;
mcm 2:c865023c4b20 138
mcm 2:c865023c4b20 139
mcm 2:c865023c4b20 140 // Store the offset
mcm 2:c865023c4b20 141 _LEM_HAIS_V_OFFSET = Device_Vref - ( VoltageDivider * myVoltage * ADC_Vref );
mcm 2:c865023c4b20 142
mcm 2:c865023c4b20 143
mcm 2:c865023c4b20 144
mcm 2:c865023c4b20 145 return _LEM_HAIS_V_OFFSET;
mcm 2:c865023c4b20 146 }