Committer:
mcm
Date:
Mon Sep 25 11:57:30 2017 +0000
Revision:
0:511cdcc65d9d
The library was completed and tested, it works as expected.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 0:511cdcc65d9d 1 /**
mcm 0:511cdcc65d9d 2 * @brief VAC.h
mcm 0:511cdcc65d9d 3 * @details For the electronic measurement of currents: DC, AC, pulsed,
mcm 0:511cdcc65d9d 4 * mixed ..., with a galvanic Isolation between the primary circuit
mcm 0:511cdcc65d9d 5 * (high power) and the secondary circuit (electronic circuit).
mcm 0:511cdcc65d9d 6 * Header file.
mcm 0:511cdcc65d9d 7 *
mcm 0:511cdcc65d9d 8 *
mcm 0:511cdcc65d9d 9 * @return NA
mcm 0:511cdcc65d9d 10 *
mcm 0:511cdcc65d9d 11 * @author Manuel Caballero
mcm 0:511cdcc65d9d 12 * @date 25/September/2017
mcm 0:511cdcc65d9d 13 * @version 25/September/2017 The ORIGIN
mcm 0:511cdcc65d9d 14 * @pre VAC ( VACUUMSCHMELZE ) current sensor-modules.
mcm 0:511cdcc65d9d 15 * @warning NaN
mcm 0:511cdcc65d9d 16 * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ).
mcm 0:511cdcc65d9d 17 */
mcm 0:511cdcc65d9d 18 #ifndef VAC_H
mcm 0:511cdcc65d9d 19 #define VAC_H
mcm 0:511cdcc65d9d 20
mcm 0:511cdcc65d9d 21 #include "mbed.h"
mcm 0:511cdcc65d9d 22
mcm 0:511cdcc65d9d 23
mcm 0:511cdcc65d9d 24 /**
mcm 0:511cdcc65d9d 25 Example:
mcm 0:511cdcc65d9d 26
mcm 0:511cdcc65d9d 27 #include "mbed.h"
mcm 0:511cdcc65d9d 28 #include "VAC.h"
mcm 0:511cdcc65d9d 29
mcm 0:511cdcc65d9d 30 VAC myCurrentTransducer ( p20 );
mcm 0:511cdcc65d9d 31 Serial pc ( USBTX, USBRX );
mcm 0:511cdcc65d9d 32
mcm 0:511cdcc65d9d 33 Ticker newReading;
mcm 0:511cdcc65d9d 34 DigitalOut myled1 ( LED1 );
mcm 0:511cdcc65d9d 35 DigitalOut myled2 ( LED2 );
mcm 0:511cdcc65d9d 36
mcm 0:511cdcc65d9d 37
mcm 0:511cdcc65d9d 38 VAC::Vector_VAC_voltage_t myVoltages;
mcm 0:511cdcc65d9d 39 float myVoltageOffset = 0;
mcm 0:511cdcc65d9d 40
mcm 0:511cdcc65d9d 41
mcm 0:511cdcc65d9d 42 void readDATA ( void )
mcm 0:511cdcc65d9d 43 {
mcm 0:511cdcc65d9d 44 VAC::Vector_VAC_current_t myCurrent;
mcm 0:511cdcc65d9d 45
mcm 0:511cdcc65d9d 46 myled2 = 1;
mcm 0:511cdcc65d9d 47
mcm 0:511cdcc65d9d 48 myVoltages = myCurrentTransducer.VAC_GetVoltage ( 1.0, 3.3 ); // NO Voltage divider that is why the numer 1, ADC Vref = 3.3 V
mcm 0:511cdcc65d9d 49 myCurrent = myCurrentTransducer.VAC_CalculateCurrent ( myVoltages, 2000, 100 ); // KN = 2000, RM = 100 Ohms
mcm 0:511cdcc65d9d 50
mcm 0:511cdcc65d9d 51 pc.printf( "Vout: %0.5f V IP: %0.5f A\r\n", myVoltages.INPUT_Voltage, myCurrent.Current );
mcm 0:511cdcc65d9d 52
mcm 0:511cdcc65d9d 53 myled2 = 0;
mcm 0:511cdcc65d9d 54 }
mcm 0:511cdcc65d9d 55
mcm 0:511cdcc65d9d 56
mcm 0:511cdcc65d9d 57 int main()
mcm 0:511cdcc65d9d 58 {
mcm 0:511cdcc65d9d 59 pc.baud ( 115200 );
mcm 0:511cdcc65d9d 60
mcm 0:511cdcc65d9d 61 // [ OPTIONAL ] CALIBRATION. It calculates the offset to calibrate the future measurements.
mcm 0:511cdcc65d9d 62 myled1 = 1;
mcm 0:511cdcc65d9d 63
mcm 0:511cdcc65d9d 64 // It reads PIN3 from the device. NOTE: This MUST be done at 0A current!!!
mcm 0:511cdcc65d9d 65 myVoltageOffset = myCurrentTransducer.VAC_SetAutoOffset ( 1.0, 3.3 ); // NO Voltage divider that is why the numer 1, ADC Vref = 3.3 V
mcm 0:511cdcc65d9d 66 myled1 = 0;
mcm 0:511cdcc65d9d 67
mcm 0:511cdcc65d9d 68 pc.printf( "Voff: %0.5f V\r\n", myVoltageOffset );
mcm 0:511cdcc65d9d 69 // CALIBRATION ends here
mcm 0:511cdcc65d9d 70
mcm 0:511cdcc65d9d 71
mcm 0:511cdcc65d9d 72 newReading.attach( &readDATA, 0.5 ); // the address of the function to be attached ( readDATA ) and the interval ( 0.5s )
mcm 0:511cdcc65d9d 73
mcm 0:511cdcc65d9d 74
mcm 0:511cdcc65d9d 75 // Let the callbacks take care of everything
mcm 0:511cdcc65d9d 76 while(1)
mcm 0:511cdcc65d9d 77 {
mcm 0:511cdcc65d9d 78 sleep();
mcm 0:511cdcc65d9d 79 }
mcm 0:511cdcc65d9d 80 }
mcm 0:511cdcc65d9d 81
mcm 0:511cdcc65d9d 82 */
mcm 0:511cdcc65d9d 83
mcm 0:511cdcc65d9d 84
mcm 0:511cdcc65d9d 85 /*!
mcm 0:511cdcc65d9d 86 Library for the VAC Current transducer.
mcm 0:511cdcc65d9d 87 */
mcm 0:511cdcc65d9d 88 class VAC
mcm 0:511cdcc65d9d 89 {
mcm 0:511cdcc65d9d 90 public:
mcm 0:511cdcc65d9d 91 #define CALIBRATION_AVERAGE 10 // Change it if you wish to calculate the offset with less measurements
mcm 0:511cdcc65d9d 92
mcm 0:511cdcc65d9d 93
mcm 0:511cdcc65d9d 94
mcm 0:511cdcc65d9d 95 #ifndef VECTOR_STRUCT_H
mcm 0:511cdcc65d9d 96 #define VECTOR_STRUCT_H
mcm 0:511cdcc65d9d 97 typedef struct {
mcm 0:511cdcc65d9d 98 float Current;
mcm 0:511cdcc65d9d 99 } Vector_VAC_current_t;
mcm 0:511cdcc65d9d 100
mcm 0:511cdcc65d9d 101 typedef struct {
mcm 0:511cdcc65d9d 102 float INPUT_Voltage;
mcm 0:511cdcc65d9d 103 } Vector_VAC_voltage_t;
mcm 0:511cdcc65d9d 104 #endif
mcm 0:511cdcc65d9d 105
mcm 0:511cdcc65d9d 106
mcm 0:511cdcc65d9d 107 /** Create an VAC object connected to the specified pins.
mcm 0:511cdcc65d9d 108 *
mcm 0:511cdcc65d9d 109 * @param INPUT Vout from the device
mcm 0:511cdcc65d9d 110 */
mcm 0:511cdcc65d9d 111 VAC ( PinName INPUT );
mcm 0:511cdcc65d9d 112
mcm 0:511cdcc65d9d 113 /** Delete VAC object.
mcm 0:511cdcc65d9d 114 */
mcm 0:511cdcc65d9d 115 ~VAC();
mcm 0:511cdcc65d9d 116
mcm 0:511cdcc65d9d 117 /** It gets the voltage.
mcm 0:511cdcc65d9d 118 */
mcm 0:511cdcc65d9d 119 Vector_VAC_voltage_t VAC_GetVoltage ( float VoltageDivider = 1.0, float ADC_Vref = 3.3 );
mcm 0:511cdcc65d9d 120
mcm 0:511cdcc65d9d 121 /** It calculates the offset automatically ( at 0A current ).
mcm 0:511cdcc65d9d 122 */
mcm 0:511cdcc65d9d 123 float VAC_SetAutoOffset ( float VoltageDivider = 1.0, float ADC_Vref = 3.3 );
mcm 0:511cdcc65d9d 124
mcm 0:511cdcc65d9d 125 /** It calculates the current.
mcm 0:511cdcc65d9d 126 */
mcm 0:511cdcc65d9d 127 Vector_VAC_current_t VAC_CalculateCurrent ( Vector_VAC_voltage_t myVoltages, uint32_t myKN, float myRM );
mcm 0:511cdcc65d9d 128
mcm 0:511cdcc65d9d 129
mcm 0:511cdcc65d9d 130
mcm 0:511cdcc65d9d 131 private:
mcm 0:511cdcc65d9d 132 AnalogIn _INPUT;
mcm 0:511cdcc65d9d 133 float _VAC_V_OFFSET;
mcm 0:511cdcc65d9d 134 };
mcm 0:511cdcc65d9d 135
mcm 0:511cdcc65d9d 136 #endif