12-18-2013 02:47 PM
I connect an optical encoder (angular) to a counter pinout of digital io part of the card. I get correct positioning from 10 degrees and above. I get wrong values if i tried to move from 1 to 10 degrees.
Can you help me about this problem please?
Thank you very much.
12-19-2013 01:51 AM
In ordrer to help, we need more details :
LV ships with some examples showing how to achieve this task.
12-19-2013 03:25 AM
Hi,
I used NI USB 6221 DAQ board and EM1 optical encoder from US Digital.
By wrong values I mean wrong positioning from 10 and less degrees. from 10 degrees and above my arm rotated correctly.
I connected the same optical encoder on this card, in the same way, but for linear motion and works perfectly (I tested it using digital caliper).
Actually, I translate the edgecounter value coming from the card to degrees by using the following formula:
edgecount = ((2500 * (degress)) / 360)
I used the following C Shapr function to get the edgecounter value
private void getEdgeCounterValuethita(int maxvaluethita, int direction)
{
Cursor.Current = Cursors.WaitCursor;
try//try block for catching unnecessary errors
{
using (Task CounterReadTask = new Task())//create new Task and using it
{
deviceid = cmbdeviceid.Text;//store the selected the dev ID
//create a counter read task by adding the parameters to the counter input channel
CounterReadTask.CIChannels.CreateCountEdgesChannel(deviceid + "/ctr1",
"", edgeType, Convert.ToInt64("0"), countDirection);//counter type and direction
//set timing parameters to the counter reader task
CounterReadTask.Timing.ConfigureSampleClock(deviceid + "/PFI3",
Convert.ToDouble("100000.00"), SampleClockActiveEdge.Rising,
SampleQuantityMode.FiniteSamples, Convert.ToInt32("100000"));
runningTask = CounterReadTask;
//create an instance of the counter reader configure above
myCounterReader = new CounterReader(CounterReadTask.Stream);
//initialize the variables to zero each time to call the function
double data = 0;
int currposition = 0;
while (data < maxvaluethita)//compare curreent value with requir value
{
data = myCounterReader.ReadSingleSampleInt32();//getting an integer number of lines read so far during the motion
}
stopmotors();//stop the current motion
//if block statement for desiding the correct direction of the motion and update the interface
//1 for cw and 0 for ccw
if (direction == 1)
{
//data = (360 * (data + 30))/2500;//convert the edgacount back to degrees
currposition = Convert.ToInt32(txtthitaposition.Text) + Convert.ToInt32 (txtthitacw.Text);//calculate the current position
txtthitaposition.Text = currposition.ToString();//store the current postion to the text box control
addCommandToHistoryList("ClockWise rotation on Θ Axis " + txtthitacw.Text + " degress, ");
}
else
{
//data = (360 * (data + 30)) / 2500;//convert the edgacount back to degrees
currposition = Convert.ToInt32(txtthitaposition.Text) - Convert.ToInt32(txtthitaccw.Text);//calculate the current position
txtthitaposition.Text = Convert.ToString(currposition);//store the current position to the text box control
addCommandToHistoryList("Counter ClockWise rotation on Θ Axis " + txtthitaccw.Text + " degress, ");
}
}
}
catch (DaqException ex)//catch any errors during the execution of the try block
{
MessageBox.Show(ex.Message);//message after catching an error
}
finally
{
Cursor.Current = Cursors.Default;
}
}
12-19-2013 06:07 PM
Hi christ's,
When you mention that you are able to use this encoder correctly as a linear encoder, are you using the same code with a different conversion? I would be interested in seeing if this is a simple conversion formula error.
Also, you are doing a lot of conversions. First, you are reading an Int32 into a double (data) and then doing some string conversion. Those might induce rounding errors that could affect the smaller optical encoder counts.
What sort of edge count number are you recording for 1 to 10 degrees? You might want to run a simple built-in example to see if the edge count actual number (not the converted angle) updates properly in that range.
Hope this helps,