Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BioZChannel.cs
00001 /******************************************************************************* 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved. 00003 * 00004 * This software is protected by copyright laws of the United States and 00005 * of foreign countries. This material may also be protected by patent laws 00006 * and technology transfer regulations of the United States and of foreign 00007 * countries. This software is furnished under a license agreement and/or a 00008 * nondisclosure agreement and may only be used or reproduced in accordance 00009 * with the terms of those agreements. Dissemination of this information to 00010 * any party or parties not specified in the license agreement and/or 00011 * nondisclosure agreement is expressly prohibited. 00012 * 00013 * The above copyright notice and this permission notice shall be included 00014 * in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00022 * OTHER DEALINGS IN THE SOFTWARE. 00023 * 00024 * Except as contained in this notice, the name of Maxim Integrated 00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00026 * Products, Inc. Branding Policy. 00027 * 00028 * The mere transfer of this software does not imply any licenses 00029 * of trade secrets, proprietary technology, copyrights, patents, 00030 * trademarks, maskwork rights, or any other form of intellectual 00031 * property whatsoever. Maxim Integrated Products, Inc. retains all 00032 * ownership rights. 00033 ******************************************************************************* 00034 */ 00035 00036 using System; 00037 using System.Collections.Generic; 00038 using System.Linq; 00039 using System.Text; 00040 00041 namespace HealthSensorPlatform 00042 { 00043 public partial class HspForm 00044 { 00045 List<RegisterField> bioZChannelField = new List<RegisterField>(); 00046 00047 RegisterField bioZSampleRateField; // Needed for dynamic changing of options 00048 RegisterField bioZDlpfField; 00049 RegisterField bioZCgmagField; 00050 00051 string[][] bioZSampleRateOptions = new string[][] 00052 { 00053 new string[] { "64 sps*", "32 sps" }, 00054 new string[] { "62.5 sps*", "31.25 sps" }, 00055 new string[] { "50 sps*", "25 sps" }, 00056 new string[] { "49.95 sps*", "24.98 sps" } 00057 }; 00058 00059 string[][] bioZCgmagOptions = { new string[] { "Off*", "8 μA", "16 μA", "32 μA", "48 μA", "64 μA", "80 μA", "96 μA" }, 00060 new string[] { "Off*", "8 μA", "16 μA", "32 μA", "48 μA", "64 μA", "80 μA" }, 00061 new string[] { "Off*", "8 μA", "16 μA", "32 μA" }, 00062 new string[] { "Off*", "8 μA", "16 μA" }, 00063 new string[] { "Off*", "8 μA" } 00064 }; 00065 00066 string[][][] bioZDlpfOptions; 00067 00068 void initalizeBioZConfigFields() 00069 { 00070 bioZDlpfOptions = new string[4][][]; 00071 00072 for (int i = 0; i < 4; i++) 00073 { 00074 bioZDlpfOptions[i] = new string[2][]; 00075 } 00076 00077 // 32768 Hz 00078 bioZDlpfOptions[0][0] = new string[] {"Bypass", "4.096 Hz*", "8.192 Hz", "16.384 Hz"}; 00079 bioZDlpfOptions[0][1] = new string[] {"Bypass", "4.096 Hz*", "8.192 Hz"}; //, "4.096 Hz"}; 00080 // 32000 Hz 00081 bioZDlpfOptions[1][0] = new string[] {"Bypass", "4.0 Hz*", "8.0 Hz", "16.0 Hz"}; 00082 bioZDlpfOptions[1][1] = new string[] {"Bypass", "4.0 Hz*", "8.0 Hz"}; //, "4.0 Hz"}; 00083 // 32000 Hz 00084 bioZDlpfOptions[2][0] = new string[] {"Bypass", "4.0 Hz*", "8.0 Hz", "16.0 Hz"}; 00085 bioZDlpfOptions[2][1] = new string[] {"Bypass", "4.0 Hz*", "8.0 Hz"}; //, "4.0 Hz"}; 00086 // 31968 Hz 00087 bioZDlpfOptions[3][0] = new string[] {"Bypass", "3.996 Hz*", "7.992 Hz", "15.984 Hz"}; 00088 bioZDlpfOptions[3][1] = new string[] {"Bypass", "3.996 Hz*", "7.992 Hz"}; //, "3.996 Hz"}; 00089 00090 string[] aHpfOptions = { "250 Hz", "500 Hz", "1000 Hz*", "2000 Hz", "4000 Hz", "8000 Hz", "Bypass" }; 00091 string[] gainOptions = { "20 V/V*", "40 V/V", "80 V/V", "160 V/V" }; 00092 string[] dlpfOptions = { "Bypass", "4 Hz*", "8 Hz", "16 Hz" }; 00093 string[] dhpfOptions = { "Bypass (DC)*", "0.05 Hz", "0.50 Hz" }; 00094 00095 00096 string[] fcgenOptions = { "4*FMSTR (~128 kHz)", "2*FMSTR (~80 kHz) - offset", "FMSTR (~40 kHz) - offset", "FMSTR/2 (~18 kHz) - offset", 00097 "FMSTR/4 (~8 kHz)", "FMSTR/8 (~4 kHz)", "FMSTR/16 (~2 kHz)", "FMSTR/32 (~1 kHz)", 00098 "FMSTR/64 (~500 Hz)*", "FMSTR/128 (~250 Hz)", "FMSTR/256 (~125 Hz)"}; 00099 string[] cgmonOptions = { "Disabled*", "Enabled" }; 00100 string[] extRbiasOptions = { "Internal*", "External" }; 00101 string[] cgModeOptions = { "Unchopped w/ LPF*", "Chopped w/o LPF", "Chopped w/ LPF", "Chopped w/ Resistive CM" }; 00102 00103 string[] enBloffOptions = { "Disabled*", "Under Range", "Over Range", "Under and Over Range" }; 00104 string[] hiITOptions = new string[256]; 00105 string[] loITOptions = new string[256]; 00106 00107 for (int i = 0; i < hiITOptions.Length; i++) 00108 { 00109 hiITOptions[i] = "±2048 * " + i; 00110 loITOptions[i] = "±32 * " + i; 00111 } 00112 hiITOptions[255] += "*"; 00113 loITOptions[255] += "*"; 00114 00115 string[] phoffOptions = new string[16]; 00116 for (int i = 0; i < phoffOptions.Length/4; i++) 00117 { 00118 phoffOptions[4 * i] = (11.25 * 4 * i).ToString() + "° (For all frequencies)"; 00119 phoffOptions[4 * i + 1] = (11.25 * (4 * i + 1)).ToString() + "° (For <= 40kHz)"; 00120 phoffOptions[4 * i + 2] = (11.25 * (4 * i + 2)).ToString() + "° (For <= 80kHz)"; 00121 phoffOptions[4 * i + 3] = (11.25 * (4 * i + 3)).ToString() + "° (For <= 40kHz)"; 00122 } 00123 phoffOptions[0] += "*"; 00124 00125 string[] enDcloffOptions = { "Disabled*", "ECGP/N", "BIP/N" }; 00126 00127 bioZSampleRateField = new RegisterField { Name = "BIOZ_RATE", Register = 0x18, Index = 23, Width = 1, Descriptions = bioZSampleRateOptions[0], Label = lblBioZSampleRate, Control = cboBioZSampleRate, Device = max30001 }; 00128 RegisterField aHpfField = new RegisterField { Name = "BIOZ_AHPF", Register = 0x18, Index = 20, Width = 3, Descriptions = aHpfOptions, Label = lblBioZAnalogHpf, Control = cboBioZAnalogHpf, Device = max30001 }; 00129 RegisterField rbiasField = new RegisterField { Name = "\nEXT_RBIAS", Register = 0x18, Index = 19, Width = 1, Descriptions = extRbiasOptions, Label = lblBioZExternalResistorBiasEnable, Control = cboBioZExternalResistorBiasEnable, Device = max30001 }; 00130 RegisterField gainField = new RegisterField { Name = "BIOZ_GAIN", Register = 0x18, Index = 16, Width = 2, Descriptions = gainOptions, Label = lblBioZChannelGain, Control = cboBioZChannelGain, Device = max30001 }; 00131 RegisterField digitalHpfField = new RegisterField { Name = "BIOZ_DHPF", Register = 0x18, Index = 14, Width = 2, Descriptions = dhpfOptions, Label = lblBioZDigitalHpf, Control = cboBioZDigitalHpf, Device = max30001 }; 00132 bioZDlpfField = new RegisterField { Name = "BIOZ_DLPF", Register = 0x18, Index = 12, Width = 2, Descriptions = dlpfOptions, Label = lblBioZDigitalLpf, Control = cboBioZDigitalLpf, Device = max30001 }; 00133 RegisterField fcgenField = new RegisterField { Name = "BIOZ_FCGEN", Register = 0x18, Index = 8, Width = 4, Descriptions = fcgenOptions, Label = lblBioZCurrentGeneratorFrequency, Control = cboBioZCurrentGeneratorFrequency, Device = max30001 }; 00134 RegisterField cgmonField = new RegisterField { Name = "BIOZ_CGMON", Register = 0x18, Index = 7, Width = 1, Descriptions = cgmonOptions, Label = lblBioZCurrentGeneratorMonitor, Control = cboBioZCurrentGeneratorMonitor, Device = max30001 }; 00135 bioZCgmagField = new RegisterField { Name = "BIOZ_CGMAG", Register = 0x18, Index = 4, Width = 3, Descriptions = bioZCgmagOptions[0], Label = lblBioZCurrentGeneratorMagnitude, Control = cboBioZCurrentGeneratorMagnitude, Device = max30001 }; 00136 RegisterField phoffField = new RegisterField { Name = "\nBIOZ_PHOFF", Register = 0x18, Index = 0, Width = 4, Descriptions = phoffOptions, Label = lblBioZModulationPhaseOffset, Control = cboBioZModulationPhaseOffset, Device = max30001 }; 00137 bioZChannelField.Add(bioZSampleRateField); 00138 bioZChannelField.Add(aHpfField); 00139 bioZChannelField.Add(rbiasField); 00140 bioZChannelField.Add(gainField); 00141 bioZChannelField.Add(digitalHpfField); 00142 bioZChannelField.Add(bioZDlpfField); 00143 bioZChannelField.Add(fcgenField); 00144 bioZChannelField.Add(cgmonField); 00145 bioZChannelField.Add(bioZCgmagField); 00146 bioZChannelField.Add(phoffField); 00147 00148 RegisterField cgmodeField = new RegisterField { Name = "BMUX_CG_MODE", Register = 0x17, Index = 12, Width = 2, Descriptions = cgModeOptions, Label = lblBioZCurrentGeneratorMode, Control = cboBioZCurrentGeneratorMode, Device = max30001 }; 00149 RegisterField enDcloffField = new RegisterField { Name = "EN_BLOFF", Register = 0x10, Index = 14, Width = 2, Descriptions = enBloffOptions, Label = lblBioZDigitalLeadOffDetectionEnable, Control = cboBioZDigitalLeadOffDetectionEnable, Device = max30001 }; 00150 RegisterField bloffHiItField = new RegisterField { Name = "BLOFF_HI_IT", Register = 0x05, Index = 8, Width = 8, Descriptions = hiITOptions, Label = lblBioZACLeadOffOverRangeThreshold, Control = cboBioZACLeadOffOverRangeThreshold, Device = max30001 }; 00151 RegisterField bloffLoItField = new RegisterField { Name = "BLOFF_LO_IT", Register = 0x05, Index = 0, Width = 8, Descriptions = loITOptions, Label = lblBioZACLeadOffUnderRangeThreshold, Control = cboBioZACLeadOffUnderRangeThreshold, Device = max30001 }; 00152 bioZChannelField.Add(cgmodeField); 00153 bioZChannelField.Add(enDcloffField); 00154 bioZChannelField.Add(bloffHiItField); 00155 bioZChannelField.Add(bloffLoItField); 00156 } 00157 00158 void BioZChannelUpdateRegisters() 00159 { 00160 internalUpdate = true; 00161 ReadComboBoxesRegisters(bioZChannelField); 00162 internalUpdate = false; 00163 } 00164 00165 private CustomControls.InitArgs.BIOZInitStart getBioZArgs() 00166 { 00167 CustomControls.InitArgs.BIOZInitStart biozArgs = new CustomControls.InitArgs.BIOZInitStart(); 00168 00169 biozArgs.Openp = cboBioZBmuxOpenp.SelectedIndex; 00170 biozArgs.Openn = cboBioZBmuxOpenn.SelectedIndex; 00171 biozArgs.Calp_sel = cboBioZBmuxCalpSel.SelectedIndex; 00172 biozArgs.Caln_sel = cboBioZBmuxCalnSel.SelectedIndex; 00173 biozArgs.CG_mode = cboBioZCurrentGeneratorMode.SelectedIndex; 00174 biozArgs.En_bioz = chkEnBioZ.Checked == true ? 1 : 0; 00175 biozArgs.B_fit = 7; // comboBox39.SelectedIndex; 00176 biozArgs.Rate = cboBioZSampleRate.SelectedIndex; 00177 biozArgs.Ahpf = cboBioZAnalogHpf.SelectedIndex; 00178 biozArgs.Ext_rbias = cboBioZExternalResistorBiasEnable.SelectedIndex; 00179 biozArgs.Gain = cboBioZChannelGain.SelectedIndex; 00180 biozArgs.Dhpf = cboBioZDigitalHpf.SelectedIndex; 00181 biozArgs.Dlpf = cboBioZDigitalLpf.SelectedIndex; 00182 biozArgs.Fcgen = cboBioZCurrentGeneratorFrequency.SelectedIndex; 00183 biozArgs.Cgmon = cboBioZCurrentGeneratorMonitor.SelectedIndex; 00184 biozArgs.Cgmag = cboBioZCurrentGeneratorMagnitude.SelectedIndex; 00185 biozArgs.Phoff = cboBioZModulationPhaseOffset.SelectedIndex; 00186 00187 return biozArgs; 00188 } 00189 00190 private void setBioZArgs(CustomControls.InitArgs.BIOZInitStart biozArgs) 00191 { 00192 cboBioZBmuxOpenp.SelectedIndex = biozArgs.Openp; 00193 cboBioZBmuxOpenn.SelectedIndex = biozArgs.Openn; 00194 cboBioZBmuxCalpSel.SelectedIndex = biozArgs.Calp_sel; 00195 cboBioZBmuxCalnSel.SelectedIndex = biozArgs.Caln_sel; 00196 cboBioZCurrentGeneratorMode.SelectedIndex = biozArgs.CG_mode; 00197 //biozArgs.En_bioz = chkEnBioZ.Checked == true ? 1 : 0; 00198 //biozArgs.B_fit = 7; // comboBox39.SelectedIndex; 00199 cboBioZSampleRate.SelectedIndex = biozArgs.Rate; 00200 cboBioZAnalogHpf.SelectedIndex = biozArgs.Ahpf; 00201 cboBioZExternalResistorBiasEnable.SelectedIndex = biozArgs.Ext_rbias; 00202 cboBioZChannelGain.SelectedIndex = biozArgs.Gain; 00203 cboBioZDigitalHpf.SelectedIndex = biozArgs.Dhpf; 00204 cboBioZDigitalLpf.SelectedIndex = biozArgs.Dlpf; 00205 cboBioZCurrentGeneratorFrequency.SelectedIndex = biozArgs.Fcgen; 00206 cboBioZCurrentGeneratorMonitor.SelectedIndex = biozArgs.Cgmon; 00207 cboBioZCurrentGeneratorMagnitude.SelectedIndex = biozArgs.Cgmag; 00208 cboBioZModulationPhaseOffset.SelectedIndex = biozArgs.Phoff; 00209 } 00210 00211 public string BioZSettingString() 00212 { 00213 StringBuilder sb = new StringBuilder(); 00214 00215 foreach(RegisterField rf in bioZChannelField) 00216 { 00217 sb.Append(rf.Label.Text.Replace("\n", String.Empty)); 00218 sb.Append(" = "); 00219 sb.Append(((MaximStyle.MaximComboBox)rf.Control).SelectedItem); 00220 sb.Append(", "); 00221 } 00222 00223 return sb.ToString(); 00224 } 00225 00226 public string EcgSettingString() 00227 { 00228 StringBuilder sb = new StringBuilder(); 00229 00230 foreach (RegisterField rf in ecgChannelField) 00231 { 00232 sb.Append(rf.Label.Text.Replace("\n", String.Empty)); 00233 sb.Append(" = "); 00234 sb.Append(((MaximStyle.MaximComboBox)rf.Control).SelectedItem); 00235 sb.Append(", "); 00236 } 00237 00238 return sb.ToString(); 00239 } 00240 00241 00242 private void cboBioZChannelGain_SelectedIndexChanged(object sender, EventArgs e) 00243 { 00244 MaximStyle.MaximComboBox cbox = (MaximStyle.MaximComboBox)sender; 00245 00246 switch (cbox.SelectedIndex) 00247 { 00248 case 0: 00249 ecgView1.GainBioZ = 20; 00250 break; 00251 case 1: 00252 ecgView1.GainBioZ = 40; 00253 break; 00254 case 2: 00255 ecgView1.GainBioZ = 80; 00256 break; 00257 case 3: 00258 ecgView1.GainBioZ = 160; 00259 break; 00260 } 00261 } 00262 00263 private void cboBioZCurrentGeneratorMagnitude_SelectedIndexChanged(object sender, EventArgs e) 00264 { 00265 MaximStyle.MaximComboBox cbox = (MaximStyle.MaximComboBox)sender; 00266 int[] currents = { 0, 8, 16, 32, 48, 64, 80, 96 }; 00267 00268 // Equation for Hex code to current magnitude 00269 ecgView1.CurrentBioZ = currents[cbox.SelectedIndex]; 00270 } 00271 00272 private void cboBioZSampleRate_SelectedIndexChanged(object sender, EventArgs e) 00273 { 00274 MaximStyle.MaximComboBox cbo = (MaximStyle.MaximComboBox)sender; 00275 double[][] sampleRates = new double[][] 00276 { 00277 new double[] {64, 32}, 00278 new double[] {62.5, 31.25}, 00279 new double[] {50, 25}, 00280 new double[] {49.95, 24.98} 00281 }; 00282 00283 if (connected && !internalUpdate) 00284 writeComboBox(cbo); 00285 00286 if (cboMasterClock.SelectedIndex > -1 && cbo.SelectedIndex > -1 && cboBioZDigitalLpf.SelectedIndex > -1) // All boxes are init 00287 { 00288 ecgView1.SampleRateBioZ = sampleRates[cboMasterClock.SelectedIndex][cbo.SelectedIndex]; 00289 00290 cboBioZDigitalLpf.Items.Clear(); 00291 bioZDlpfField.Descriptions = bioZDlpfOptions[cboMasterClock.SelectedIndex][cboBioZSampleRate.SelectedIndex]; 00292 bioZDlpfField.Control = cboBioZDigitalLpf; // Trigger update of descriptions 00293 00294 cboBioZDigitalLpf.SelectedIndex = bioZDlpfField.ReadField(); 00295 00296 } 00297 } 00298 00299 private void cboBioZCurrentGeneratorFrequency_SelectedIndexChanged(object sender, EventArgs e) 00300 { 00301 string[] currentOptions; 00302 switch (cboBioZCurrentGeneratorFrequency.SelectedIndex) 00303 { 00304 case 0: 00305 case 1: 00306 case 2: 00307 case 3: 00308 currentOptions = bioZCgmagOptions[0]; 00309 break; 00310 case 4: 00311 currentOptions = bioZCgmagOptions[1]; 00312 break; 00313 case 5: 00314 currentOptions = bioZCgmagOptions[2]; 00315 break; 00316 case 6: 00317 currentOptions = bioZCgmagOptions[3]; 00318 break; 00319 default: 00320 currentOptions = bioZCgmagOptions[4]; 00321 break; 00322 } 00323 00324 if (cboBioZCurrentGeneratorMagnitude.SelectedIndex >= currentOptions.Length) // Force user selection to be valid 00325 { 00326 cboBioZCurrentGeneratorMagnitude.SelectedIndex = currentOptions.Length - 1; 00327 } 00328 bioZCgmagField.Descriptions = currentOptions; 00329 bioZCgmagField.Control = cboBioZCurrentGeneratorMagnitude; // Repopulate drop down options 00330 } 00331 00332 private void cboBioZDigitalLeadOffDetectionEnable_SelectedIndexChanged(object sender, EventArgs e) 00333 { 00334 MaximStyle.MaximComboBox cbo = (MaximStyle.MaximComboBox)sender; 00335 00336 if (cbo.SelectedIndex == 0) 00337 ecgView1.EnableBioZOverUnderRange = false; 00338 else 00339 ecgView1.EnableBioZOverUnderRange = true; 00340 } 00341 00342 } 00343 }
Generated on Tue Jul 12 2022 21:52:37 by
1.7.2