05-28-2009 02:54 AM
Hi,
i want to measure the high-level-time of a pulse-width modulated signal from a digital temperature sensor. I found the"Measure 2 Edge Separation" example in
"\Examples\DotNET2.0\Counter\Measure 2 Edge Separation\Meas2EdgeSeparation ", but i don't know how to give the output signal of the sensor to the couter of the pic6601. Should I coonect the sensor output to CTR 0 gate or source or what else?
Best Regards
05-28-2009 06:59 AM
Yeehaaw - measuring works. But there is a little speed problem.... Could you watch my code and give some hints to speed it up? The timer interval is 0,1s but I only get 3 values per second.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NationalInstruments.DAQmx;
namespace Window1
{
public partial class Form1 : Form
{
Task myTask1 = new Task("HighTime");
Task myTask2 = new Task("LowTime");
double high_time;
double low_time;
double temperature;
public Form1()
{
InitializeComponent();
myTask1.CIChannels.CreatePulseWidthChannel("Dev1/ctr0", "", 0.000001, 0.1, CIPulseWidthStartingEdge.Rising, CIPulseWidthUnits.Ticks);
myTask2.CIChannels.CreatePulseWidthChannel("Dev1/ctr0", "", 0.000001, 0.1, CIPulseWidthStartingEdge.Falling, CIPulseWidthUnits.Ticks);
}
void DoTemp()
{
try
{
CounterReader counterInReader1 = new CounterReader(myTask1.Stream);
CounterReader counterInReader2 = new CounterReader(myTask2.Stream);
high_time = counterInReader1.ReadSingleSampleDouble();
low_time = counterInReader2.ReadSingleSampleDouble();
// calculating temperature: Sensor TMP05
temperature = 421 - (751 * (high_time / low_time));
}
catch (DaqException exception)
{
timer1.Enabled = false;
MessageBox.Show(exception.Message);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
// 100 ms interval
DoTemp();
textBox1.Text = temperature.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
timer1.Enabled = false;
button1.Text = "Start";
}
else
{
timer1.Enabled = true;
button1.Text = "Stop";
}
}
}
}
05-29-2009 08:02 AM
Hi,
the problem is here: You create a new taskeverytime you call DoTemp()
CounterReader counterInReader1 = new CounterReader(myTask1.Stream);
this is very time consuming.
CounterReader counterInReader2 = new CounterReader(myTask2.Stream);
For a faster solution use
' Create the callback and start the first read asyncCB = New AsyncCallback(AddressOf CounterInCallback) counterInReader.BeginReadMultiSampleDouble(numberOfSamples, asyncCB, myTask)
instead. Take a loop at Meas2EdgeSeparation_BufCont.2008.sln example.
For further information on software vs hardware timing take a look at Top 10 Considerations for Your High-Speed Digital Application
Regards,
05-29-2009 09:32 AM
Hi, i removed the "new task creation" part from DoTemp() and placed in the Form1 constuctor.
The speed is still slow. (3 values per second).
In the NI Measurement and Automation Studio i created a task which fetches pulse width values from ctr0. This one is pretty fast and send about 10 values per second.
How does this work so fast? Could you tell me the configuration for such high speed?
P.s: Where can I get the told example? I only have exaples for VS 2003 & VS2005.
05-29-2009 10:13 AM