Current transducer. For the electronic measurement of currents: DC, AC, pulsed..., with galvanic separation between the primary circuit and the secondary circuit.
LEM_HAIS.h@4:5002bb8e907b, 2017-10-10 (annotated)
- Committer:
- mcm
- Date:
- Tue Oct 10 14:56:04 2017 +0000
- Revision:
- 4:5002bb8e907b
- Parent:
- 3:6bc9b8543f13
A structure with several parameters were declared, these parameters will define the system. ; ; NOTE: All the test are performed using RMS theory. Sampling at 1ms for 1 second ( = 1000 samples ).; ; The library was tested and it works as expected.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mcm | 1:3766b24dab80 | 1 | /** |
mcm | 1:3766b24dab80 | 2 | * @brief LEM_HAIS.h |
mcm | 2:c865023c4b20 | 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 | * Header file. |
mcm | 1:3766b24dab80 | 7 | * |
mcm | 1:3766b24dab80 | 8 | * |
mcm | 1:3766b24dab80 | 9 | * @return NA |
mcm | 1:3766b24dab80 | 10 | * |
mcm | 2:c865023c4b20 | 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 | #ifndef LEM_HAIS_H |
mcm | 1:3766b24dab80 | 19 | #define LEM_HAIS_H |
mcm | 1:3766b24dab80 | 20 | |
mcm | 1:3766b24dab80 | 21 | #include "mbed.h" |
mcm | 1:3766b24dab80 | 22 | |
mcm | 1:3766b24dab80 | 23 | |
mcm | 1:3766b24dab80 | 24 | /** |
mcm | 1:3766b24dab80 | 25 | Example: |
mcm | 1:3766b24dab80 | 26 | |
mcm | 2:c865023c4b20 | 27 | #include "mbed.h" |
mcm | 2:c865023c4b20 | 28 | #include "LEM_HAIS.h" |
mcm | 2:c865023c4b20 | 29 | |
mcm | 3:6bc9b8543f13 | 30 | |
mcm | 4:5002bb8e907b | 31 | LEM_HAIS myCurrentTransducer ( p20 ); |
mcm | 2:c865023c4b20 | 32 | Serial pc ( USBTX, USBRX ); |
mcm | 2:c865023c4b20 | 33 | |
mcm | 2:c865023c4b20 | 34 | Ticker newReading; |
mcm | 2:c865023c4b20 | 35 | DigitalOut myled1 ( LED1 ); |
mcm | 2:c865023c4b20 | 36 | DigitalOut myled2 ( LED2 ); |
mcm | 2:c865023c4b20 | 37 | AnalogIn myVref ( p19 ); |
mcm | 3:6bc9b8543f13 | 38 | AnalogIn myINPUT ( p20 ); |
mcm | 3:6bc9b8543f13 | 39 | |
mcm | 2:c865023c4b20 | 40 | |
mcm | 4:5002bb8e907b | 41 | LEM_HAIS::LEM_HAIS_parameters_t myParameters; |
mcm | 4:5002bb8e907b | 42 | LEM_HAIS::LEM_HAIS_voltage_t myVoltages; |
mcm | 2:c865023c4b20 | 43 | |
mcm | 2:c865023c4b20 | 44 | |
mcm | 2:c865023c4b20 | 45 | void readDATA ( void ) |
mcm | 2:c865023c4b20 | 46 | { |
mcm | 4:5002bb8e907b | 47 | LEM_HAIS::LEM_HAIS_current_t myCurrent; |
mcm | 2:c865023c4b20 | 48 | |
mcm | 2:c865023c4b20 | 49 | myled2 = 1; |
mcm | 2:c865023c4b20 | 50 | |
mcm | 3:6bc9b8543f13 | 51 | myVoltages = myCurrentTransducer.LEM_HAIS_GetVoltage (); |
mcm | 4:5002bb8e907b | 52 | myCurrent = myCurrentTransducer.LEM_HAIS_CalculateCurrent ( myVoltages, myParameters, LEM_HAIS::FILTER_DISABLED ); |
mcm | 2:c865023c4b20 | 53 | |
mcm | 4:5002bb8e907b | 54 | pc.printf( "IP: %0.5f A\r\n", myCurrent.Current ); |
mcm | 2:c865023c4b20 | 55 | |
mcm | 2:c865023c4b20 | 56 | myled2 = 0; |
mcm | 2:c865023c4b20 | 57 | } |
mcm | 2:c865023c4b20 | 58 | |
mcm | 2:c865023c4b20 | 59 | |
mcm | 2:c865023c4b20 | 60 | int main() |
mcm | 2:c865023c4b20 | 61 | { |
mcm | 2:c865023c4b20 | 62 | uint32_t i = 0; |
mcm | 2:c865023c4b20 | 63 | |
mcm | 4:5002bb8e907b | 64 | // CONFIGURATION. The parameters of the system |
mcm | 4:5002bb8e907b | 65 | // myParameters.lem_hais_reference_voltage = 2.5; // ( uncomment ) Mandatory if calibration is NOT used! |
mcm | 4:5002bb8e907b | 66 | myParameters.voltage_divider = 2.0; // Resistor ( both with the same value ) divider at the Sensor ( LEM-HAIS ) Vout |
mcm | 4:5002bb8e907b | 67 | myParameters.adc_reference_voltage = 3.3; // ADC microcontroller ~ 3.3V |
mcm | 4:5002bb8e907b | 68 | myParameters.lem_hais_ipm = 150.0; // HAIS 150-P |
mcm | 4:5002bb8e907b | 69 | |
mcm | 2:c865023c4b20 | 70 | pc.baud ( 115200 ); |
mcm | 2:c865023c4b20 | 71 | |
mcm | 3:6bc9b8543f13 | 72 | |
mcm | 2:c865023c4b20 | 73 | // [ OPTIONAL ] CALIBRATION. It calculates the offset to calibrate the future measurements. |
mcm | 2:c865023c4b20 | 74 | // It reads the Vref from the device. |
mcm | 2:c865023c4b20 | 75 | myled1 = 1; |
mcm | 3:6bc9b8543f13 | 76 | for ( i = 0; i < 10; i++ ) { |
mcm | 4:5002bb8e907b | 77 | myParameters.lem_hais_reference_voltage += myVref.read(); |
mcm | 2:c865023c4b20 | 78 | wait ( 0.25 ); |
mcm | 2:c865023c4b20 | 79 | } |
mcm | 2:c865023c4b20 | 80 | |
mcm | 4:5002bb8e907b | 81 | myParameters.lem_hais_reference_voltage /= 10.0; |
mcm | 4:5002bb8e907b | 82 | myParameters.lem_hais_reference_voltage *= myParameters.adc_reference_voltage; |
mcm | 2:c865023c4b20 | 83 | |
mcm | 2:c865023c4b20 | 84 | // It reads OUPUT from the device. NOTE: This MUST be done at 0A current!!! |
mcm | 4:5002bb8e907b | 85 | myParameters.lem_hais_offset_voltage = myCurrentTransducer.LEM_HAIS_SetAutoOffset ( myParameters ); |
mcm | 2:c865023c4b20 | 86 | myled1 = 0; |
mcm | 2:c865023c4b20 | 87 | |
mcm | 4:5002bb8e907b | 88 | pc.printf( "Vref: %0.5f V Voff: %0.5f V\r\n", myParameters.lem_hais_reference_voltage, myParameters.lem_hais_offset_voltage ); |
mcm | 2:c865023c4b20 | 89 | // CALIBRATION ends here |
mcm | 2:c865023c4b20 | 90 | |
mcm | 2:c865023c4b20 | 91 | |
mcm | 4:5002bb8e907b | 92 | newReading.attach( &readDATA, 1.5 ); // the address of the function to be attached ( readDATA ) and the interval ( 1.5s ) |
mcm | 2:c865023c4b20 | 93 | |
mcm | 2:c865023c4b20 | 94 | |
mcm | 2:c865023c4b20 | 95 | // Let the callbacks take care of everything |
mcm | 2:c865023c4b20 | 96 | while(1) { |
mcm | 2:c865023c4b20 | 97 | sleep(); |
mcm | 2:c865023c4b20 | 98 | } |
mcm | 2:c865023c4b20 | 99 | } |
mcm | 1:3766b24dab80 | 100 | |
mcm | 1:3766b24dab80 | 101 | */ |
mcm | 1:3766b24dab80 | 102 | |
mcm | 1:3766b24dab80 | 103 | |
mcm | 1:3766b24dab80 | 104 | /*! |
mcm | 1:3766b24dab80 | 105 | Library for the LEM_HAIS Current transducer. |
mcm | 1:3766b24dab80 | 106 | */ |
mcm | 1:3766b24dab80 | 107 | class LEM_HAIS |
mcm | 1:3766b24dab80 | 108 | { |
mcm | 1:3766b24dab80 | 109 | public: |
mcm | 3:6bc9b8543f13 | 110 | #define CALIBRATION_AVERAGE 10 // Change it if you wish to calculate the offset with less measurements |
mcm | 3:6bc9b8543f13 | 111 | #define SAMPLE_DATA 1000 // 1 sample every 1ms -> 1000 total samples in total ( = 1s ) |
mcm | 3:6bc9b8543f13 | 112 | |
mcm | 3:6bc9b8543f13 | 113 | typedef enum { |
mcm | 3:6bc9b8543f13 | 114 | FILTER_ENABLED = 1, |
mcm | 3:6bc9b8543f13 | 115 | FILTER_DISABLED = 0 |
mcm | 3:6bc9b8543f13 | 116 | } LEM_HAIS_filter_status_t; |
mcm | 3:6bc9b8543f13 | 117 | |
mcm | 2:c865023c4b20 | 118 | |
mcm | 1:3766b24dab80 | 119 | |
mcm | 1:3766b24dab80 | 120 | |
mcm | 4:5002bb8e907b | 121 | #ifndef LEM_HAIS_DATA_STRUCT_H |
mcm | 4:5002bb8e907b | 122 | #define LEM_HAIS_DATA_STRUCT_H |
mcm | 1:3766b24dab80 | 123 | typedef struct { |
mcm | 1:3766b24dab80 | 124 | float Current; |
mcm | 4:5002bb8e907b | 125 | } LEM_HAIS_current_t; |
mcm | 1:3766b24dab80 | 126 | |
mcm | 1:3766b24dab80 | 127 | typedef struct { |
mcm | 3:6bc9b8543f13 | 128 | float OUTPUT_Voltage[SAMPLE_DATA]; |
mcm | 4:5002bb8e907b | 129 | } LEM_HAIS_voltage_t; |
mcm | 4:5002bb8e907b | 130 | |
mcm | 4:5002bb8e907b | 131 | typedef struct { |
mcm | 4:5002bb8e907b | 132 | float lem_hais_offset_voltage; |
mcm | 4:5002bb8e907b | 133 | float lem_hais_reference_voltage; |
mcm | 4:5002bb8e907b | 134 | float voltage_divider; |
mcm | 4:5002bb8e907b | 135 | float adc_reference_voltage; |
mcm | 4:5002bb8e907b | 136 | float lem_hais_ipm; |
mcm | 4:5002bb8e907b | 137 | } LEM_HAIS_parameters_t; |
mcm | 1:3766b24dab80 | 138 | #endif |
mcm | 1:3766b24dab80 | 139 | |
mcm | 1:3766b24dab80 | 140 | |
mcm | 4:5002bb8e907b | 141 | |
mcm | 4:5002bb8e907b | 142 | |
mcm | 1:3766b24dab80 | 143 | /** Create an LEM_HAIS object connected to the specified pins. |
mcm | 1:3766b24dab80 | 144 | * |
mcm | 1:3766b24dab80 | 145 | * @param OUTPUT Vout from the device |
mcm | 1:3766b24dab80 | 146 | */ |
mcm | 4:5002bb8e907b | 147 | LEM_HAIS ( PinName OUTPUT ); |
mcm | 1:3766b24dab80 | 148 | |
mcm | 1:3766b24dab80 | 149 | /** Delete LEM_HAIS object. |
mcm | 1:3766b24dab80 | 150 | */ |
mcm | 1:3766b24dab80 | 151 | ~LEM_HAIS(); |
mcm | 1:3766b24dab80 | 152 | |
mcm | 1:3766b24dab80 | 153 | /** It gets the voltage. |
mcm | 1:3766b24dab80 | 154 | */ |
mcm | 4:5002bb8e907b | 155 | LEM_HAIS_voltage_t LEM_HAIS_GetVoltage ( void ); |
mcm | 1:3766b24dab80 | 156 | |
mcm | 2:c865023c4b20 | 157 | /** It calculates the offset automatically ( at 0A current ). |
mcm | 2:c865023c4b20 | 158 | */ |
mcm | 4:5002bb8e907b | 159 | float LEM_HAIS_SetAutoOffset ( LEM_HAIS_parameters_t myParameters ); |
mcm | 2:c865023c4b20 | 160 | |
mcm | 1:3766b24dab80 | 161 | /** It calculates the current. |
mcm | 1:3766b24dab80 | 162 | */ |
mcm | 4:5002bb8e907b | 163 | LEM_HAIS_current_t LEM_HAIS_CalculateCurrent ( LEM_HAIS_voltage_t myVoltages, LEM_HAIS_parameters_t myParameters, LEM_HAIS_filter_status_t myFilter = FILTER_DISABLED ); |
mcm | 1:3766b24dab80 | 164 | |
mcm | 1:3766b24dab80 | 165 | |
mcm | 1:3766b24dab80 | 166 | |
mcm | 1:3766b24dab80 | 167 | private: |
mcm | 2:c865023c4b20 | 168 | AnalogIn _OUTPUT; |
mcm | 1:3766b24dab80 | 169 | }; |
mcm | 1:3766b24dab80 | 170 | |
mcm | 1:3766b24dab80 | 171 | #endif |