06-05-2007 02:10 PM
06-06-2007 11:13 PM
06-07-2007 02:19 PM
Hi Raajit,
The application is a production test fixture for a resolver position feedback device.
Long story short, it uses a very accurate encoder on the same shaft as the resolver to
verify the accuracy of the resolver.
There are 4 counters involved. 0 & 1 are up/down counters that are used to keep track of the
position of the resolver and the encoder. Counter 2 also is connected to the encoder
and is used to generate a pulse every n resolver counts. This counter is programmed to generate
"n" pulses per revolution. Its output is wired to the gate input of 1 & 2 and is used to clock in
the samples. The gate input to counter 3 is wired to the encoder's index pulse (once every 360 degrees)
and is used to trigger the start of the data capture (Ctr 3 doesn't do any counting, just a trigger).
***** Traditional NI-DAQ *******
Here's a snippet the old traditional NI-DAQ code used to set up one of the counters
// ************ Configure Counter 0 to collect position information *************
// start the counter operation
GPCTR_Control (pSc->boardNum, pSc->counterNumber, ND_RESET);
// set the counter for buffered event counting
GPCTR_Set_Application (pSc->boardNum, pSc->counterNumber, ND_BUFFERED_EVENT_CNT);
// set the data buffer and number of samples to collect
GPCTR_Config_Buffer (pSc->boardNum, pSc->counterNumber, 0, pSc->sampleCount, pSc->positionCounterBuffer);
// use hardware control of the direction line
GPCTR_Change_Parameter (pSc->boardNum, pSc->counterNumber, ND_UP_DOWN, ND_HARDWARE);
// count on falling edge
GPCTR_Change_Parameter (pSc->boardNum, pSc->counterNumber, ND_SOURCE_POLARITY, ND_HIGH_TO_LOW);
// Set the initial count
GPCTR_Change_Parameter (pSc->boardNum, pSc->counterNumber, ND_INITIAL_COUNT, pSc->initialCount);
// Set to count in synchronous mode
GPCTR_Change_Parameter (pSc->boardNum, pSc->counterNumber, ND_COUNTING_SYNCHRONOUS, ND_YES);
// set the counter to use a hardware trigger.
GPCTR_Change_Parameter (pSc->boardNum, pSc->counterNumber, ND_START_TRIGGER, ND_ENABLED);
// select the output of counter 3 ( which is the sample clocke ) as the trigger
Select_Signal (pSc->boardNum, ND_START_TRIGGER, ND_PFI_27, ND_LOW_TO_HIGH);
// start the counter operation
GPCTR_Control (pSc->boardNum, pSc->counterNumber, ND_PREPARE);
In another section of code in the traditional NI-DAQ version I used:
GPCTR_Watch (DAQ_DEVICE_NUM, ND_COUNTER_0, ND_ARMED, &isArmed0);
to see if the data collection for that revolution had started and reported status to the screen:
QUESTION IS: How do I accomplish the above line of code in NI-DAQmx?
***** DAQmx *******
The DAQmx setup code looks similar to:
// create the CTR0 task
DAQmxCreateTask("",&dthCounter0Enc);
// Use ctr0 on the PCI-6602 to count edges from the encoder
DAQmxCreateCICountEdgesChan ( dthCounter0Enc, appendToDeviceName( strTemp, daqDevNameStrPCI6602, "ctr0" ),"",DAQmx_Val_Falling,0,DAQmx_Val_ExtControlled );
// Used to be called synchronous counting mode
DAQmxSetChanAttribute (dthCounter0Enc, "", DAQmx_CI_DupCountPrevent, 1);
// initial count
DAQmxSetChanAttribute (dthCounter0Enc, "", DAQmx_CI_CountEdges_InitialCnt, pSc->initialCount);
// sample on the falling edge to allow direction signal to set up
DAQmxCfgSampClkTiming (dthCounter0Enc, appendToDeviceName( strTemp, daqDevNameStrPCI6602, "PFI38" ), MAX_EXPECTED_CNT_SAMPLE_RATE, DAQmx_Val_Falling, DAQmx_Val_FiniteSamps, pSc->sampleCount );
// Triggering the counter requires an "arm-start" style trigger. The next 3 calls set it up
DAQmxSetTrigAttribute ( dthCounter0Enc, DAQmx_ArmStartTrig_Type, DAQmx_Val_DigEdge );
// PFI27 is the source input input to CTR 3 and is used as the trigger. It is connected to the encoder index pulse
DAQmxSetTrigAttribute ( dthCounter0Enc, DAQmx_DigEdge_ArmStartTrig_Src, appendToDeviceName( strTemp, daqDevNameStrPCI6602, "PFI27" ) );
// trigger on the rising edge
DAQmxSetTrigAttribute ( dthCounter0Enc, DAQmx_DigEdge_ArmStartTrig_Edge, DAQmx_Val_Rising );
// start the encoder counter
DAQmxStartTask(dthCounter0Enc);
Thanks,
Kirk
06-11-2007 02:04 PM