01-04-2024 11:07 AM
I'm using a cDAQ-9133 with the 9215 voltage input module to collect some data. I also have a 9402 digital IO module.
I want to synchronize the data collection to an external TTL signal, that fires a pulse every 40'th microsecond.
I want to use that signal to trigger data acquisition every N'th pulse.
So I connect the signal to a counter and compare the count value to create a trigger signal, but I need to reset the counter.
The DAQMX Counter Input channel property node has a CountEdges.CountReset.Enable and a CountEdges.CountReset.ResetCount property, so I would expect that these could be used to reset the counter value, but no luck there. Is it possible to reset the counter based on either a boolean flag or a preset counter max value ?
I noticed that "counter reset" gets ~950 hits on this community 😲.
FYI, I'm not experienced in LabVIEW !!!
01-05-2024 06:13 AM
I don't know the 9215 specifically, but from the spec sheet it appears to use an SAR style converter. Therefore, I expect the following ought to be possible:
- configure the repeating 40 usec (25 kHz) pulse to be used as your task's "sample clock timebase".
- you can then also configure the sample clock timebase divisor to be =N.
- then every Nth pulse causes a single sample to be captured
The above assumes that you want a single sample to be captured every N external pulses. If you truly want to re-trigger a multi-sample acquisition every N pulses, there's a little different way to use a counter that might be simpler.
Configure the counter for pulse generation using "Ticks" as the units. Set the total pulse period to be N Ticks and configure the counter to use the 40 usec pulse as its timebase. Then configure the AI task to use the counter output as its trigger and configure the task to be retriggerable (assuming your DAQ hardware supports retriggering).
-Kevin P
01-22-2024 05:03 AM - edited 01-22-2024 05:05 AM
Hi Kevin.
I tried using the TTL pulse (the 25 kHz pulse) as the sample clock timebase for the 9215, and then determine a suitable timebase divisor. I don't think the 9215 supports timebase division when using external clock as I get errors hinting at this.
As I'm still relatively novice in LabVIEW (DAQMX), I'm not able to use the counter output as the timebase for the 9215.
Hence, I've connected the TTL pulse to a 9402 DIO, at channel 0 - using it as the counter ticks. The counter output is directed to the next channel on the DIO, and the only way I'm able to use the counter output is to connect it to the third channel, and then use that channel as the timebase for the 9215:
Please allow me to show the VI for the counter output task:
CounterOutputTask VI block diagram
CounterOutputTask HMI
and the VI for the analog read task:
AnalogReadTask VI block diagram:
AnalogReadTask VI HMI:
I'm thinking this is a bit "hacky" solution. What do you think ?
Also, I would like to read the digital input channel, i.e. the counter output signal, in the same VI as I'm reading the analog input to see when the measurements are triggered. I'm trying to do this in the next block diagram, running simultaneously with the counter output task VI shown in the top figure:
DigitalAndAnalogReadTask block diagram:
DigitalAndAnalogReadTask HMI
From the HMI, we see that the clock source PFI2 (channel 2 on the 9402) is firing consistently, but no samples are read by the 9215... I'm guessing there are race conditions or something. What do you think ?
01-31-2024 12:12 PM
Part 1: Do I think it's too "hacky?"
No, not particularly. I find it simpler to do signal routing programmatically without physical wires and screwdriver work, but there's nothing wrong with your more physical routing method, especially since that's what you already understand well and already have in place.
However, I'd recommend you at least consider reading multiple samples per AI read instead of only 1. (Not sure of your actual rate since your front panel values and OP description aren't fully consistent with one another. But I wouldn't bother trying to update a chart any faster than 5-10 times a second which is already much faster than a human operator can notice and react to anything they see.)
Part 2: Reading the counter output clock signal
Well, now there's several problems.
1. What are you trying to capture about the output clock? The full square waveform? Or just a count of the # cycles?
2. Either way, you shouldn't be trying to do it with software-timed DI task. Nor by calling DAQmx Timing to use the counter output clock itself as a DI sample clock.
3. You've also added data dependencies between your DI loop and AI loop such that the DI loop must end before the AI loop will be allowed to begin. (And it's then likely to end immediately on the first iteration.)
So first and foremost, what are you wanting to know about that counter output clock that has you setting up a DI task to try (unsuccessfully) to find out?
-Kevin P
02-01-2024 12:21 PM - edited 02-01-2024 12:22 PM
Thanks Kevin.
Regarding the first part and routing signals programmatically. This is exactly what I'm aiming for. Should I be able to use the counter output as the timebase for the 9215 ? The way I did it uses three channels on the 9402 DIO, when really it should be possible to do the same using only one channel: i.e. the 25 kHz TTL input. If you know how to do it without "shorting the terminals" (is this the correct phrasing?), then please share.
I'm not sure why you write that the front panel settings and the OP are inconsistent... Do you mean the sample rate in the figure "AnalogReadTask VI HMI " ?
Regarding the second part.
1. I wanted to capture the counter output waveform (which is wired from ch1 to ch2 on the 9402 DIO module) just to demonstrate visually that this is the triggering signal for the 9215 measurements. This is not a VI that normally would run during data acquisition, and also the VI would not run simultaneously with the AnalogReadTask VI.
2. When you say that the DI is software-timed, is this due "wait until next millisec" function in the while-loop ? Also, note that the DAQmx timing function is used for the AI task and not for the DI task. I'm trying to set up two tasks running in parallel in the same VI. One that reads the digital input (9402-ch2) and one that reads the analog input (9215-ch3).
3. I guess the data dependency is due to tunnelling between the loops ? I think this is the problem with that VI. I'm not able to check as I'm writing this at home, but I will delete the tunnels and test tomorrow.
Ronny
02-01-2024 02:02 PM
I haven't used a cDAQ with embedded controller but have a lot of general experience with NI DAQ devices and DAQmx. Some stuff I know well, and where I don't, I'll point it out.
I would *expect* you to be able to use the 25 kHz pulse as a sample clock timebase for your 9215 module. But I've mainly worked with desktop and PXI devices which tend to support a great deal of flexibility for routing external signals to be used as specific internal functions such as a sample clock timebase.
I simply don't know whether your combo of devices has some specific limitations, so be sure to try each of the 4 possible DIO channels in case your routing options are limited. If it doesn't work for any of the 4 channels, please post your test code (back-saved if necessary to LV 2020 or earlier), and identify any errors or odd behavior.
RE: what looked "inconsistent" to me
You described the external signal as 25 kHz. Then your counter output screencap shows as being configured for 1000 low ticks and 1000 high ticks. The total period is 2000 ticks, resulting in a 25000/2000 = 12.5 Hz counter output.
But then your AI screencaps show this being used directly as a sample clock whose frequency you declare as 1 Hz.
This inconsistency made me unsure about your actual AI sample rate, which affects the advice about how many samples to read per iteration. If no more than 12.5 Hz, you're in the ballpark where reading 1 sample per iteration is probably acceptable, though I'd personally probably opt for something like 4 or 5.
And I'd also strongly recommend removing the msec timer in the AI loop. The request for samples from DAQmx Read will already set your loop timing without wasting CPU. And as a rule you shouldn't have 2 different mechanisms trying to control loop timing simultaneously.
1. I'm inclined to persuade you not to bother trying to capture that waveform because anything you might learn from it can be inferred in much simpler ways.
For starters, any half-decent capture of the clock waveform will require you to sample at a rate approaching or exceeding 10x the clock frequency so you get multiple samples during each high and low time. All that really does is prove that the clock signal is present and there are simpler ways to do that. Most simply, you can query the AI task for the total # samples acquired, knowing that you only get samples when the clock signal is working.
2. DI is software-timed primarily because you didn't call DAQmx Timing to set up any kind of hardware timing. This puts the task in "on-demand" timing mode where each call to DAQmx Read initiates a new reading with a fairly short but somewhat variable execution time. Hardware timing latches samples at precise times and accumulates them in buffers for later retrieval. The subsequent calls to DAQmx Read will again have fairly short and somewhat variable execution time, but the data samples returned from the buffering process will have been taken at extremely precise hardware-timed intervals.
The msec timer adds another important layer of software timing on the loop's iteration rate. This would likely to be the bigger source of timing variability between samples if you left your task in software-timed on-demand mode.
3. Yes, those tunnels are exactly the data dependency I meant.
-Kevin P