Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

obtaining time from 6024e

Currently i am using the 6024e card to do quadrature counting from a rotary encoder to obtain the distance travelled when the encoder rotated.

However i need to obtain the velocity. How do i obtain time from the DAQ 6024e card?

Currently i use these functions to obtain and print the number of counts from the encoder.

/*ND_COUNTER_0 for right wheel*/
GPCTR_Control (1, ND_COUNTER_0, ND_RESET);
GPCTR_Set_Application (1, ND_COUNTER_0, ND_SIMPLE_EVENT_CNT);
GPCTR_Change_Parameter (1, ND_COUNTER_0, ND_UP_DOWN, ND_HARDWARE);
GPCTR_Change_Parameter (1, ND_COUNTER_0, ND_INITIAL_COUNT, 10000000);
GPCTR_Control (1, ND_COUNTER_0, ND_PROGRAM);

/*ND_COUNTER_1 for left wheel*/
GPCTR_Control (1, ND_COUNTER_1, ND_RESET);
GPCTR_Set_A
pplication (1, ND_COUNTER_1, ND_SIMPLE_EVENT_CNT);
GPCTR_Change_Parameter (1, ND_COUNTER_1, ND_UP_DOWN, ND_HARDWARE);
GPCTR_Change_Parameter (1, ND_COUNTER_1, ND_INITIAL_COUNT, 10000000);
GPCTR_Control (1, ND_COUNTER_1, ND_PROGRAM);

/*ND_COUNTER_0 for right wheel*/
GPCTR_Watch (1, ND_COUNTER_0, ND_COUNT, &counterValue1);
printf("The initial count for right wheel is %d\n", counterValue1);


/*ND_COUNTER_1 for left wheel*/
GPCTR_Watch (1, ND_COUNTER_1, ND_COUNT, &counterValue2);
printf("The initial count for left wheel is %d\n", counterValue2);

Now i need to obtain the a certain time interval for example 50ms. How do i do that?

regards,

Leroy
0 Kudos
Message 1 of 4
(2,780 Views)
Hi Leroy,

Typically, a counter is used to determine time by using the number of counts of a known timebase. For example, if you are using the internal 100kHz timebase you can count the number of pulses between a start event and an end event. By dividing the count by the timebase you can obtain the time period.

However, in your case you are using both counters for position measurement so you don't have any left over for time measurement.

Based on this I can only think of 2 possible solutions. The first would be to use software timing. You would check the system time before programming your counters and you would check the time again after reading your count value. The difference will give you the period of time. This, however, is inaccurate
for small periods of time and is system dependent. Another option is to use your analog input to measure time. I'm not sure how much more accurate this method will be though. You would trigger an analog input operation to begin on one channel when you want to start measuring time. You would end your analog input when you want to stop. You would select the internal timebase (100kHz or 20MHz) as your sample clock. Once you are finished, you can determine the size of the array that is returned (elements that have a value) and divide that number by the timebase to obtain time. My suggestion would be to apply the 5V board signal to the analog input. I would also suggest using a start trigger and a reference trigger to obtain hardware timing. Although this method is more complicated to program, it might do the trick.

Anyway, I hope that helps. Have a good day.

Ron
Applications Engineering
National Instruments
Message 2 of 4
(2,780 Views)
Can we just use software to do the timing.. i.e. use Labwindow to do an interrupt every 2ms and read the encoder each time. the difference in counts divided by 2ms will give the velocity.
0 Kudos
Message 3 of 4
(2,780 Views)
That would work just fine. However, there will be a small amount of jitter in the clock. This means it will be 2ms +/-[small amount]. If you extend your time to 10ms or 100ms, this small amount becomes less and less significant allowing you to take more accurate velocity measurements.

Either way that's a good way to do it.

Ron
0 Kudos
Message 4 of 4
(2,780 Views)