// Check the current ADC settings for clock frequencies that are beyond the clock specifications.
        private bool CheckFreq(string sResolution, string sGain, string sSampleRate, string sConversionMode,
            ComboBox cbInputBufferMode, CyNumericUpDown nudConvRate, ComboBox cbConvMode, ComboBox cbResolution,
            TextBox tbClockFreq, Label lbSPSRange, bool saveValue, string sinputRange, ComboBox cbInputRange)
        {
            float theFreq;
            float theFreqKHz;
            int resolution;
            int gain, conversionMode, inputRange;
            uint minRate, maxRate;
            float TheMaxFreq;
            float TheMinFreq;
            float TheMaxFreqKHz;
            float TheMinFreqKHz;
            string errorMessage;
            bool retVal;
            uint convRate = (uint)nudConvRate.Value;

            retVal = true;
            resolution = int.Parse(cbResolution.Text);// int.Parse(m_Component.GetCommittedParam(sResolution).Value);
            //gain = int.Parse(m_Component.GetCommittedParam(sGain).Value);
            string gainValue = m_Component.GetCommittedParam(sGain).Value;
            try
            {
                gain = int.Parse(gainValue);
            }
            catch (Exception)
            {
                gain = 1;
            }
            conversionMode = (int)cbConvMode.SelectedIndex; //m_Component.GetCommittedParam(sConversionMode).Value);
            inputRange = Convert.ToInt32(m_Component.GetCommittedParam(sinputRange).Value);
            if (resolution > 15)
            {
                // If buffer is enabled, for 2x,4x,8x gain, the frequency is halved and
                // halved and halved respectively

                // Unbuffered Input
                if (cbInputBufferMode.Items[cbInputBufferMode.SelectedIndex].ToString() == BYPASS_BUFFER)
                    TheMaxFreq = (float)Cyrc.MAX_FREQ_16_20_BITS[inputRange];
                else
                    TheMaxFreq = (float)Cyrc.MAX_FREQ_16_20_BITS[inputRange] / gain;

                TheMinFreq = (float)Cyrc.MIN_FREQ_15_20_BITS;
            }
            else
            {
                // Unbuffered Input
                if (cbInputBufferMode.Items[cbInputBufferMode.SelectedIndex].ToString() == BYPASS_BUFFER)
                    TheMaxFreq = (float)Cyrc.MAX_FREQ_8_15_BITS[inputRange];
                else
                    TheMaxFreq = (float)Cyrc.MAX_FREQ_8_15_BITS[inputRange] / gain;

                // Minimum frequency is equal to that for 8-14 bit resolution
                TheMinFreq = (float)Cyrc.MIN_FREQ_8_14_BITS;
            }

            theFreq = (float)GetFreq((uint)resolution, (uint)conversionMode, (uint)nudConvRate.Value);
            theFreqKHz = theFreq / (float)1000.0;
            TheMaxFreqKHz = TheMaxFreq / (float)1000.0;
            TheMinFreqKHz = (float)(TheMinFreq / 1000.0);

            maxRate = GetConvRate(TheMaxFreq, true, resolution, conversionMode);
            minRate = GetConvRate(TheMinFreq, false, resolution, conversionMode);

            // Compare to valid value
            if (maxRate < minRate)
            {
                errorMessage = String.Empty;

                if (gain == 8)
                {
                    // 192KHz. And lower limit will be 128KHz.
                    TheMaxFreq = 192000;
                    TheMinFreq = 128000;
                    TheMaxFreqKHz = (float)192;
                    TheMinFreqKHz = (float)128;
                }
                maxRate = GetConvRate(TheMaxFreq, true, resolution, conversionMode);
                minRate = GetConvRate(TheMinFreq, false, resolution, conversionMode);
            }

            errorMessage = String.Empty;
            if (theFreq > TheMaxFreq)
            {
                errorMessage = "The sample rate of " + (uint)nudConvRate.Value
                    + " SPS has exceeded the maximum limit of "
                    + maxRate.ToString()
                    + " SPS for the conversion mode, resolution and frequency.";
                m_errorProvider.SetError(nudConvRate, errorMessage);
                m_errorProvider.SetError(cbResolution, errorMessage);
                m_errorProvider.SetError(cbConvMode, errorMessage);
                m_errorProvider.SetError(tbClockFreq, errorMessage);
                retVal = false;
            }
            else if (theFreq < TheMinFreq)
            {
                errorMessage = "The sample rate of " + (uint)nudConvRate.Value +
                               " SPS has below the minimum limit of "
                    + minRate.ToString()
                    + " SPS for the conversion mode, resolution and frequency.";
                m_errorProvider.SetError(nudConvRate, errorMessage);
                m_errorProvider.SetError(cbResolution, errorMessage);
                m_errorProvider.SetError(cbConvMode, errorMessage);
                m_errorProvider.SetError(tbClockFreq, errorMessage);
                retVal = false;
            }
            else
            {
                m_errorProvider.SetError(cbResolution, String.Empty);
                m_errorProvider.SetError(cbConvMode, String.Empty);
                m_errorProvider.SetError(nudConvRate, String.Empty);
                m_errorProvider.SetError(tbClockFreq, String.Empty);
                retVal = true;
            }

            if (saveValue)
            {
                SetAParameter(sSampleRate, nudConvRate.Value.ToString(), false);
            }
            tbClockFreq.Text = theFreqKHz.ToString("0.000");
            lbSPSRange.Text = MESSAGE_RANGE + minRate.ToString() + " - " + maxRate.ToString() + MESSAGE_RANGE_END;

            return retVal;
        }
 private void CheckRefVoltage(CyNumericUpDown nudRefVoltage, ComboBox cbReference)
 {
     m_errorProvider.SetError(nudRefVoltage, String.Empty);
     decimal retVal = (decimal)GetVDDAValue();
     if (cbReference.Text.Contains(INTERNAL_VDDA_4))
     {
         retVal /= 4;
         nudRefVoltage.Value = retVal;
     }
     else if (cbReference.Text.Contains(INTERNAL_VDDA_3))
     {
         retVal /= 3;
         nudRefVoltage.Value = retVal;
     }
     if (nudRefVoltage.Value > MAX_VREF_VALUE)
     {
         // We will not force the value to be Max value.
         string errorMessage = string.Format("Error: Parameter should be within value {0}-{1}\n",
             MIN_VREF_VALUE, MAX_VREF_VALUE);
         m_errorProvider.SetError(nudRefVoltage, errorMessage);
         m_errorProvider.SetIconAlignment(nudRefVoltage, ErrorIconAlignment.MiddleLeft);
     }
     else if (nudRefVoltage.Value < MIN_VREF_VALUE)
     {
         // We will not force the value to be Min value.
         string errorMessage = string.Format("Error: Parameter should be within value {0}-{1}\n",
             MIN_VREF_VALUE, MAX_VREF_VALUE);
         m_errorProvider.SetError(nudRefVoltage, errorMessage);
         m_errorProvider.SetIconAlignment(nudRefVoltage, ErrorIconAlignment.MiddleLeft);
     }
 }
        // Check what combination of Input Range and Reference is selected
        private void UpdateRefVoltageEnable(int index, Control cbReference, Control cbInputRange, Control label, 
            CyNumericUpDown nudRefVolt)
        {
            UnhookAllEvents();

            nudRefVolt.Enabled = false;
            decimal refVtg = GetRefVoltage(index);
            if (cbReference.Text.Contains(REF_EXTERNAL) || (cbInputRange.Text.Equals(RANGE_VSSA_TO_VDDA)))
            {
                nudRefVolt.Enabled = true;
                if (cbInputRange.Text.Equals(RANGE_VSSA_TO_VDDA))
                {
                    // label_Warning.Text += "r-vda";

                    label.Text = LABEL_VOLTS_VDD;
                    decimal retVal = (decimal)GetVDDAValue();
                    if (retVal < MAX_VDDA3_VALUE)
                    {
                        retVal /= 3;
                    }
                    else
                    {
                        retVal /= 4;
                    }
                    // FOR display purpose and hence this will not be validated.
                    nudRefVolt.Value = retVal;
                    nudRefVolt.Enabled = false;
                }
                else
                {
                    label.Text = LABEL_VOLTS;
                    nudRefVolt.Value = refVtg;
                }
            }
            else
            {
                if (!(cbReference.Text.Contains(INTERNAL_VDDA_4) || cbReference.Text.Contains(INTERNAL_VDDA_3)))
                {
                    label.Text = LABEL_VOLTS;
                    // TODO: This depends on the VDDA values.
                    nudRefVolt.Value = refVtg;
                    nudRefVolt.Value = VREF_INT_VALUE;
                    nudRefVolt.Enabled = false;
                }
            }
            HookAllEvents();
        }