repo time
Dependencies: mbed MAX14720 MAX30205 USBDevice
HspGuiSourceV301/HSPGui/DeviceDescriptions/AccelDevice.cs@20:6d2af70c92ab, 2021-04-06 (annotated)
- Committer:
- darienf
- Date:
- Tue Apr 06 06:41:40 2021 +0000
- Revision:
- 20:6d2af70c92ab
another repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
darienf | 20:6d2af70c92ab | 1 | using System; |
darienf | 20:6d2af70c92ab | 2 | using System.Collections.Generic; |
darienf | 20:6d2af70c92ab | 3 | using System.Linq; |
darienf | 20:6d2af70c92ab | 4 | using System.Text; |
darienf | 20:6d2af70c92ab | 5 | |
darienf | 20:6d2af70c92ab | 6 | namespace Maxim.MAX30101GUI.DeviceDescriptions |
darienf | 20:6d2af70c92ab | 7 | { |
darienf | 20:6d2af70c92ab | 8 | /// <summary> |
darienf | 20:6d2af70c92ab | 9 | /// This class holds the properties of the ADC selected |
darienf | 20:6d2af70c92ab | 10 | /// </summary> |
darienf | 20:6d2af70c92ab | 11 | public class AccelDevice |
darienf | 20:6d2af70c92ab | 12 | { |
darienf | 20:6d2af70c92ab | 13 | string name = "MAX11270"; |
darienf | 20:6d2af70c92ab | 14 | //public string[] parts = {"MAX11270"};//, "MAX11271", "MAX11280"}; |
darienf | 20:6d2af70c92ab | 15 | int resolution = 24; |
darienf | 20:6d2af70c92ab | 16 | bool bipolar = true; |
darienf | 20:6d2af70c92ab | 17 | bool twosComp = true; |
darienf | 20:6d2af70c92ab | 18 | double VREFExternal = 2.5; |
darienf | 20:6d2af70c92ab | 19 | |
darienf | 20:6d2af70c92ab | 20 | public double gain; //calculated |
darienf | 20:6d2af70c92ab | 21 | public int offset; //calculated |
darienf | 20:6d2af70c92ab | 22 | //public double CNVSTime = 1000;//us |
darienf | 20:6d2af70c92ab | 23 | |
darienf | 20:6d2af70c92ab | 24 | //public double[] cont_SINC;// = { 1.9, 3.9, 7.8, 15.6, 31.2, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000 }; |
darienf | 20:6d2af70c92ab | 25 | //public double[] single_cont = { 50, 62.5, 100, 125, 200, 250, 400, 500, 800, 1000, 1600, 2000, 3200, 4000, 6400, 12800 }; |
darienf | 20:6d2af70c92ab | 26 | //public double[] cont_FIR = { 125, 250, 500, 1000, 2000, 4000, 8000, 16000 }; |
darienf | 20:6d2af70c92ab | 27 | public List<double> cont_SINC = new List<double>(); |
darienf | 20:6d2af70c92ab | 28 | public List<double> single_cont = new List<double>(); |
darienf | 20:6d2af70c92ab | 29 | public List<double> cont_FIR = new List<double>(); |
darienf | 20:6d2af70c92ab | 30 | |
darienf | 20:6d2af70c92ab | 31 | public bool FIRon = false; |
darienf | 20:6d2af70c92ab | 32 | |
darienf | 20:6d2af70c92ab | 33 | //public string DeviceName; |
darienf | 20:6d2af70c92ab | 34 | public List<RegisterDescription> Registers; |
darienf | 20:6d2af70c92ab | 35 | public int RegisterCount; |
darienf | 20:6d2af70c92ab | 36 | |
darienf | 20:6d2af70c92ab | 37 | //Registers |
darienf | 20:6d2af70c92ab | 38 | public RegisterDescription STAT; |
darienf | 20:6d2af70c92ab | 39 | public RegisterDescription CTRL1; |
darienf | 20:6d2af70c92ab | 40 | public RegisterDescription CTRL2; |
darienf | 20:6d2af70c92ab | 41 | public RegisterDescription CTRL3; |
darienf | 20:6d2af70c92ab | 42 | public RegisterDescription CTRL4; |
darienf | 20:6d2af70c92ab | 43 | public RegisterDescription CTRL5; |
darienf | 20:6d2af70c92ab | 44 | public RegisterDescription DATA; |
darienf | 20:6d2af70c92ab | 45 | public RegisterDescription SOC_SPI; |
darienf | 20:6d2af70c92ab | 46 | public RegisterDescription SGC_SPI; |
darienf | 20:6d2af70c92ab | 47 | public RegisterDescription SCOC_SPI; |
darienf | 20:6d2af70c92ab | 48 | public RegisterDescription SCGC_SPI; |
darienf | 20:6d2af70c92ab | 49 | public RegisterDescription HPF; |
darienf | 20:6d2af70c92ab | 50 | public RegisterDescription SOC_ADC; |
darienf | 20:6d2af70c92ab | 51 | public RegisterDescription SGC_ADC; |
darienf | 20:6d2af70c92ab | 52 | public RegisterDescription SCOC_ADC; |
darienf | 20:6d2af70c92ab | 53 | public RegisterDescription SCGC_ADC; |
darienf | 20:6d2af70c92ab | 54 | |
darienf | 20:6d2af70c92ab | 55 | public List<BitInfo> CommandMODE0Bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 56 | public List<BitInfo> CommandMODE1Bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 57 | |
darienf | 20:6d2af70c92ab | 58 | public AccelDevice() |
darienf | 20:6d2af70c92ab | 59 | { |
darienf | 20:6d2af70c92ab | 60 | GetDefault(); |
darienf | 20:6d2af70c92ab | 61 | } |
darienf | 20:6d2af70c92ab | 62 | |
darienf | 20:6d2af70c92ab | 63 | /// Get the default structure and values of the Register map |
darienf | 20:6d2af70c92ab | 64 | /// |
darienf | 20:6d2af70c92ab | 65 | public void GetDefault() |
darienf | 20:6d2af70c92ab | 66 | { |
darienf | 20:6d2af70c92ab | 67 | if (name == "MAX11214") |
darienf | 20:6d2af70c92ab | 68 | { |
darienf | 20:6d2af70c92ab | 69 | cont_SINC.AddRange(new double[] { 0.95, 1.9, 3.9, 7.8, 15.6, 31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000 }); |
darienf | 20:6d2af70c92ab | 70 | single_cont.AddRange(new double[] { 25, 31.25, 50, 62.5, 100, 125, 200, 250, 400, 500, 800, 1000, 1600, 2000, 3200, 6400 }); |
darienf | 20:6d2af70c92ab | 71 | cont_FIR.AddRange(new double[] { 62.5, 125, 250, 500, 1000, 2000, 4000, 8000 }); |
darienf | 20:6d2af70c92ab | 72 | } |
darienf | 20:6d2af70c92ab | 73 | else//MAX11216, MAX11270 |
darienf | 20:6d2af70c92ab | 74 | { |
darienf | 20:6d2af70c92ab | 75 | cont_SINC.AddRange(new double[] { 1.9, 3.9, 7.8, 15.6, 31.2, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000 }); |
darienf | 20:6d2af70c92ab | 76 | single_cont.AddRange(new double[] { 50, 62.5, 100, 125, 200, 250, 400, 500, 800, 1000, 1600, 2000, 3200, 4000, 6400, 12800 }); |
darienf | 20:6d2af70c92ab | 77 | cont_FIR.AddRange(new double[] { 125, 250, 500, 1000, 2000, 4000, 8000, 16000 }); |
darienf | 20:6d2af70c92ab | 78 | } |
darienf | 20:6d2af70c92ab | 79 | |
darienf | 20:6d2af70c92ab | 80 | //SetFullScaleAndOffset(); |
darienf | 20:6d2af70c92ab | 81 | |
darienf | 20:6d2af70c92ab | 82 | Registers = new List<RegisterDescription>(); |
darienf | 20:6d2af70c92ab | 83 | |
darienf | 20:6d2af70c92ab | 84 | List<BitInfo> R0bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 85 | List<BitInfo> R1bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 86 | List<BitInfo> R2bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 87 | List<BitInfo> R3bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 88 | List<BitInfo> R4bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 89 | List<BitInfo> R5bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 90 | List<BitInfo> R6bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 91 | List<BitInfo> R7bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 92 | List<BitInfo> R8bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 93 | List<BitInfo> R9bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 94 | List<BitInfo> R10bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 95 | List<BitInfo> R11bits = new List<BitInfo>(); |
darienf | 20:6d2af70c92ab | 96 | |
darienf | 20:6d2af70c92ab | 97 | //bit description for STAT |
darienf | 20:6d2af70c92ab | 98 | R0bits.Add(new BitInfo() { bitIndex = "B[0]", name = "RDY", Description = "Ready: 1 = new conversion result is ready" }); |
darienf | 20:6d2af70c92ab | 99 | R0bits.Add(new BitInfo() { bitIndex = "B[1]", name = "MSTAT", Description = "Measurement Status: 1 = modulator is busy measuring" }); |
darienf | 20:6d2af70c92ab | 100 | R0bits.Add(new BitInfo() { bitIndex = "B[2]", name = "DOR", Description = "Data Overrange: 1 = data out of range" }); |
darienf | 20:6d2af70c92ab | 101 | R0bits.Add(new BitInfo() { bitIndex = "B[3]", name = "SYSGOR", Description = "System Gain Overrange: 1 = system gain out of range" }); |
darienf | 20:6d2af70c92ab | 102 | R0bits.Add(new BitInfo() { bitIndex = "B[7:4]", name = "RATE[3:0]", Description = "Data Rate: Data rate of previous conversion" }); |
darienf | 20:6d2af70c92ab | 103 | R0bits.Add(new BitInfo() { bitIndex = "B[8]", name = "AOR", Description = "Analog Overrange: input voltage > 1.3 x full scale" }); |
darienf | 20:6d2af70c92ab | 104 | R0bits.Add(new BitInfo() { bitIndex = "B[9]", name = "RDERR", Description = "Data Read Error: 1 = data read while data written" }); |
darienf | 20:6d2af70c92ab | 105 | R0bits.Add(new BitInfo() { bitIndex = "B[11:10]", name = "PSTAT[1:0]", Description = "Power Status\r\n00 = ADC is converting\r\n01 = powered down\r\n10 = standby" }); |
darienf | 20:6d2af70c92ab | 106 | R0bits.Add(new BitInfo() { bitIndex = "B[13:12]", name = "Reserved", Description = "-" }); |
darienf | 20:6d2af70c92ab | 107 | R0bits.Add(new BitInfo() { bitIndex = "B[14]", name = "ERROR", Description = "Error: 1 = CAL[1:0] set to invalid setting of 11" }); |
darienf | 20:6d2af70c92ab | 108 | R0bits.Add(new BitInfo() { bitIndex = "B[15]", name = "INRESET", Description = "In Reset: 1 = part is in reset mode" }); |
darienf | 20:6d2af70c92ab | 109 | |
darienf | 20:6d2af70c92ab | 110 | //bit description for CTRL1 |
darienf | 20:6d2af70c92ab | 111 | R1bits.Add(new BitInfo() { bitIndex = "B[0]", name = "CONTSC", Description = "Continuous Single Cycle: 1 = continuous conversion" }); |
darienf | 20:6d2af70c92ab | 112 | R1bits.Add(new BitInfo() { bitIndex = "B[1]", name = "SCYCLE", Description = "Single Cycle: 1 = single cycle mode" }); |
darienf | 20:6d2af70c92ab | 113 | R1bits.Add(new BitInfo() { bitIndex = "B[2]", name = "FORMAT", Description = "Format: 1 = offset binary, 0 = two's complement" }); |
darienf | 20:6d2af70c92ab | 114 | R1bits.Add(new BitInfo() { bitIndex = "B[3]", name = "U/B", Description = "Input Range: 1 = unipolar, 0 = bipolar" }); |
darienf | 20:6d2af70c92ab | 115 | R1bits.Add(new BitInfo() { bitIndex = "B[5:4]", name = "PD[1:0]", Description = "Power State\r\n00 = normal\r\n01 = power down\r\n10 = standby\r\n11 = reset registers" }); |
darienf | 20:6d2af70c92ab | 116 | R1bits.Add(new BitInfo() { bitIndex = "B[6]", name = "SYNC", Description = "SYNC: 1 = continuous mode, 0 = pulse mode" }); |
darienf | 20:6d2af70c92ab | 117 | R1bits.Add(new BitInfo() { bitIndex = "B[7]", name = "EXTCK", Description = "Clock: 1 = external, 0 = internal" }); |
darienf | 20:6d2af70c92ab | 118 | |
darienf | 20:6d2af70c92ab | 119 | //bit description for CTRL2 |
darienf | 20:6d2af70c92ab | 120 | R2bits.Add(new BitInfo() { bitIndex = "B[2:0]", name = "PGA[2:0]", Description = "PGA Gain\r\n000 = x1 100 = x16\r\n001 = x2 101 = x32\r\n010 = x4 110 = x64\r\n011 = x8 111 = x128" }); |
darienf | 20:6d2af70c92ab | 121 | R2bits.Add(new BitInfo() { bitIndex = "B[3]", name = "PGAEN", Description = "PGA Enable: 1 = enable" }); |
darienf | 20:6d2af70c92ab | 122 | R2bits.Add(new BitInfo() { bitIndex = "B[4]", name = "LPMODE", Description = "PGA Low Power: 1 = low power" }); |
darienf | 20:6d2af70c92ab | 123 | R2bits.Add(new BitInfo() { bitIndex = "B[5]", name = "BUFEN", Description = "Input Buffer Enable: 1 = enable" }); |
darienf | 20:6d2af70c92ab | 124 | R2bits.Add(new BitInfo() { bitIndex = "B[7:6]", name = "DGAIN[1:0]", Description = "Modulator Digital Gain\r\n00 = x1\r\n01 = x2\r\n10 = x4\r\n11 = x8" }); |
darienf | 20:6d2af70c92ab | 125 | |
darienf | 20:6d2af70c92ab | 126 | //bit description for CTRL3 |
darienf | 20:6d2af70c92ab | 127 | if (name == "MAX11270") |
darienf | 20:6d2af70c92ab | 128 | { |
darienf | 20:6d2af70c92ab | 129 | R3bits.Add(new BitInfo() { bitIndex = "B[1:0]", name = "Reserved", Description = "-" }); |
darienf | 20:6d2af70c92ab | 130 | R3bits.Add(new BitInfo() { bitIndex = "B[2]", name = "Reserved", Description = "-" }); |
darienf | 20:6d2af70c92ab | 131 | } |
darienf | 20:6d2af70c92ab | 132 | else |
darienf | 20:6d2af70c92ab | 133 | { |
darienf | 20:6d2af70c92ab | 134 | R3bits.Add(new BitInfo() { bitIndex = "B[1:0]", name = "FILT[1:0]", Description = "Filter Control\r\n0x = SINC\r\n10 = FIR\r\n11 = IIR" }); |
darienf | 20:6d2af70c92ab | 135 | R3bits.Add(new BitInfo() { bitIndex = "B[2]", name = "PHASE", Description = "FIR Phase: 1 = minimum, 0 = linear" }); |
darienf | 20:6d2af70c92ab | 136 | } |
darienf | 20:6d2af70c92ab | 137 | |
darienf | 20:6d2af70c92ab | 138 | R3bits.Add(new BitInfo() { bitIndex = "B[3]", name = "DATA32", Description = "32-bit Data: 1 = 32-bit data, 0 = 24-bit data" }); |
darienf | 20:6d2af70c92ab | 139 | R3bits.Add(new BitInfo() { bitIndex = "B[4]", name = "MODBITS", Description = "Modulator Output Mode Enable: 1 = enable" }); |
darienf | 20:6d2af70c92ab | 140 | R3bits.Add(new BitInfo() { bitIndex = "B[5]", name = "ENMSYNC", Description = "Modulator SYNC Pulse Enable: 1 = enable" }); |
darienf | 20:6d2af70c92ab | 141 | R3bits.Add(new BitInfo() { bitIndex = "B[7:6]", name = "Reserved", Description = "-" }); |
darienf | 20:6d2af70c92ab | 142 | |
darienf | 20:6d2af70c92ab | 143 | |
darienf | 20:6d2af70c92ab | 144 | //bit description for CTRL4 |
darienf | 20:6d2af70c92ab | 145 | R4bits.Add(new BitInfo() { bitIndex = "B[0]", name = "DIO1", Description = "GPIO1 Bit Value" }); |
darienf | 20:6d2af70c92ab | 146 | R4bits.Add(new BitInfo() { bitIndex = "B[1]", name = "DIO2", Description = "GPIO2 Bit Value" }); |
darienf | 20:6d2af70c92ab | 147 | R4bits.Add(new BitInfo() { bitIndex = "B[2]", name = "DIO3", Description = "GPIO3 Bit Value" }); |
darienf | 20:6d2af70c92ab | 148 | R4bits.Add(new BitInfo() { bitIndex = "B[3]", name = "Reserved", Description = "-" }); |
darienf | 20:6d2af70c92ab | 149 | R4bits.Add(new BitInfo() { bitIndex = "B[4]", name = "DIR1", Description = "GPIO1 Direction: 1 = output, 0 = input" }); |
darienf | 20:6d2af70c92ab | 150 | R4bits.Add(new BitInfo() { bitIndex = "B[5]", name = "DIR2", Description = "GPIO2 Direction: 1 = output, 0 = input" }); |
darienf | 20:6d2af70c92ab | 151 | R4bits.Add(new BitInfo() { bitIndex = "B[6]", name = "DIR3", Description = "GPIO3 Direction: 1 = output, 0 = input" }); |
darienf | 20:6d2af70c92ab | 152 | R4bits.Add(new BitInfo() { bitIndex = "B[7]", name = "Reserved", Description = "-" }); |
darienf | 20:6d2af70c92ab | 153 | |
darienf | 20:6d2af70c92ab | 154 | //bit description for CTRL5 |
darienf | 20:6d2af70c92ab | 155 | R5bits.Add(new BitInfo() { bitIndex = "B[0]", name = "NOSCO", Description = "Disable Self Calibration Offset" }); |
darienf | 20:6d2af70c92ab | 156 | R5bits.Add(new BitInfo() { bitIndex = "B[1]", name = "NOSCG", Description = "Disable Self Calibration Gain" }); |
darienf | 20:6d2af70c92ab | 157 | R5bits.Add(new BitInfo() { bitIndex = "B[2]", name = "NOSYSO", Description = "Disable System Calibration Offset" }); |
darienf | 20:6d2af70c92ab | 158 | R5bits.Add(new BitInfo() { bitIndex = "B[3]", name = "NOSYSG", Description = "Disable System Calibration Gain" }); |
darienf | 20:6d2af70c92ab | 159 | R5bits.Add(new BitInfo() { bitIndex = "B[5:4]", name = "Reserved", Description = "-" }); |
darienf | 20:6d2af70c92ab | 160 | R5bits.Add(new BitInfo() { bitIndex = "B[7:6]", name = "CAL[1:0]", Description = "Calibration\r\n00 = Perform Self Calibration\r\n01 = Perform System Offset Calibration\r\n10 = Perform System Gain Calibration" }); |
darienf | 20:6d2af70c92ab | 161 | |
darienf | 20:6d2af70c92ab | 162 | //bit description for Data |
darienf | 20:6d2af70c92ab | 163 | R6bits.Add(new BitInfo() { bitIndex = "B[31:0]", name = "DATA", Description = "32-Bit Mode: MSB = bit31, LSB = bit0" }); |
darienf | 20:6d2af70c92ab | 164 | R6bits.Add(new BitInfo() { bitIndex = "B[31:8]", name = "DATA", Description = "24-Bit Mode: MSB = bit31, LSB = bit8" }); |
darienf | 20:6d2af70c92ab | 165 | |
darienf | 20:6d2af70c92ab | 166 | //bit description for SOC |
darienf | 20:6d2af70c92ab | 167 | R7bits.Add(new BitInfo() { bitIndex = "B[23:0]", name = "SOC[23:0]", Description = "System Offset Calibration: two's complement format" }); |
darienf | 20:6d2af70c92ab | 168 | |
darienf | 20:6d2af70c92ab | 169 | //bit description for SGC |
darienf | 20:6d2af70c92ab | 170 | R8bits.Add(new BitInfo() { bitIndex = "B[23:0]", name = "SGC[23:0]", Description = "System Gain Calibration: two's complement format" }); |
darienf | 20:6d2af70c92ab | 171 | |
darienf | 20:6d2af70c92ab | 172 | //bit description for SCOC |
darienf | 20:6d2af70c92ab | 173 | R9bits.Add(new BitInfo() { bitIndex = "B[23:0]", name = "SCOC[23:0]", Description = "Self Offset Calibration: two's complement format" }); |
darienf | 20:6d2af70c92ab | 174 | |
darienf | 20:6d2af70c92ab | 175 | //bit description for SCGC |
darienf | 20:6d2af70c92ab | 176 | R10bits.Add(new BitInfo() { bitIndex = "B[23:0]", name = "SCGC[23:0]", Description = "Self Gain Calibration: two's complement format" }); |
darienf | 20:6d2af70c92ab | 177 | |
darienf | 20:6d2af70c92ab | 178 | //bit description for HPF |
darienf | 20:6d2af70c92ab | 179 | R11bits.Add(new BitInfo() { bitIndex = "B[16:0]", name = "HPF[16:0]", Description = "High Pass Filter: corner frequency" }); |
darienf | 20:6d2af70c92ab | 180 | |
darienf | 20:6d2af70c92ab | 181 | //add information to registers |
darienf | 20:6d2af70c92ab | 182 | STAT = new RegisterDescription() { Address = 0x00, Name = "STAT", Description = "Status", ReadOnly = true, numBytes = 2, Value = 0x0000, BitInfo = R0bits }; |
darienf | 20:6d2af70c92ab | 183 | CTRL1 = new RegisterDescription() { Address = 0x01, Name = "CTRL1", Description = "Control 1", ReadOnly = false, numBytes = 1, Value = 0x02, BitInfo = R1bits }; |
darienf | 20:6d2af70c92ab | 184 | CTRL2 = new RegisterDescription() { Address = 0x02, Name = "CTRL2", Description = "Control 2", ReadOnly = false, numBytes = 1, Value = 0x00, BitInfo = R2bits }; |
darienf | 20:6d2af70c92ab | 185 | CTRL3 = new RegisterDescription() { Address = 0x03, Name = "CTRL3", Description = "Control 3", ReadOnly = false, numBytes = 1, Value = 0x61, BitInfo = R3bits }; |
darienf | 20:6d2af70c92ab | 186 | CTRL4 = new RegisterDescription() { Address = 0x04, Name = "CTRL4", Description = "Control 4", ReadOnly = false, numBytes = 1, Value = 0x08, BitInfo = R4bits }; |
darienf | 20:6d2af70c92ab | 187 | CTRL5 = new RegisterDescription() { Address = 0x05, Name = "CTRL5", Description = "Control 5", ReadOnly = false, numBytes = 1, Value = 0x0C, BitInfo = R5bits }; |
darienf | 20:6d2af70c92ab | 188 | DATA = new RegisterDescription() { Address = 0x06, Name = "DATA", Description = "Data", ReadOnly = true, numBytes = 4, Value = 0x00000000, BitInfo = R6bits }; |
darienf | 20:6d2af70c92ab | 189 | SOC_SPI = new RegisterDescription() { Address = 0x07, Name = "SOC_SPI", Description = "SPI System Offset Calibration", ReadOnly = false, numBytes = 3, Value = 0x000000, BitInfo = R7bits }; |
darienf | 20:6d2af70c92ab | 190 | SGC_SPI = new RegisterDescription() { Address = 0x08, Name = "SGC_SPI", Description = "SPI System Gain Calibration", ReadOnly = false, numBytes = 3, Value = 0x7FFFFF, BitInfo = R8bits }; |
darienf | 20:6d2af70c92ab | 191 | SCOC_SPI = new RegisterDescription() { Address = 0x09, Name = "SCOC_SPI", Description = "SPI Self Offset Calibration", ReadOnly = false, numBytes = 3, Value = 0x000000, BitInfo = R9bits }; |
darienf | 20:6d2af70c92ab | 192 | SCGC_SPI = new RegisterDescription() { Address = 0x0A, Name = "SCGC_SPI", Description = "SPI Self Gain Calibration", ReadOnly = false, numBytes = 3, Value = 0xBF851B, BitInfo = R10bits }; |
darienf | 20:6d2af70c92ab | 193 | HPF = new RegisterDescription() { Address = 0x0B, Name = "HPF", Description = "High Pass Filter", ReadOnly = false, numBytes = 2, Value = 0x0000, BitInfo = R11bits }; |
darienf | 20:6d2af70c92ab | 194 | SOC_ADC = new RegisterDescription() { Address = 0x15, Name = "SOC_ADC", Description = "ADC System Offset Calibration", ReadOnly = true, numBytes = 3, Value = 0x000000, BitInfo = R7bits }; |
darienf | 20:6d2af70c92ab | 195 | SGC_ADC = new RegisterDescription() { Address = 0x16, Name = "SGC_ADC", Description = "ADC System Gain Calibration", ReadOnly = true, numBytes = 3, Value = 0x000000, BitInfo = R8bits }; |
darienf | 20:6d2af70c92ab | 196 | SCOC_ADC = new RegisterDescription() { Address = 0x17, Name = "SCOC_ADC", Description = "ADC Self Offset Calibration", ReadOnly = true, numBytes = 3, Value = 0x000000, BitInfo = R9bits }; |
darienf | 20:6d2af70c92ab | 197 | SCGC_ADC = new RegisterDescription() { Address = 0x18, Name = "SCGC_ADC", Description = "ADC Self Gain Calibration", ReadOnly = true, numBytes = 3, Value = 0x000000, BitInfo = R10bits }; |
darienf | 20:6d2af70c92ab | 198 | |
darienf | 20:6d2af70c92ab | 199 | //add registers to map |
darienf | 20:6d2af70c92ab | 200 | /* |
darienf | 20:6d2af70c92ab | 201 | Registers.Add(STAT); |
darienf | 20:6d2af70c92ab | 202 | Registers.Add(CTRL1); |
darienf | 20:6d2af70c92ab | 203 | Registers.Add(CTRL2); |
darienf | 20:6d2af70c92ab | 204 | Registers.Add(CTRL3); |
darienf | 20:6d2af70c92ab | 205 | Registers.Add(CTRL4); |
darienf | 20:6d2af70c92ab | 206 | Registers.Add(CTRL5); |
darienf | 20:6d2af70c92ab | 207 | Registers.Add(DATA); |
darienf | 20:6d2af70c92ab | 208 | Registers.Add(SOC_SPI); |
darienf | 20:6d2af70c92ab | 209 | Registers.Add(SGC_SPI); |
darienf | 20:6d2af70c92ab | 210 | Registers.Add(SCOC_SPI); |
darienf | 20:6d2af70c92ab | 211 | Registers.Add(SCGC_SPI); |
darienf | 20:6d2af70c92ab | 212 | |
darienf | 20:6d2af70c92ab | 213 | if (name != "MAX11270") |
darienf | 20:6d2af70c92ab | 214 | Registers.Add(HPF); |
darienf | 20:6d2af70c92ab | 215 | |
darienf | 20:6d2af70c92ab | 216 | Registers.Add(SOC_ADC); |
darienf | 20:6d2af70c92ab | 217 | Registers.Add(SGC_ADC); |
darienf | 20:6d2af70c92ab | 218 | Registers.Add(SCOC_ADC); |
darienf | 20:6d2af70c92ab | 219 | Registers.Add(SCGC_ADC); |
darienf | 20:6d2af70c92ab | 220 | */ |
darienf | 20:6d2af70c92ab | 221 | //STATUS_REG_AUX |
darienf | 20:6d2af70c92ab | 222 | for (int reg = 0; reg <= 0x3F; reg++) |
darienf | 20:6d2af70c92ab | 223 | { |
darienf | 20:6d2af70c92ab | 224 | Registers.Add(new RegisterDescription() { Address = (byte)reg, Name = RegisterNames[reg], Description = "ADC Self Gain Calibration", ReadOnly = true, numBytes = 1, Value = 0x000000, BitInfo = R10bits }); |
darienf | 20:6d2af70c92ab | 225 | } |
darienf | 20:6d2af70c92ab | 226 | RegisterCount = Registers.Count; |
darienf | 20:6d2af70c92ab | 227 | |
darienf | 20:6d2af70c92ab | 228 | |
darienf | 20:6d2af70c92ab | 229 | //bit description for command MODE 0 bits |
darienf | 20:6d2af70c92ab | 230 | CommandMODE0Bits.Add(new BitInfo() { bitIndex = "B[3:0]", name = "RATE[3:0]", Description = "Data Rate for conversion" }); |
darienf | 20:6d2af70c92ab | 231 | CommandMODE0Bits.Add(new BitInfo() { bitIndex = "B[4]", name = "IMPD", Description = "1 = sleep mode\r\n0 = normal" }); |
darienf | 20:6d2af70c92ab | 232 | CommandMODE0Bits.Add(new BitInfo() { bitIndex = "B[5]", name = "CAL", Description = "1 = perform calibration\r\n0 = no calibration" }); |
darienf | 20:6d2af70c92ab | 233 | CommandMODE0Bits.Add(new BitInfo() { bitIndex = "B[6]", name = "MODE", Description = "MODE = 0 to start conversion, power down or calibrate" }); |
darienf | 20:6d2af70c92ab | 234 | CommandMODE0Bits.Add(new BitInfo() { bitIndex = "B[7]", name = "START", Description = "START = 1" }); |
darienf | 20:6d2af70c92ab | 235 | |
darienf | 20:6d2af70c92ab | 236 | //bit description for command MODE 1 bits |
darienf | 20:6d2af70c92ab | 237 | CommandMODE1Bits.Add(new BitInfo() { bitIndex = "B[0]", name = "R/W", Description = "Read/Write bit:\r\n1 = read, 0 = write" }); |
darienf | 20:6d2af70c92ab | 238 | CommandMODE1Bits.Add(new BitInfo() { bitIndex = "B[5:1]", name = "RS[4:0]", Description = "Register address" }); |
darienf | 20:6d2af70c92ab | 239 | CommandMODE1Bits.Add(new BitInfo() { bitIndex = "B[6]", name = "MODE", Description = "MODE = 1 for register access mode" }); |
darienf | 20:6d2af70c92ab | 240 | CommandMODE1Bits.Add(new BitInfo() { bitIndex = "B[7]", name = "START", Description = "START = 1" }); |
darienf | 20:6d2af70c92ab | 241 | } |
darienf | 20:6d2af70c92ab | 242 | |
darienf | 20:6d2af70c92ab | 243 | public void ResetReigsters() |
darienf | 20:6d2af70c92ab | 244 | { |
darienf | 20:6d2af70c92ab | 245 | CTRL1.Value = 0x02; |
darienf | 20:6d2af70c92ab | 246 | CTRL2.Value = 0x00; |
darienf | 20:6d2af70c92ab | 247 | CTRL3.Value = 0x61; |
darienf | 20:6d2af70c92ab | 248 | CTRL4.Value = 0x08; |
darienf | 20:6d2af70c92ab | 249 | CTRL5.Value = 0x0C; |
darienf | 20:6d2af70c92ab | 250 | |
darienf | 20:6d2af70c92ab | 251 | HPF.Value = 0; |
darienf | 20:6d2af70c92ab | 252 | |
darienf | 20:6d2af70c92ab | 253 | SOC_SPI.Value = 0; |
darienf | 20:6d2af70c92ab | 254 | SGC_SPI.Value = 0x7FFFFF; |
darienf | 20:6d2af70c92ab | 255 | SCOC_SPI.Value = 0; |
darienf | 20:6d2af70c92ab | 256 | SCGC_SPI.Value = 0xBF851B; |
darienf | 20:6d2af70c92ab | 257 | |
darienf | 20:6d2af70c92ab | 258 | } |
darienf | 20:6d2af70c92ab | 259 | |
darienf | 20:6d2af70c92ab | 260 | String[] RegisterNames = { |
darienf | 20:6d2af70c92ab | 261 | "Reserved", |
darienf | 20:6d2af70c92ab | 262 | "Reserved", |
darienf | 20:6d2af70c92ab | 263 | "Reserved", |
darienf | 20:6d2af70c92ab | 264 | "Reserved", |
darienf | 20:6d2af70c92ab | 265 | "Reserved", |
darienf | 20:6d2af70c92ab | 266 | "Reserved", |
darienf | 20:6d2af70c92ab | 267 | "Reserved", |
darienf | 20:6d2af70c92ab | 268 | "STATUS_REG_AUX", |
darienf | 20:6d2af70c92ab | 269 | "Reserved", |
darienf | 20:6d2af70c92ab | 270 | "Reserved", |
darienf | 20:6d2af70c92ab | 271 | "Reserved", |
darienf | 20:6d2af70c92ab | 272 | "Reserved", |
darienf | 20:6d2af70c92ab | 273 | "OUT_TEMP_L", |
darienf | 20:6d2af70c92ab | 274 | "OUT_TEMP_H", |
darienf | 20:6d2af70c92ab | 275 | "INT_COUNTER_REG", |
darienf | 20:6d2af70c92ab | 276 | "WHO_AM_I", |
darienf | 20:6d2af70c92ab | 277 | "Reserved", |
darienf | 20:6d2af70c92ab | 278 | "Reserved", |
darienf | 20:6d2af70c92ab | 279 | "Reserved", |
darienf | 20:6d2af70c92ab | 280 | "Reserved", |
darienf | 20:6d2af70c92ab | 281 | "Reserved", |
darienf | 20:6d2af70c92ab | 282 | "Reserved", |
darienf | 20:6d2af70c92ab | 283 | "Reserved", |
darienf | 20:6d2af70c92ab | 284 | "Reserved", |
darienf | 20:6d2af70c92ab | 285 | "Reserved", |
darienf | 20:6d2af70c92ab | 286 | "Reserved", |
darienf | 20:6d2af70c92ab | 287 | "Reserved", |
darienf | 20:6d2af70c92ab | 288 | "Reserved", |
darienf | 20:6d2af70c92ab | 289 | "Reserved", |
darienf | 20:6d2af70c92ab | 290 | "Reserved", |
darienf | 20:6d2af70c92ab | 291 | "Reserved", |
darienf | 20:6d2af70c92ab | 292 | "TEMP_CFG_REG", |
darienf | 20:6d2af70c92ab | 293 | "CTRL_REG1", |
darienf | 20:6d2af70c92ab | 294 | "CTRL_REG2", |
darienf | 20:6d2af70c92ab | 295 | "CTRL_REG3", |
darienf | 20:6d2af70c92ab | 296 | "CTRL_REG4", |
darienf | 20:6d2af70c92ab | 297 | "CTRL_REG5", |
darienf | 20:6d2af70c92ab | 298 | "CTRL_REG6", |
darienf | 20:6d2af70c92ab | 299 | "REFERENCE", |
darienf | 20:6d2af70c92ab | 300 | "STATUS_REG2", |
darienf | 20:6d2af70c92ab | 301 | "OUT_X_L", |
darienf | 20:6d2af70c92ab | 302 | "OUT_X_H", |
darienf | 20:6d2af70c92ab | 303 | "OUT_Y_L", |
darienf | 20:6d2af70c92ab | 304 | "OUT_Y_H", |
darienf | 20:6d2af70c92ab | 305 | "OUT_Z_L", |
darienf | 20:6d2af70c92ab | 306 | "OUT_Z_H", |
darienf | 20:6d2af70c92ab | 307 | "FIFO_CTRL_REG", |
darienf | 20:6d2af70c92ab | 308 | "FIFO_SRC_REG", |
darienf | 20:6d2af70c92ab | 309 | "INT1_CFG", |
darienf | 20:6d2af70c92ab | 310 | "INT1_SOURCE", |
darienf | 20:6d2af70c92ab | 311 | "INT1_THS", |
darienf | 20:6d2af70c92ab | 312 | "INT1_DURATION", |
darienf | 20:6d2af70c92ab | 313 | "INT2_CFG", |
darienf | 20:6d2af70c92ab | 314 | "INT2_SOURCE", |
darienf | 20:6d2af70c92ab | 315 | "INT2_THS", |
darienf | 20:6d2af70c92ab | 316 | "INT2_DURATION", |
darienf | 20:6d2af70c92ab | 317 | "CLICK_CFG", |
darienf | 20:6d2af70c92ab | 318 | "CLICK_SRC", |
darienf | 20:6d2af70c92ab | 319 | "CLICK_THS", |
darienf | 20:6d2af70c92ab | 320 | "TIME_LIMIT", |
darienf | 20:6d2af70c92ab | 321 | "TIME_LATENCY", |
darienf | 20:6d2af70c92ab | 322 | "TIME_WINDOW", |
darienf | 20:6d2af70c92ab | 323 | "Act_THS", |
darienf | 20:6d2af70c92ab | 324 | "Act_DUR" |
darienf | 20:6d2af70c92ab | 325 | }; |
darienf | 20:6d2af70c92ab | 326 | |
darienf | 20:6d2af70c92ab | 327 | |
darienf | 20:6d2af70c92ab | 328 | /// When the name property changes the other properties will change based on the name |
darienf | 20:6d2af70c92ab | 329 | public string Name |
darienf | 20:6d2af70c92ab | 330 | { |
darienf | 20:6d2af70c92ab | 331 | get |
darienf | 20:6d2af70c92ab | 332 | { |
darienf | 20:6d2af70c92ab | 333 | return name; |
darienf | 20:6d2af70c92ab | 334 | } |
darienf | 20:6d2af70c92ab | 335 | set |
darienf | 20:6d2af70c92ab | 336 | { |
darienf | 20:6d2af70c92ab | 337 | if (value != name) |
darienf | 20:6d2af70c92ab | 338 | { |
darienf | 20:6d2af70c92ab | 339 | name = value; |
darienf | 20:6d2af70c92ab | 340 | |
darienf | 20:6d2af70c92ab | 341 | //change register map and sampling rates for other devices |
darienf | 20:6d2af70c92ab | 342 | ChangeADCSetting(); |
darienf | 20:6d2af70c92ab | 343 | } |
darienf | 20:6d2af70c92ab | 344 | |
darienf | 20:6d2af70c92ab | 345 | } |
darienf | 20:6d2af70c92ab | 346 | } |
darienf | 20:6d2af70c92ab | 347 | |
darienf | 20:6d2af70c92ab | 348 | public void ChangeADCSetting() |
darienf | 20:6d2af70c92ab | 349 | { |
darienf | 20:6d2af70c92ab | 350 | switch (name) |
darienf | 20:6d2af70c92ab | 351 | { |
darienf | 20:6d2af70c92ab | 352 | case "MAX11214": |
darienf | 20:6d2af70c92ab | 353 | |
darienf | 20:6d2af70c92ab | 354 | if (cont_SINC[0] != 0.95) |
darienf | 20:6d2af70c92ab | 355 | { |
darienf | 20:6d2af70c92ab | 356 | cont_SINC.Clear(); |
darienf | 20:6d2af70c92ab | 357 | single_cont.Clear(); |
darienf | 20:6d2af70c92ab | 358 | cont_FIR.Clear(); |
darienf | 20:6d2af70c92ab | 359 | cont_SINC.AddRange(new double[] { 0.95, 1.9, 3.9, 7.8, 15.6, 31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000 }); |
darienf | 20:6d2af70c92ab | 360 | single_cont.AddRange(new double[] { 25, 31.25, 50, 62.5, 100, 125, 200, 250, 400, 500, 800, 1000, 1600, 2000, 3200, 6400 }); |
darienf | 20:6d2af70c92ab | 361 | cont_FIR.AddRange(new double[] { 62.5, 125, 250, 500, 1000, 2000, 4000, 8000 }); |
darienf | 20:6d2af70c92ab | 362 | } |
darienf | 20:6d2af70c92ab | 363 | |
darienf | 20:6d2af70c92ab | 364 | if (!Registers.Contains(HPF)) |
darienf | 20:6d2af70c92ab | 365 | { |
darienf | 20:6d2af70c92ab | 366 | Registers.Insert(11, HPF); |
darienf | 20:6d2af70c92ab | 367 | RegisterCount = Registers.Count; |
darienf | 20:6d2af70c92ab | 368 | |
darienf | 20:6d2af70c92ab | 369 | |
darienf | 20:6d2af70c92ab | 370 | CTRL3.BitInfo[0].name = "FILT[1:0]"; |
darienf | 20:6d2af70c92ab | 371 | CTRL3.BitInfo[0].Description = "Filter Control\r\n0x = SINC\r\n10 = FIR\r\n11 = IIR"; |
darienf | 20:6d2af70c92ab | 372 | CTRL3.BitInfo[1].name = "PHASE"; |
darienf | 20:6d2af70c92ab | 373 | CTRL3.BitInfo[1].Description = "FIR Phase: 1 = minimum, 0 = linear"; |
darienf | 20:6d2af70c92ab | 374 | } |
darienf | 20:6d2af70c92ab | 375 | |
darienf | 20:6d2af70c92ab | 376 | break; |
darienf | 20:6d2af70c92ab | 377 | case "MAX11216": |
darienf | 20:6d2af70c92ab | 378 | |
darienf | 20:6d2af70c92ab | 379 | if (cont_SINC[0] != 1.9) |
darienf | 20:6d2af70c92ab | 380 | { |
darienf | 20:6d2af70c92ab | 381 | cont_SINC.Clear(); |
darienf | 20:6d2af70c92ab | 382 | single_cont.Clear(); |
darienf | 20:6d2af70c92ab | 383 | cont_FIR.Clear(); |
darienf | 20:6d2af70c92ab | 384 | |
darienf | 20:6d2af70c92ab | 385 | cont_SINC.AddRange(new double[] { 1.9, 3.9, 7.8, 15.6, 31.2, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000 }); |
darienf | 20:6d2af70c92ab | 386 | single_cont.AddRange(new double[] { 50, 62.5, 100, 125, 200, 250, 400, 500, 800, 1000, 1600, 2000, 3200, 4000, 6400, 12800 }); |
darienf | 20:6d2af70c92ab | 387 | cont_FIR.AddRange(new double[] { 125, 250, 500, 1000, 2000, 4000, 8000, 16000 }); |
darienf | 20:6d2af70c92ab | 388 | } |
darienf | 20:6d2af70c92ab | 389 | |
darienf | 20:6d2af70c92ab | 390 | if (!Registers.Contains(HPF)) |
darienf | 20:6d2af70c92ab | 391 | { |
darienf | 20:6d2af70c92ab | 392 | Registers.Insert(11, HPF); |
darienf | 20:6d2af70c92ab | 393 | RegisterCount = Registers.Count; |
darienf | 20:6d2af70c92ab | 394 | |
darienf | 20:6d2af70c92ab | 395 | |
darienf | 20:6d2af70c92ab | 396 | CTRL3.BitInfo[0].name = "FILT[1:0]"; |
darienf | 20:6d2af70c92ab | 397 | CTRL3.BitInfo[0].Description = "Filter Control\r\n0x = SINC\r\n10 = FIR\r\n11 = IIR"; |
darienf | 20:6d2af70c92ab | 398 | CTRL3.BitInfo[1].name = "PHASE"; |
darienf | 20:6d2af70c92ab | 399 | CTRL3.BitInfo[1].Description = "FIR Phase: 1 = minimum, 0 = linear"; |
darienf | 20:6d2af70c92ab | 400 | } |
darienf | 20:6d2af70c92ab | 401 | |
darienf | 20:6d2af70c92ab | 402 | break; |
darienf | 20:6d2af70c92ab | 403 | case "MAX11270": |
darienf | 20:6d2af70c92ab | 404 | |
darienf | 20:6d2af70c92ab | 405 | if (cont_SINC[0] != 1.9) |
darienf | 20:6d2af70c92ab | 406 | { |
darienf | 20:6d2af70c92ab | 407 | cont_SINC.Clear(); |
darienf | 20:6d2af70c92ab | 408 | single_cont.Clear(); |
darienf | 20:6d2af70c92ab | 409 | cont_FIR.Clear(); |
darienf | 20:6d2af70c92ab | 410 | |
darienf | 20:6d2af70c92ab | 411 | cont_SINC.AddRange(new double[] { 1.9, 3.9, 7.8, 15.6, 31.2, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000 }); |
darienf | 20:6d2af70c92ab | 412 | single_cont.AddRange(new double[] { 50, 62.5, 100, 125, 200, 250, 400, 500, 800, 1000, 1600, 2000, 3200, 4000, 6400, 12800 }); |
darienf | 20:6d2af70c92ab | 413 | cont_FIR.AddRange(new double[] { 125, 250, 500, 1000, 2000, 4000, 8000, 16000 }); |
darienf | 20:6d2af70c92ab | 414 | } |
darienf | 20:6d2af70c92ab | 415 | |
darienf | 20:6d2af70c92ab | 416 | if (Registers.Contains(HPF)) |
darienf | 20:6d2af70c92ab | 417 | { |
darienf | 20:6d2af70c92ab | 418 | Registers.Remove(HPF); |
darienf | 20:6d2af70c92ab | 419 | RegisterCount = Registers.Count; |
darienf | 20:6d2af70c92ab | 420 | |
darienf | 20:6d2af70c92ab | 421 | |
darienf | 20:6d2af70c92ab | 422 | CTRL3.BitInfo[0].name = "Reserved"; |
darienf | 20:6d2af70c92ab | 423 | CTRL3.BitInfo[0].Description = "-"; |
darienf | 20:6d2af70c92ab | 424 | CTRL3.BitInfo[1].name = "Reserved"; |
darienf | 20:6d2af70c92ab | 425 | CTRL3.BitInfo[1].Description = "-"; |
darienf | 20:6d2af70c92ab | 426 | } |
darienf | 20:6d2af70c92ab | 427 | |
darienf | 20:6d2af70c92ab | 428 | break; |
darienf | 20:6d2af70c92ab | 429 | case "MAX11271": |
darienf | 20:6d2af70c92ab | 430 | |
darienf | 20:6d2af70c92ab | 431 | if (cont_SINC[0] != 1.9) |
darienf | 20:6d2af70c92ab | 432 | { |
darienf | 20:6d2af70c92ab | 433 | cont_SINC.Clear(); |
darienf | 20:6d2af70c92ab | 434 | single_cont.Clear(); |
darienf | 20:6d2af70c92ab | 435 | cont_FIR.Clear(); |
darienf | 20:6d2af70c92ab | 436 | |
darienf | 20:6d2af70c92ab | 437 | cont_SINC.AddRange(new double[] { 1.9, 3.9, 7.8, 15.6, 31.2, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000 }); |
darienf | 20:6d2af70c92ab | 438 | single_cont.AddRange(new double[] { 50, 62.5, 100, 125, 200, 250, 400, 500, 800, 1000, 1600, 2000, 3200, 4000, 6400, 12800 }); |
darienf | 20:6d2af70c92ab | 439 | cont_FIR.AddRange(new double[] { 125, 250, 500, 1000, 2000, 4000, 8000, 16000 }); |
darienf | 20:6d2af70c92ab | 440 | } |
darienf | 20:6d2af70c92ab | 441 | |
darienf | 20:6d2af70c92ab | 442 | if (Registers.Contains(HPF)) |
darienf | 20:6d2af70c92ab | 443 | { |
darienf | 20:6d2af70c92ab | 444 | Registers.Remove(HPF); |
darienf | 20:6d2af70c92ab | 445 | RegisterCount = Registers.Count; |
darienf | 20:6d2af70c92ab | 446 | |
darienf | 20:6d2af70c92ab | 447 | |
darienf | 20:6d2af70c92ab | 448 | CTRL3.BitInfo[0].name = "Reserved"; |
darienf | 20:6d2af70c92ab | 449 | CTRL3.BitInfo[0].Description = "-"; |
darienf | 20:6d2af70c92ab | 450 | CTRL3.BitInfo[1].name = "Reserved"; |
darienf | 20:6d2af70c92ab | 451 | CTRL3.BitInfo[1].Description = "-"; |
darienf | 20:6d2af70c92ab | 452 | } |
darienf | 20:6d2af70c92ab | 453 | break; |
darienf | 20:6d2af70c92ab | 454 | case "MAX11280": |
darienf | 20:6d2af70c92ab | 455 | break; |
darienf | 20:6d2af70c92ab | 456 | case "MAX11281": |
darienf | 20:6d2af70c92ab | 457 | break; |
darienf | 20:6d2af70c92ab | 458 | case "MAX11282": |
darienf | 20:6d2af70c92ab | 459 | break; |
darienf | 20:6d2af70c92ab | 460 | } |
darienf | 20:6d2af70c92ab | 461 | |
darienf | 20:6d2af70c92ab | 462 | } |
darienf | 20:6d2af70c92ab | 463 | |
darienf | 20:6d2af70c92ab | 464 | public int Resolution |
darienf | 20:6d2af70c92ab | 465 | { |
darienf | 20:6d2af70c92ab | 466 | get |
darienf | 20:6d2af70c92ab | 467 | { |
darienf | 20:6d2af70c92ab | 468 | return resolution; |
darienf | 20:6d2af70c92ab | 469 | |
darienf | 20:6d2af70c92ab | 470 | } |
darienf | 20:6d2af70c92ab | 471 | set |
darienf | 20:6d2af70c92ab | 472 | { |
darienf | 20:6d2af70c92ab | 473 | if (value != resolution) |
darienf | 20:6d2af70c92ab | 474 | { |
darienf | 20:6d2af70c92ab | 475 | resolution = value; |
darienf | 20:6d2af70c92ab | 476 | |
darienf | 20:6d2af70c92ab | 477 | //SetFullScaleAndOffset(); |
darienf | 20:6d2af70c92ab | 478 | } |
darienf | 20:6d2af70c92ab | 479 | } |
darienf | 20:6d2af70c92ab | 480 | } |
darienf | 20:6d2af70c92ab | 481 | |
darienf | 20:6d2af70c92ab | 482 | public double VREF |
darienf | 20:6d2af70c92ab | 483 | { |
darienf | 20:6d2af70c92ab | 484 | get |
darienf | 20:6d2af70c92ab | 485 | { |
darienf | 20:6d2af70c92ab | 486 | return VREFExternal; |
darienf | 20:6d2af70c92ab | 487 | |
darienf | 20:6d2af70c92ab | 488 | } |
darienf | 20:6d2af70c92ab | 489 | set |
darienf | 20:6d2af70c92ab | 490 | { |
darienf | 20:6d2af70c92ab | 491 | if (value != VREFExternal) |
darienf | 20:6d2af70c92ab | 492 | { |
darienf | 20:6d2af70c92ab | 493 | VREFExternal = value; |
darienf | 20:6d2af70c92ab | 494 | |
darienf | 20:6d2af70c92ab | 495 | //SetFullScaleAndOffset(); |
darienf | 20:6d2af70c92ab | 496 | } |
darienf | 20:6d2af70c92ab | 497 | } |
darienf | 20:6d2af70c92ab | 498 | } |
darienf | 20:6d2af70c92ab | 499 | |
darienf | 20:6d2af70c92ab | 500 | public bool IsBipolar |
darienf | 20:6d2af70c92ab | 501 | { |
darienf | 20:6d2af70c92ab | 502 | get |
darienf | 20:6d2af70c92ab | 503 | { |
darienf | 20:6d2af70c92ab | 504 | return bipolar; |
darienf | 20:6d2af70c92ab | 505 | |
darienf | 20:6d2af70c92ab | 506 | } |
darienf | 20:6d2af70c92ab | 507 | set |
darienf | 20:6d2af70c92ab | 508 | { |
darienf | 20:6d2af70c92ab | 509 | if (value != bipolar) |
darienf | 20:6d2af70c92ab | 510 | { |
darienf | 20:6d2af70c92ab | 511 | bipolar = value; |
darienf | 20:6d2af70c92ab | 512 | |
darienf | 20:6d2af70c92ab | 513 | //SetFullScaleAndOffset(); |
darienf | 20:6d2af70c92ab | 514 | } |
darienf | 20:6d2af70c92ab | 515 | } |
darienf | 20:6d2af70c92ab | 516 | } |
darienf | 20:6d2af70c92ab | 517 | |
darienf | 20:6d2af70c92ab | 518 | public bool IsTwosComp |
darienf | 20:6d2af70c92ab | 519 | { |
darienf | 20:6d2af70c92ab | 520 | get |
darienf | 20:6d2af70c92ab | 521 | { |
darienf | 20:6d2af70c92ab | 522 | return twosComp; |
darienf | 20:6d2af70c92ab | 523 | |
darienf | 20:6d2af70c92ab | 524 | } |
darienf | 20:6d2af70c92ab | 525 | set |
darienf | 20:6d2af70c92ab | 526 | { |
darienf | 20:6d2af70c92ab | 527 | if (value != twosComp) |
darienf | 20:6d2af70c92ab | 528 | { |
darienf | 20:6d2af70c92ab | 529 | twosComp = value; |
darienf | 20:6d2af70c92ab | 530 | |
darienf | 20:6d2af70c92ab | 531 | //SetFullScaleAndOffset(); |
darienf | 20:6d2af70c92ab | 532 | } |
darienf | 20:6d2af70c92ab | 533 | } |
darienf | 20:6d2af70c92ab | 534 | } |
darienf | 20:6d2af70c92ab | 535 | |
darienf | 20:6d2af70c92ab | 536 | /// Calculates the Full scale value and offset of the ADC |
darienf | 20:6d2af70c92ab | 537 | public void SetGainAndOffset(int res) |
darienf | 20:6d2af70c92ab | 538 | { |
darienf | 20:6d2af70c92ab | 539 | double FullScale; |
darienf | 20:6d2af70c92ab | 540 | |
darienf | 20:6d2af70c92ab | 541 | if (bipolar) |
darienf | 20:6d2af70c92ab | 542 | { |
darienf | 20:6d2af70c92ab | 543 | FullScale = 2 * VREFExternal; |
darienf | 20:6d2af70c92ab | 544 | |
darienf | 20:6d2af70c92ab | 545 | if (twosComp) //2's compliment |
darienf | 20:6d2af70c92ab | 546 | offset = 0; |
darienf | 20:6d2af70c92ab | 547 | else //offset binary |
darienf | 20:6d2af70c92ab | 548 | offset = 1 << (res - 1); //2^(resolution-1) |
darienf | 20:6d2af70c92ab | 549 | } |
darienf | 20:6d2af70c92ab | 550 | else //unipolar |
darienf | 20:6d2af70c92ab | 551 | { |
darienf | 20:6d2af70c92ab | 552 | FullScale = VREFExternal; |
darienf | 20:6d2af70c92ab | 553 | offset = 0; |
darienf | 20:6d2af70c92ab | 554 | } |
darienf | 20:6d2af70c92ab | 555 | |
darienf | 20:6d2af70c92ab | 556 | long digitalFullscale = ((long)1 << res) - 1; |
darienf | 20:6d2af70c92ab | 557 | |
darienf | 20:6d2af70c92ab | 558 | gain = FullScale / digitalFullscale; |
darienf | 20:6d2af70c92ab | 559 | } |
darienf | 20:6d2af70c92ab | 560 | } |
darienf | 20:6d2af70c92ab | 561 | |
darienf | 20:6d2af70c92ab | 562 | /// <summary> |
darienf | 20:6d2af70c92ab | 563 | /// This class sets up a structure to hold register information |
darienf | 20:6d2af70c92ab | 564 | /// </summary> |
darienf | 20:6d2af70c92ab | 565 | /// @see RegisterMap |
darienf | 20:6d2af70c92ab | 566 | public class RegisterDescription |
darienf | 20:6d2af70c92ab | 567 | { |
darienf | 20:6d2af70c92ab | 568 | public byte Address; |
darienf | 20:6d2af70c92ab | 569 | public string Name; |
darienf | 20:6d2af70c92ab | 570 | public bool ReadOnly; |
darienf | 20:6d2af70c92ab | 571 | public int numBytes; |
darienf | 20:6d2af70c92ab | 572 | public string Description; |
darienf | 20:6d2af70c92ab | 573 | public int Value; |
darienf | 20:6d2af70c92ab | 574 | public List<BitInfo> BitInfo; |
darienf | 20:6d2af70c92ab | 575 | } |
darienf | 20:6d2af70c92ab | 576 | |
darienf | 20:6d2af70c92ab | 577 | ///<summary> |
darienf | 20:6d2af70c92ab | 578 | /// This class sets up the structure to hold bit information of registers |
darienf | 20:6d2af70c92ab | 579 | /// </summary> |
darienf | 20:6d2af70c92ab | 580 | ///@see RegisterDescription |
darienf | 20:6d2af70c92ab | 581 | public class BitInfo |
darienf | 20:6d2af70c92ab | 582 | { |
darienf | 20:6d2af70c92ab | 583 | public string name; |
darienf | 20:6d2af70c92ab | 584 | public string bitIndex; |
darienf | 20:6d2af70c92ab | 585 | public string Description; |
darienf | 20:6d2af70c92ab | 586 | } |
darienf | 20:6d2af70c92ab | 587 | } |