Hey guys, I've been working on this code for roughly an hour, but have stumbled upon an issue with my InputPort class. I've used this MANY times, but for some reason my Visual C# is angry at me... Here are the errors, for both Frequency_Pot and Duty_Pot (haha duty pot... ).
Also, when the .SetPulse is written, and the program loops back to the top, will I have an issue with re-writing the .SetPulse and setting the output to High or Low over and over again, resulting in an infinite High or Low output? Or does it wait till the 'period' is completed before assigning the new 'period' and 'duration'? If so, how do I fix this?
Here's the code:
using System;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace PWM_Tester{ public class Program { public static void Main() { AnalogInput Frequency_Pot = new AnalogInput(Pins.GPIO_PIN_A0); AnalogInput Duty_Pot = new AnalogInput(Pins.GPIO_PIN_A1); PWM Test_PWM = new PWM(Pins.GPIO_PIN_D13); double Freq_Hz_Bits = Frequency_Pot.Read(); double Duty_Cycle_Bits = Duty_Pot.Read(); double Freq_Hz_Scale = Freq_Hz_Bits / 1023; // To scale from 0-1 double Duty_Cycle_Scale = Duty_Cycle_Bits / 1023; // To scale from 0-1 int Duty_Cycle = (int)(Duty_Cycle_Scale * 100); // To scale from 0-100% uint PWM_Min = 0; // In Hz uint PWM_Max = 400; //In Hz int Freq_Hz = (int)(PWM_Min + (Freq_Hz_Scale * (PWM_Max - PWM_Min))); uint period = (uint)((1 / Freq_Hz) * 1000 * 1000); // Period in usec (*microseconds*) uint duration = (uint)(Duty_Cycle_Scale * period); // Duration in usec Test_PWM.SetPulse(period, duration); Debug.Print("Duty Cycle = " + Duty_Cycle + "%"); Debug.Print("Frequency = " + Freq_Hz); } }}
Thanks a lot!!