/// <summary> /// Constructs a new PWMResistive Heater /// </summary> /// <param name="deviceName">The device on which the pwm counter sits</param> /// <param name="pwmCounterName">The name of the counter to use</param> /// <param name="pwmCounterOutput">The pin on which to generate the output</param> public PWMResistiveHeater(string deviceName, string pwmCounterName, string pwmCounterOutput) { MinOutput = 0.001; //By default limit maximum duty cycle of this //heater to 50% MaxOutput = 0.5; //Set default generation frequency to 500 Hz _pwmSignal = new CODataFrequency(500, MinOutput); string connection = deviceName + "/" + pwmCounterName; //create our pwm task, set up a counter channelr on the output pin and configure it to run until stopped _pwmTask = new Task("ResistiveHeater_" + deviceName + pwmCounterName); _pwmTask.COChannels.CreatePulseChannelFrequency(connection, "", COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0, _pwmSignal.Frequency, _pwmSignal.DutyCycle); _pwmTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples); _pwmTask.ExportSignals.CounterOutputEventOutputTerminal = pwmCounterOutput; //create writer _pwmWriter = new CounterSingleChannelWriter(_pwmTask.Stream); //start task _pwmTask.Start(); _pwmWriter.WriteSingleSample(false, _pwmSignal); }
/*public string[] PeltierModes { * get { return Enum.GetNames(typeof(PeltierMode)); } * }*/ /// <summary> /// Constructor of Peltier control class /// </summary> /// <param name="deviceName">The device name of the NI board, f.e. dev1</param> /// <param name="pwmCounterName">The name of the counter to use for this peltier, f.e. ctr0</param> /// <param name="pwmCounterOutput">The pinout of the counter (?) f.e. PFI12</param> /// <param name="pwmFrequency">The frequency of the PWM on the counter</param> /// <param name="heatingPolarityDOLine">The digital out line for the polarity switch</param> public Peltier(string deviceName, string pwmCounterName, string pwmCounterOutput, double pwmFrequency, string heatingPolarityDOLine) { if (ViewModelBase.IsInDesignMode) { DutyCycle = .2; PeltierMode = PeltierModes.Heat; return; } doHeatingPolarityTask = new Task(); doHeatingPolarityTask.DOChannels.CreateChannel(deviceName + "/" + heatingPolarityDOLine, "", ChannelLineGrouping.OneChannelForAllLines); doHeatingPolarityWriter = new DigitalSingleChannelWriter(doHeatingPolarityTask.Stream); PeltierMode = PeltierModes.Heat; dataFrequency = new CODataFrequency(pwmFrequency, MinDutyCycle); pwmTask = new Task("Peltier " + deviceName + " " + pwmCounterName); pwmTask.COChannels.CreatePulseChannelFrequency(deviceName + "/" + pwmCounterName, "", COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0, dataFrequency.Frequency, dataFrequency.DutyCycle); pwmTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples); pwmTask.ExportSignals.CounterOutputEventOutputTerminal = pwmCounterOutput; pwmWriter = new CounterSingleChannelWriter(pwmTask.Stream); pwmTask.Start(); DutyCycle = 0; }