baseline build
Dependencies: FastPWM mbed-os mbed
ADCInput.cpp@0:8a420ac6394e, 2017-06-19 (annotated)
- Committer:
- jrhodes5150
- Date:
- Mon Jun 19 15:55:51 2017 +0000
- Revision:
- 0:8a420ac6394e
initial build - baseline;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jrhodes5150 | 0:8a420ac6394e | 1 | |
jrhodes5150 | 0:8a420ac6394e | 2 | #include "ADCInput.h" |
jrhodes5150 | 0:8a420ac6394e | 3 | #include "DeviceProperties.h" |
jrhodes5150 | 0:8a420ac6394e | 4 | |
jrhodes5150 | 0:8a420ac6394e | 5 | ADCInput::ADCInput(void) : vSense(p15), |
jrhodes5150 | 0:8a420ac6394e | 6 | iSense(p16), |
jrhodes5150 | 0:8a420ac6394e | 7 | vRMS(p19), |
jrhodes5150 | 0:8a420ac6394e | 8 | iRMS(p20) |
jrhodes5150 | 0:8a420ac6394e | 9 | |
jrhodes5150 | 0:8a420ac6394e | 10 | { |
jrhodes5150 | 0:8a420ac6394e | 11 | avgValue = 0.0; |
jrhodes5150 | 0:8a420ac6394e | 12 | } |
jrhodes5150 | 0:8a420ac6394e | 13 | |
jrhodes5150 | 0:8a420ac6394e | 14 | double ADCInput::GetSensedVoltage(void) |
jrhodes5150 | 0:8a420ac6394e | 15 | { |
jrhodes5150 | 0:8a420ac6394e | 16 | avgValue = 0.0; |
jrhodes5150 | 0:8a420ac6394e | 17 | for(int i=0; i<NUM_SAMPLES; i++) { |
jrhodes5150 | 0:8a420ac6394e | 18 | avgValue += vSense.read(); |
jrhodes5150 | 0:8a420ac6394e | 19 | wait_us(1); |
jrhodes5150 | 0:8a420ac6394e | 20 | } |
jrhodes5150 | 0:8a420ac6394e | 21 | |
jrhodes5150 | 0:8a420ac6394e | 22 | //Device.deviceConfig.voltageSensed = ((avgValue / NUM_SAMPLES) * 3.3 )* 200 ; |
jrhodes5150 | 0:8a420ac6394e | 23 | return ((avgValue / NUM_SAMPLES) * 3.3 )* 200 ; |
jrhodes5150 | 0:8a420ac6394e | 24 | |
jrhodes5150 | 0:8a420ac6394e | 25 | } |
jrhodes5150 | 0:8a420ac6394e | 26 | |
jrhodes5150 | 0:8a420ac6394e | 27 | double ADCInput::GetSensedCurrent(void) |
jrhodes5150 | 0:8a420ac6394e | 28 | { |
jrhodes5150 | 0:8a420ac6394e | 29 | avgValue = 0.0; |
jrhodes5150 | 0:8a420ac6394e | 30 | for(int i=0; i<NUM_SAMPLES; i++) { |
jrhodes5150 | 0:8a420ac6394e | 31 | avgValue += iSense.read(); |
jrhodes5150 | 0:8a420ac6394e | 32 | wait_us(1); |
jrhodes5150 | 0:8a420ac6394e | 33 | } |
jrhodes5150 | 0:8a420ac6394e | 34 | //Device.deviceConfig.currentSensed = ((avgValue / NUM_SAMPLES) * 3.3); |
jrhodes5150 | 0:8a420ac6394e | 35 | return((avgValue / NUM_SAMPLES) * 3.3)/.85; |
jrhodes5150 | 0:8a420ac6394e | 36 | |
jrhodes5150 | 0:8a420ac6394e | 37 | } |
jrhodes5150 | 0:8a420ac6394e | 38 | |
jrhodes5150 | 0:8a420ac6394e | 39 | double ADCInput::GetRMSVoltage(void) |
jrhodes5150 | 0:8a420ac6394e | 40 | { |
jrhodes5150 | 0:8a420ac6394e | 41 | avgValue = 0.0; |
jrhodes5150 | 0:8a420ac6394e | 42 | for(int i=0; i<NUM_SAMPLES; i++) { |
jrhodes5150 | 0:8a420ac6394e | 43 | avgValue += vRMS.read(); |
jrhodes5150 | 0:8a420ac6394e | 44 | wait_us(1); |
jrhodes5150 | 0:8a420ac6394e | 45 | } |
jrhodes5150 | 0:8a420ac6394e | 46 | |
jrhodes5150 | 0:8a420ac6394e | 47 | |
jrhodes5150 | 0:8a420ac6394e | 48 | return (avgValue / NUM_SAMPLES)* 3.3 * 200 ; |
jrhodes5150 | 0:8a420ac6394e | 49 | } |
jrhodes5150 | 0:8a420ac6394e | 50 | |
jrhodes5150 | 0:8a420ac6394e | 51 | double ADCInput::GetRMSCurrent(void) |
jrhodes5150 | 0:8a420ac6394e | 52 | { |
jrhodes5150 | 0:8a420ac6394e | 53 | avgValue = 0.0; |
jrhodes5150 | 0:8a420ac6394e | 54 | for(int i=0; i<NUM_SAMPLES; i++) { |
jrhodes5150 | 0:8a420ac6394e | 55 | avgValue += iRMS.read(); |
jrhodes5150 | 0:8a420ac6394e | 56 | wait_us(1); |
jrhodes5150 | 0:8a420ac6394e | 57 | } |
jrhodes5150 | 0:8a420ac6394e | 58 | |
jrhodes5150 | 0:8a420ac6394e | 59 | return((avgValue / NUM_SAMPLES) * 3.3)/.85 ; |
jrhodes5150 | 0:8a420ac6394e | 60 | |
jrhodes5150 | 0:8a420ac6394e | 61 | } |
jrhodes5150 | 0:8a420ac6394e | 62 | |
jrhodes5150 | 0:8a420ac6394e | 63 | double ADCInput::GetResistance(void) |
jrhodes5150 | 0:8a420ac6394e | 64 | { |
jrhodes5150 | 0:8a420ac6394e | 65 | |
jrhodes5150 | 0:8a420ac6394e | 66 | return((GetRMSVoltage()) / GetRMSCurrent()); |
jrhodes5150 | 0:8a420ac6394e | 67 | |
jrhodes5150 | 0:8a420ac6394e | 68 | } |
jrhodes5150 | 0:8a420ac6394e | 69 | double ADCInput::GetSensedPower(void) |
jrhodes5150 | 0:8a420ac6394e | 70 | { |
jrhodes5150 | 0:8a420ac6394e | 71 | return( GetSensedVoltage() * GetSensedCurrent() ); |
jrhodes5150 | 0:8a420ac6394e | 72 | } |
jrhodes5150 | 0:8a420ac6394e | 73 |