Skip to content

Commit 968f92d

Browse files
authored
Merge pull request #312 from ShimmerResearch/gsr_verisense_amplifier_reference
Decode Verisense SR68/SR61 GSR against its 0.4986 V amplifier reference
2 parents 73dcd41 + 81a1a5b commit 968f92d

4 files changed

Lines changed: 145 additions & 35 deletions

File tree

‎ShimmerDriver/src/main/java/com/shimmerresearch/sensors/SensorGSR.java‎

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ public class SensorGSR extends AbstractSensor {
4141
private double[] currentGsrRefResistorsKohms = SHIMMER3_GSR_REF_RESISTORS_KOHMS;
4242
private double[][] currentGsrResistanceKohmsMinMax = SHIMMER3_GSR_RESISTANCE_MIN_MAX_KOHMS;
4343
private int currentGsrUncalLimitRange3 = GSR_UNCAL_LIMIT_RANGE3;
44-
44+
private double currentGsrAmplifierRefVoltage = GSR_AMPLIFIER_REF_VOLTAGE;
45+
46+
/**
47+
* The voltage on the GSR amplifier's non-inverting input, which the amplifier equation divides
48+
* by: 0.5 V on the Shimmer3, the ShimmerGQ and the Verisense GSR+ (SR62). The Verisense Pulse+
49+
* (SR68) and SR61-5/6 front end has its own:
50+
* {@code SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE}.
51+
*/
52+
public static final double GSR_AMPLIFIER_REF_VOLTAGE = 0.5;
53+
4554
public static final double[] SHIMMER3_GSR_REF_RESISTORS_KOHMS = new double[] {
4655
40.2, //Range 0
4756
287.0, //Range 1
@@ -361,7 +370,7 @@ public ObjectCluster processDataCustom(SensorDetails sensorDetails, byte[] senso
361370
// gsrAdcValueUnCal = SensorGSR.nudgeGsrADC(gsrAdcValueUnCal, currentGSRRange);
362371

363372
//...and on ranges 0-2 too, where only the resistance changes (DEV-1070)
364-
gsrResistanceKOhms = SensorGSR.calibrateGsrDataToKOhmsWithOpenCircuitLimit(gsrAdcValueUnCal, currentGSRRange, currentGsrUncalLimitRange3, microcontrollerAdcProperties, currentGsrRefResistorsKohms);
373+
gsrResistanceKOhms = SensorGSR.calibrateGsrDataToKOhmsWithOpenCircuitLimit(gsrAdcValueUnCal, currentGSRRange, currentGsrUncalLimitRange3, microcontrollerAdcProperties, currentGsrRefResistorsKohms, currentGsrAmplifierRefVoltage);
365374
gsrResistanceKOhms = SensorGSR.nudgeGsrResistance(gsrResistanceKOhms, getGSRRange(), currentGsrResistanceKohmsMinMax);
366375
gsrConductanceUSiemens = SensorGSR.convertkOhmToUSiemens(gsrResistanceKOhms);
367376
// } else {
@@ -602,17 +611,27 @@ public static double calibrateGsrDataToSiemens(double gsrUncalibratedData, doubl
602611
return gsrCalibratedData;
603612
}
604613

605-
/** Based on circuit theory of the GSR non-inverting amplifier.
606-
*
614+
/** Based on circuit theory of the GSR non-inverting amplifier, with the 0.5 V reference of the
615+
* Shimmer3, the ShimmerGQ and the Verisense GSR+ (SR62).
616+
*
607617
* @param gsrUncalibratedData
608618
* @param range
609-
* @param microcontrollerAdcProperties
619+
* @param microcontrollerAdcProperties
610620
* @return
611621
*/
612622
public static double calibrateGsrDataToKOhmsUsingAmplifierEq(double gsrUncalibratedData, int range, MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties, double[] gsrRefResistorsKohms){
623+
return calibrateGsrDataToKOhmsUsingAmplifierEq(gsrUncalibratedData, range, microcontrollerAdcProperties, gsrRefResistorsKohms, GSR_AMPLIFIER_REF_VOLTAGE);
624+
}
625+
626+
/** Based on circuit theory of the GSR non-inverting amplifier: R = Rf / (V / Vref - 1).
627+
*
628+
* @param gsrAmplifierRefVoltage the front end's amplifier reference: {@link #GSR_AMPLIFIER_REF_VOLTAGE},
629+
* or {@code SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE} on gen-2
630+
*/
631+
public static double calibrateGsrDataToKOhmsUsingAmplifierEq(double gsrUncalibratedData, int range, MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties, double[] gsrRefResistorsKohms, double gsrAmplifierRefVoltage){
613632
double rFeedback = gsrRefResistorsKohms[range];
614633
double volts = SensorADC.calibrateAdcChannelToVolts(gsrUncalibratedData, microcontrollerAdcProperties);
615-
double rSource = rFeedback/((volts/0.5)-1.0);
634+
double rSource = rFeedback/((volts/gsrAmplifierRefVoltage)-1.0);
616635
return rSource;
617636
}
618637

@@ -622,7 +641,7 @@ public static double calibrateGsrDataToKOhmsUsingAmplifierEq(double gsrUncalibra
622641
* <p>
623642
* The amplifier equation has no positive solution at or below the amplifier's reference: no skin
624643
* resistance can pull the output under it, so a code there means the electrodes are open. Range 3
625-
* has long raised such a code to its open-circuit limit, the first code above the reference, so
644+
* has long raised such a code to its open-circuit limit, a code just above the reference, so
626645
* that an open circuit decodes as thousands of MOhm. Ranges 0-2 did not, and in auto-range they
627646
* see these codes too. When the electrodes come off, the device climbs one range at a time, and
628647
* the firmware repeats the sample that triggered each switch through the 80 ms settling time,
@@ -641,17 +660,32 @@ public static double calibrateGsrDataToKOhmsUsingAmplifierEq(double gsrUncalibra
641660
* or {@code SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3} on gen-2
642661
*/
643662
public static double calibrateGsrDataToKOhmsWithOpenCircuitLimit(double gsrUncalibratedData, int range, int gsrUncalLimitRange3, MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties, double[] gsrRefResistorsKohms){
663+
return calibrateGsrDataToKOhmsWithOpenCircuitLimit(gsrUncalibratedData, range, gsrUncalLimitRange3, microcontrollerAdcProperties, gsrRefResistorsKohms, GSR_AMPLIFIER_REF_VOLTAGE);
664+
}
665+
666+
/**
667+
* {@link #calibrateGsrDataToKOhmsWithOpenCircuitLimit(double, int, int, MICROCONTROLLER_ADC_PROPERTIES, double[])}
668+
* with the front end's own amplifier reference.
669+
*/
670+
public static double calibrateGsrDataToKOhmsWithOpenCircuitLimit(double gsrUncalibratedData, int range, int gsrUncalLimitRange3, MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties, double[] gsrRefResistorsKohms, double gsrAmplifierRefVoltage){
644671
if(gsrUncalibratedData<gsrUncalLimitRange3) {
645-
return calibrateGsrDataToKOhmsUsingAmplifierEq(gsrUncalLimitRange3, 3, microcontrollerAdcProperties, gsrRefResistorsKohms);
672+
return calibrateGsrDataToKOhmsUsingAmplifierEq(gsrUncalLimitRange3, 3, microcontrollerAdcProperties, gsrRefResistorsKohms, gsrAmplifierRefVoltage);
646673
}
647-
return calibrateGsrDataToKOhmsUsingAmplifierEq(gsrUncalibratedData, range, microcontrollerAdcProperties, gsrRefResistorsKohms);
674+
return calibrateGsrDataToKOhmsUsingAmplifierEq(gsrUncalibratedData, range, microcontrollerAdcProperties, gsrRefResistorsKohms, gsrAmplifierRefVoltage);
648675
}
649676

650677
/**TODO test method no functioning properly yet
651678
* @param gsrkOhms
652679
* @return
653680
*/
654681
public static int uncalibrateGsrDataTokOhmsUsingAmplifierEq(double gsrkOhms, MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties, double[] gsrRefResistorsKohms, double[][] gsrResistanceKohmsMinMax){
682+
return uncalibrateGsrDataTokOhmsUsingAmplifierEq(gsrkOhms, microcontrollerAdcProperties, gsrRefResistorsKohms, gsrResistanceKohmsMinMax, GSR_AMPLIFIER_REF_VOLTAGE);
683+
}
684+
685+
/**{@link #uncalibrateGsrDataTokOhmsUsingAmplifierEq(double, MICROCONTROLLER_ADC_PROPERTIES, double[], double[][])}
686+
* with the front end's own amplifier reference.
687+
*/
688+
public static int uncalibrateGsrDataTokOhmsUsingAmplifierEq(double gsrkOhms, MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties, double[] gsrRefResistorsKohms, double[][] gsrResistanceKohmsMinMax, double gsrAmplifierRefVoltage){
655689
int range = 0;
656690
for(int i=0;i<gsrResistanceKohmsMinMax.length;i++) {
657691
double[] minMax = gsrResistanceKohmsMinMax[i];
@@ -663,7 +697,7 @@ public static int uncalibrateGsrDataTokOhmsUsingAmplifierEq(double gsrkOhms, MIC
663697
}
664698

665699
double rFeedback = gsrRefResistorsKohms[range];
666-
double volts = ((rFeedback / gsrkOhms) + 1.0) * 0.5;
700+
double volts = ((rFeedback / gsrkOhms) + 1.0) * gsrAmplifierRefVoltage;
667701

668702
int gsrUncalibratedData = SensorADC.uncalibrateAdcChannelFromVolts(volts, microcontrollerAdcProperties);
669703
//Add range
@@ -777,6 +811,15 @@ public void setCurrentGsrUncalLimitRange3(int currentGsrUncalLimitRange3) {
777811
this.currentGsrUncalLimitRange3 = currentGsrUncalLimitRange3;
778812
}
779813

814+
public double getCurrentGsrAmplifierRefVoltage() {
815+
return currentGsrAmplifierRefVoltage;
816+
}
817+
818+
819+
public void setCurrentGsrAmplifierRefVoltage(double currentGsrAmplifierRefVoltage) {
820+
this.currentGsrAmplifierRefVoltage = currentGsrAmplifierRefVoltage;
821+
}
822+
780823
// @Deprecated
781824
// public static boolean isSupportedImprovedGsrCalibration(ShimmerVerObject svo) {
782825
// if(svo.compareVersions(HW_ID.SHIMMER_3, FW_ID.SDLOG, 0, 19, 0)

‎ShimmerDriver/src/main/java/com/shimmerresearch/verisense/sensors/SensorGSRVerisense.java‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,30 @@ public static GSR_RANGE getForConfigValue(int configValue) {
8686
150.0, //Range 1
8787
562.0, //Range 2
8888
1740.0}; //Range 3
89+
/**
90+
* The amplifier reference of this front end: a 261k/100k divider off the 1.8 V rail, so
91+
* 1.8 x 100 / 361 = 0.4986 V at the op-amp's non-inverting input, on every Verisense revision
92+
* that has it. It was taken as the Shimmer3's 0.5 V until now, which read every resistance about
93+
* 0.5-1% high and an open circuit as about 4.0 GOhm instead of 541 MOhm. The C# API and the web
94+
* SDK divide by 0.4986 V.
95+
* <p>
96+
* The SAADC samples GSR against VDD/4 with a gain of 1/4, so its full scale is the rail itself.
97+
* If the divider is fed from that same rail, the reference sits at code 1134.3 whatever the
98+
* rail's exact level.
99+
*/
100+
public static final double VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE = 1.8 * 100.0 / (261.0 + 100.0);
89101
/**
90102
* Codes below this, on any range, decode as range 3 at it so that an open circuit reads as open
91103
* ({@link SensorGSR#calibrateGsrDataToKOhmsWithOpenCircuitLimit}; range 3 only until DEV-1070).
92-
* It has to be the first code above the 0.5 V amplifier reference that
93-
* {@link SensorGSR#calibrateGsrDataToKOhmsUsingAmplifierEq} divides by: 0.5 V is code 1137.5 at
94-
* this front end's 1.8 V full scale, so 1138, as 683 is at the Shimmer3's 3.0 V. Anything lower
95-
* decodes to a negative resistance, which the auto-range nudge floors at 8 kOhm, reading an open
96-
* circuit as 125 uS. It was 1134, the last code below 0.4986 V, until DEV-1067.
104+
* It has to be above the {@link #VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE 0.4986 V}
105+
* reference (code 1134.3 at this front end's 1.8 V full scale). Anything at or below it decodes
106+
* to a negative resistance, which the auto-range nudge floors at 8 kOhm, reading an open circuit
107+
* as 125 uS. It was 1134 until DEV-1067, one code short.
108+
* <p>
109+
* 1138 is the first code above 0.5 V, which this decode divided by until the reference was
110+
* corrected. It is kept, rather than lowered to 1135, because it is the value the C# API and the
111+
* web SDK use, and because codes 1135-1137 are an open circuit too: on range 3 they decode to
112+
* 0.7-3.0 GOhm.
97113
*/
98114
public static final int VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3 = 1138;
99115

@@ -133,6 +149,7 @@ public SensorGSRVerisense(ShimmerVerObject svo) {
133149
|| svo.getHardwareVersion() == HW_ID.VERISENSE_IMU) {
134150
setCurrentGsrRefResistorsKohms(VERISENSE_PULSE_PLUS_GSR_REF_RESISTORS_KOHMS);
135151
setCurrentGsrUncalLimitRange3(VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3);
152+
setCurrentGsrAmplifierRefVoltage(VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE);
136153
}
137154
}
138155
//--------- Constructors for this class end --------------

‎ShimmerDriver/src/test/java/com/shimmerresearch/sensors/API_00019_GsrBelowReferenceReadsOpen.java‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,32 @@ public class API_00019_GsrBelowReferenceReadsOpen {
5858

5959
private enum FrontEnd {
6060
SHIMMER3(MICROCONTROLLER_ADC_PROPERTIES.SHIMMER2R3_3V0, SensorGSR.SHIMMER3_GSR_REF_RESISTORS_KOHMS,
61-
SensorGSR.GSR_UNCAL_LIMIT_RANGE3),
61+
SensorGSR.GSR_UNCAL_LIMIT_RANGE3, SensorGSR.GSR_AMPLIFIER_REF_VOLTAGE),
6262
VERISENSE_GSR_PLUS(MICROCONTROLLER_ADC_PROPERTIES.VERISENSE_3V0, SensorGSR.SHIMMER3_GSR_REF_RESISTORS_KOHMS,
63-
SensorGSR.GSR_UNCAL_LIMIT_RANGE3),
63+
SensorGSR.GSR_UNCAL_LIMIT_RANGE3, SensorGSR.GSR_AMPLIFIER_REF_VOLTAGE),
6464
VERISENSE_GEN2(MICROCONTROLLER_ADC_PROPERTIES.VERISENSE_1V8,
6565
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_REF_RESISTORS_KOHMS,
66-
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3);
66+
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3,
67+
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE);
6768

6869
final MICROCONTROLLER_ADC_PROPERTIES adc;
6970
final double[] refResistorsKohms;
7071
final int limit;
72+
final double refVoltage;
7173

72-
FrontEnd(MICROCONTROLLER_ADC_PROPERTIES adc, double[] refResistorsKohms, int limit) {
74+
FrontEnd(MICROCONTROLLER_ADC_PROPERTIES adc, double[] refResistorsKohms, int limit, double refVoltage) {
7375
this.adc = adc;
7476
this.refResistorsKohms = refResistorsKohms;
7577
this.limit = limit;
78+
this.refVoltage = refVoltage;
7679
}
7780

7881
double equation(int code, int range) {
79-
return SensorGSR.calibrateGsrDataToKOhmsUsingAmplifierEq(code, range, adc, refResistorsKohms);
82+
return SensorGSR.calibrateGsrDataToKOhmsUsingAmplifierEq(code, range, adc, refResistorsKohms, refVoltage);
8083
}
8184

8285
double withOpenCircuitLimit(int code, int range) {
83-
return SensorGSR.calibrateGsrDataToKOhmsWithOpenCircuitLimit(code, range, limit, adc, refResistorsKohms);
86+
return SensorGSR.calibrateGsrDataToKOhmsWithOpenCircuitLimit(code, range, limit, adc, refResistorsKohms, refVoltage);
8487
}
8588

8689
double openCircuitKohms() {
@@ -104,19 +107,22 @@ public void test001_everyCodeBelowTheLimitDecodesAsRange3AtTheLimit() {
104107
}
105108

106109
/**
107-
* The limit is the first code above the 0.5 V reference on every front end, so the rule moves
108-
* exactly the codes that the equation decoded to a negative resistance, which are the samples
109-
* that ASM-2156's 8 kOhm floor already moved. Every other code decodes as it always has.
110+
* The rule moves only codes that were an open circuit already. On the Shimmer3, the ShimmerGQ and
111+
* the SR62 the limit is the first code above the 0.5 V reference, so these are exactly the codes
112+
* that decoded to a negative resistance, the samples ASM-2156's 8 kOhm floor already moved. On
113+
* gen-2 the reference is 0.4986 V (code 1134.3) and the limit 1138, so codes 1135-1137 move too;
114+
* they decode above the top of range 3 on every range. Every other code decodes as it always has.
110115
*/
111116
@Test
112-
public void test002_onlyCodesTheEquationDecodedNegativeChange() {
117+
public void test002_onlyCodesThatWereAlreadyOpenChange() {
113118
for (FrontEnd frontEnd : FrontEnd.values()) {
114119
for (int range = 0; range <= 3; range++) {
115120
for (int code = 0; code <= 4095; code++) {
116121
String context = frontEnd + " range " + range + " code " + code;
117122
double equation = frontEnd.equation(code, range);
118123
if (code < frontEnd.limit) {
119-
assertTrue(context + " decodes to " + equation + " kOhm", equation < 0);
124+
assertTrue(context + " decodes to " + equation + " kOhm",
125+
equation < 0 || equation > WINDOWS_KOHMS[3][1]);
120126
} else {
121127
assertTrue(context + " decodes to " + equation + " kOhm", equation > 0);
122128
assertEquals(context, equation, frontEnd.withOpenCircuitLimit(code, range), 0.0);

‎ShimmerDriver/src/test/java/com/shimmerresearch/verisense/sensors/API_00015_VerisenseGsrOpenCircuitLimit.java‎

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.shimmerresearch.verisense.sensors;
22

3+
import static org.junit.Assert.assertEquals;
34
import static org.junit.Assert.assertNotNull;
45
import static org.junit.Assert.assertTrue;
56

@@ -12,6 +13,7 @@
1213
import com.shimmerresearch.driverUtilities.ExpansionBoardDetails;
1314
import com.shimmerresearch.driverUtilities.SensorDetails;
1415
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID;
16+
import com.shimmerresearch.sensors.SensorADC;
1517
import com.shimmerresearch.sensors.SensorADC.MICROCONTROLLER_ADC_PROPERTIES;
1618
import com.shimmerresearch.sensors.SensorGSR;
1719
import com.shimmerresearch.sensors.SensorGSR.ObjectClusterSensorName;
@@ -25,10 +27,11 @@
2527
* With nothing across the electrodes the amplifier's gain falls to one and its output settles on
2628
* the reference, so the ADC reads a few codes either side of it. The decode raises every range-3
2729
* code below {@link SensorGSRVerisense#VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3} to that limit,
28-
* which only works if the limit is itself above the reference. It was 1134, below the 0.5 V this
29-
* decode divides by (code 1137.5 at 1.8 V), so codes 1134 to 1137 decoded to a negative
30-
* resistance: auto-range floored it at 8 kOhm, the highest conductance the device can report, and
31-
* fixed range 3 pinned it to 680 kOhm, the bottom of the range. On an SR68-9 with the electrodes
30+
* which only works if the limit is itself above the reference. It was 1134, below the reference
31+
* (0.4986 V, code 1134.3 at 1.8 V; this decode divided by 0.5 V, code 1137.5, until the reference
32+
* was corrected), so the clamped codes decoded to a negative resistance: auto-range floored it at
33+
* 8 kOhm, the highest conductance the device can report, and fixed range 3 pinned it to 680 kOhm,
34+
* the bottom of the range. On an SR68-9 with the electrodes
3235
* open (DEV-793 dataset B6, ASM_PC Test_056) the range-3 codes peak at 1126-1136, so most of an
3336
* open-circuit recording read 125 uS.
3437
* <p>
@@ -65,14 +68,50 @@ public void test004_sr61FixedRange3OpenCircuitReadsOpen() {
6568
}
6669

6770
/**
68-
* The limit is exactly the first code above the reference: one lower and the clamp produces
69-
* negative resistances again, any higher and it overwrites codes that decode properly.
71+
* The limit has to clear the amplifier reference, or the clamp produces negative resistances
72+
* again, as the old limit of 1134 did. It is the first code above 0.5 V, the value the C# API and
73+
* the web SDK use too; the codes between the reference and the limit are an open circuit anyway.
7074
*/
7175
@Test
72-
public void test005_limitIsTheFirstCodeAboveTheAmplifierReference() {
76+
public void test005_limitClearsTheAmplifierReference() {
7377
int limit = SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3;
7478
assertTrue(calibrateRange3(limit) > 0);
75-
assertTrue(calibrateRange3(limit - 1) < 0);
79+
assertTrue(calibrateRange3(1134) < 0);
80+
assertTrue(volts(limit) > 0.5 && volts(limit - 1) < 0.5);
81+
for (int code = limit - 3; code < limit; code++) {
82+
assertTrue("code " + code, calibrateRange3(code) > RANGE_3_MAX_KOHMS);
83+
}
84+
}
85+
86+
/** A 261k/100k divider off the 1.8 V rail: the value the C# API and the web SDK round to 0.4986 V. */
87+
@Test
88+
public void test006_amplifierReferenceIsTheDividerVoltage() {
89+
assertEquals(0.4986, SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE, 0.00005);
90+
assertEquals(SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE,
91+
createSensorGsr(HW_ID.VERISENSE_PULSE_PLUS, 9).getCurrentGsrAmplifierRefVoltage(), 0.0);
92+
assertEquals(SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE,
93+
createSensorGsr(HW_ID.VERISENSE_IMU, 5).getCurrentGsrAmplifierRefVoltage(), 0.0);
94+
assertEquals(SensorGSR.GSR_AMPLIFIER_REF_VOLTAGE,
95+
createSensorGsr(HW_ID.VERISENSE_GSR_PLUS, 1).getCurrentGsrAmplifierRefVoltage(), 0.0);
96+
}
97+
98+
/**
99+
* A real 2.7 MOhm load on an SR68-9 (DEV-793 dataset B4d, median code about 1850 on range 3)
100+
* decodes as the C# API and the web SDK decode it, 2758 kOhm, and closer to the load than the old
101+
* 0.5 V reference put it (2778 kOhm).
102+
*/
103+
@Test
104+
public void test007_realLoadDecodesAsTheOtherApisDo() {
105+
SensorGSRVerisense sensorGsr = createSensorGsr(HW_ID.VERISENSE_PULSE_PLUS, 9);
106+
sensorGsr.setGsrRange(GSR_RANGE.AUTO_RANGE);
107+
double kOhms = decodeRange3Sample(sensorGsr, 1850)
108+
.getFormatClusterValue(ObjectClusterSensorName.GSR_RESISTANCE, CHANNEL_TYPE.CAL.toString());
109+
110+
double otherApis = SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_REF_RESISTORS_KOHMS[RANGE_3] / (volts(1850) / 0.4986 - 1.0);
111+
assertEquals(otherApis, kOhms, otherApis * 1e-4);
112+
double oldReference = SensorGSR.calibrateGsrDataToKOhmsUsingAmplifierEq(1850, RANGE_3,
113+
MICROCONTROLLER_ADC_PROPERTIES.VERISENSE_1V8, SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_REF_RESISTORS_KOHMS);
114+
assertTrue(kOhms + " vs " + oldReference, Math.abs(kOhms - 2700.0) < Math.abs(oldReference - 2700.0));
76115
}
77116

78117
private static void assertOpenCircuitReadsOpen(int hwId, int hwRev, GSR_RANGE gsrRange) {
@@ -114,6 +153,11 @@ private static ObjectCluster decodeRange3Sample(SensorGSRVerisense sensorGsr, in
114153
private static double calibrateRange3(int code) {
115154
return SensorGSR.calibrateGsrDataToKOhmsUsingAmplifierEq(code, RANGE_3,
116155
MICROCONTROLLER_ADC_PROPERTIES.VERISENSE_1V8,
117-
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_REF_RESISTORS_KOHMS);
156+
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_REF_RESISTORS_KOHMS,
157+
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_AMPLIFIER_REF_VOLTAGE);
158+
}
159+
160+
private static double volts(int code) {
161+
return SensorADC.calibrateAdcChannelToVolts(code, MICROCONTROLLER_ADC_PROPERTIES.VERISENSE_1V8);
118162
}
119163
}

0 commit comments

Comments
 (0)