LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using DAQmx_Val_ChangeDetectionEvent as a sample clock

Hi Ian,

I have quite a bit of experience with playing with encoders in CVI, no my area of confusion is on the signal routing. I still think wiring A and B to a buffered event counter is the way to go unless there is a reason why not ?

So lets assume then that I have A and B connected to Digital Input Line0/Port0 and Line0:Port1 respectively and that the task is configured for change detection. The output will thus be a series of ChangeDetectEvents which I am told that I can route to various connections on the board. Great, lets route one to PFI1 and use that as the sampling source for the 6 analaogue inputs I mentions.

Now lets also route the ChangeDetectEvents to Counter 1's GATE (PFI4). Now lets route the 80Mhz timebase (or suitable timebase) to Couter 1's SOURCE (PFI3). Cool, now only have to configure the Counter 1 task for Buffered Event Counting and bob's yer uncle....i.e. it will count the number of ticks from the 80Mhz timebase between each Change Detect Event from counter 0.

My question is how to configure things as i've just described them above. If you could answer that or perhapps indicate someone who could then that would be great. Let me know if anything is unclear ?

thanks, Shaun.


0 Kudos
Message 11 of 18
(2,285 Views)

Hi Shaun,

To route the change detection event to the counter, use DAQmxExportSignal. If you open up the function panel of this, you have the option to choose “Change Detection Event” in the Signal ID field, and PFI1 in the Output Terminal field. You can route to PFI4 in the same way.

To route the 80MHz clock, pass DAQmx_Val_80MHzTimebase as the Signal ID argument (you may have to type this in manually rather than select it on the function panel) and select PFI3 as the output terminal.

If you have tried this method of signal routing to no avail then please send me the code you are using and I will investigate further.

For the buffered event counting:

  1. Open the Task.
  2. Use DAQmxCfgSampClkTiming to configure your counter source, active edge etc.
  3. Start the Task.
  4. Read the Samples continuously using the DAQmxReadCounterF64 function.
  5. Stop & Clear the task when you’re done.

Again if you have tried this already and haven’t got anywhere please send me the code so I can see where you are going wrong.

Regards,

Ian

0 Kudos
Message 12 of 18
(2,274 Views)
Hi ian,

I have attached my DAQ initialisation code which creates and starts the tasks. The problem I am still encountering is as follows:

When I use the signal ID you suggested, namely DAQmx_Val_80MHzTimebase, I get the following error:

    //Now route the 80MHz Timebase signal to the Source (PFI3) of the Timestamp Counter
    DAQmxErrChk (DAQmxExportSignal (
        envPtr->timestampsTaskHandle,
        DAQmx_Val_80MHzTimebase,
        "/Dev1/Ctr1Source"));       

Signal type requested to be exported is not valid.
Invalid Identifier: 1436

Task name: TimeStamps

Staus Code: -200374

When I use the 20MHz Timebase I get this error:

Signal type requested to be exported is not supported for the specified task running on the given device.
Property: DAQmx_Exported_20MHzTimebase_outputTerm

Task Name: TimeStamps

Staus Code: -200375

When I look at the
DAQmxExportSignal help I see that there is no 80Mhz signal option available.

Can you please let me know how I should route the 80Mhz signal to Counter 1 Source (PFI3) ?

Many thanks, Shaun.
0 Kudos
Message 13 of 18
(2,264 Views)

Hi Shaun,

Sorry for the delay. Before I talk about the counter clock, I’ve found this KB on event handling with DAQmx that may be a good reference in the future if you have any more problems with the change detection event.

http://digital.ni.com/public.nsf/allkb/DF5719473800838086256F1E0054FD7B?OpenDocument

Thanks very much for sending me your code. It’s very well documented and has made it allot easier for me to help so thanks for that. Also, after speaking with my colleagues I’ve gained a better understanding of why your code is not working:

  • You do not need to route the 80MHz clock into counter 1 manually. Instead CVI will automatically assign the 80MHz clock to the counter source using the DAQmxCfgSampClkTiming alone.
  • Also, make sure that you have a separate task for generating the change detection event, and counting that same event.

Best of luck Shaun; hope this helps,

Ian C.

0 Kudos
Message 14 of 18
(2,238 Views)
After a couple of days of literally trial and error i've managed to answer my own questions. I've attached the DAQ C source here for anyone who is looking to do something similar. I have to say the DAQ documentation is very scantily clad to say the least. Anyway, on with the solution.

1) I routed Quad Encoder A and B signals into the Digital IO Port 0, Lines 0 and 1, and configured it for Edge Change Detection.
2) I routed the same Quad Encoder A, B and Z signals into Counter 0 for position measurement.
3) I routed the ChangeDetectionEvent from (1) above to the GATE input of Counter 1 and configured it for Buffered Event Counting
4) I had to route the 80MHz clock to Counter 1's SOURCE input, consequently the Counter counts this clock's rising edges and then latches the value into buffer every time a ChangeDetctionEvent occurs from (1) above.
5) Finally, I used the same ChangeDetectionEvent from (1) as the sample clock for a seperate Analogue Input Task and the Quad Encoder Position Measurement described in  (2) above.

The end result is a set of timestamped and angle stamped analogue inputs, sampled on every detected rotation of the encoder.

And here's the source for reference.

Cheers, Shaun.



0 Kudos
Message 15 of 18
(2,221 Views)
Hi Steorn

               We trying to do almost the same task wat you were doing i.e triggering the analog acquisition on every rising and falling edge of the encoder.Our encoder is connected to the 9411 and analog acquisition is suppose to be done on 9215.Can you help us on this coz we are confused with how exactly to use change detection API to trigger analog acquisition.

Thanks a bunch


Eagerly waiting for your reply


0 Kudos
Message 16 of 18
(1,997 Views)
I don't think that you'd be able to use Steorn's program with your hardware (9411 & 9215).
0 Kudos
Message 17 of 18
(1,987 Views)
Can u Guide us on that.
0 Kudos
Message 18 of 18
(1,977 Views)