示例#1
0
文件: Program.cs 项目: piwi1263/nf429
        public static void Main()
        {
            try
            {
                // See if any analog stuff is still out there
                Console.WriteLine(AdcController.GetDeviceSelector());

                // Assign first ADC
                AdcController _ctl1 = AdcController.GetDefault();

                // Some stats to see we are alive
                Console.WriteLine("Channels    : " + _ctl1.ChannelCount.ToString());
                Console.WriteLine("Active mode : " + _ctl1.ChannelMode.ToString()); // 0=SingleEnded, 1=Differential
                Console.WriteLine("Resolution  : " + _ctl1.ResolutionInBits.ToString() + " bits");
                Console.WriteLine("Min value   : " + _ctl1.MinValue);
                Console.WriteLine("Max value   : " + _ctl1.MaxValue);

                // Now open a channel.
                // We don't need additional HW to test ADC.
                // if we use the internal temp sensor
                AdcChannel _ac0 = _ctl1.OpenChannel(AdcChannels.Channel_0);

                int _val1 = -1;

                // Loopie
                for (; ;)
                {
                    _val1 = _ac0.ReadValue();
                    Console.WriteLine("Value read from ADC = " + _val1);

                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                // Do whatever please you with the exception caught
                Console.WriteLine(ex.ToString());
                // Loopie
                for (; ;)
                {
                    Thread.Sleep(1000);
                }
            }
        }
示例#2
0
        public static void Main()
        {
            string devs = AdcController.GetDeviceSelector();

            Console.WriteLine("devs=" + devs);

            AdcController adc1 = AdcController.GetDefault();

            int max1 = adc1.MaxValue;
            int min1 = adc1.MinValue;

            Console.WriteLine("min1=" + min1.ToString() + " max1=" + max1.ToString());

            AdcChannel ac0 = adc1.OpenChannel(0);

            // the following indexes are valid for STM32F769I-DISCO board
            AdcChannel vref = adc1.OpenChannel(0);
            AdcChannel vbat = adc1.OpenChannel(8);

            // VP
            //AdcChannel ac3 = adc1.OpenChannel(3);
            // VN
            while (true)
            {
                int value     = ac0.ReadValue();
                int valueVref = vref.ReadValue();
                int valueVbat = vbat.ReadValue();

                double percent = ac0.ReadRatio();

                Console.WriteLine("value0=" + value.ToString() + " ratio=" + percent.ToString());
                Console.WriteLine("verf" + valueVref.ToString() + " ratio=" + percent.ToString());
                Console.WriteLine("vbat" + valueVbat.ToString() + " ratio=" + percent.ToString());

                Thread.Sleep(1000);
            }
        }
示例#3
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard.AdcTest starting");
            Debug.WriteLine(AdcController.GetDeviceSelector());

            try
            {
                AdcController adc        = AdcController.GetDefault();
                AdcChannel    adcChannel = adc.OpenChannel(0);

                while (true)
                {
                    double value = adcChannel.ReadRatio();

                    Debug.WriteLine($"Value: {value:F2}");

                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }