Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set counter input source, gate and output

Solved!
Go to solution

I am trying to route the internal timebase 20 MHz clock as an input to a counter source on a M series PXI - 6289 card as shown below: 

V_lab_0-1707499289549.png

 

I want to also use a trigger to the gate to generate a 10 MHz clock on the output which I want to then use as a clock for a digital line (this is described on page 117 of the manual M Series User Manual - National Instruments (ni.com) as Continuous pulse train generation). I have been using MATLAB so far and cannot figure out how to connect the internal 20 MHz timebase to the source of the counter. I've tried using the addinput function, addoutput function, addtrigger function in different combinations, but run into issues like you can't add an input to an output counter, for example.

 

I'm open to using daqexpress, python, labview, or literally anything to achieve this. I also tried doing this in daqexpress and could not figure out how to access each of the counter terminals (for example, why can't we just have a counter object and be able to put signals into the input source, gate, etc... and measure an output??). If anyone could provide any guidance that would be tremendously helpful. Thanks a lot!

 

0 Kudos
Message 1 of 4
(645 Views)
I selected outputs/terminals based on the suggested available options coupled with this information:
 
 
V_lab_2-1707506555414.png
V_lab_3-1707506853278.png

 


 

Here is an example of something I tried:

 

%% Power test board through stim daq
% Battery and NI DAQ connection must be connected to stimdaq
clear all
% Load Daq and device info
d = daqlist;
d(1, 🙂
d{1, "DeviceInfo"}
deviceID = d{1,2}; % chooses the slot, 1 = slot4; 3 = slot6 (breakout)
dq = daq("ni");
 
addoutput(dq,deviceID,"ctr0","PulseGeneration") % Add output of counter 0, PFI12, P2.4
addtrigger(dq,"Digital","StartTrigger","External","PXI1Slot4/PFI9") % Define trigger to counter 0 gate, PFI9, P2.1
addclock(dq,"ScanClock","PXI1Slot4/20MHzTimebase","PXI1Slot4/Ctr0Source") % Add 20 MHz clock
 
>> I get the error "Cannot specify the same device as both the source and destination for 'PXI1Slot4'." when trying to do the add clock option.
 
I've also tried addinput to target the ctr0 source terminal (defined as port2/line0 in the input, see earlier image):
%% Power test board through stim daq
% Battery and NI DAQ connection must be connected to stimdaq
clear all
% Load Daq and device info
d = daqlist;
d(1, 🙂
d{1, "DeviceInfo"}
deviceID = d{1,2}; % chooses the slot, 1 = slot4; 3 = slot6 (breakout)
dq = daq("ni");
 
addinput(dq, deviceID,"port2/line0","Digital") % Add the input to counter 0 source, PFI8, P2.1
addoutput(dq,deviceID,"ctr0","PulseGeneration") % Add output of counter 0, PFI12, P2.4
addtrigger(dq,"Digital","StartTrigger","External","PXI1Slot4/PFI9") % Define trigger to counter 0 gate, PFI9, P2.1
 
>> I get, "Warning: Added channel does not support clocked sampling: clocked operations are disabled. Only on-demand operations are allowed." So this technically works, but I need to route the 20 MHz timebase to this terminal somehow and it is only accessible internally. Additionally, I don't think this is the correct way to target the counter source.
 
 

 

 

0 Kudos
Message 2 of 4
(625 Views)
Solution
Accepted by topic author V_lab

It's simpler to produce a 10 MHz output using the internal 80 MHz timebase.  It's *possible* with the 20 MHz timebase, but demands more non-default config work to set up properly.

 

I can only help with LabVIEW though I strongly suspect Python would give you access to the needed config.  Probably not DAQExpress though and maybe not Matlab either (over the years I've seen a number of threads identifying ways the Matlab API into NI's hardware is limited).

 

The good news is that it should be a pretty simple mod to one of the shipping examples named "Counter - Continuous Output.vi".   I simply expanded the DAQmx Channel property node to add the top property 'CO.CtrTimebaseSrc' to the three that were already there.  (I right-clicked to make it a "write" field rather than a "read" field, then right-clicked again to create a front panel control).  On the front panel you can then select the 80 MHz timebase for your device and configure your trigger.

 

                                                 Kevin_Price_0-1707507804783.png

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 4
(617 Views)

Thank you so much for this! I also found this example which helped me understand the MATLAB approach (Generate Pulse Width Modulated Signals Using NI Devices - MATLAB & Simulink (mathworks.com)). It abstracts the notion of the counter and I am not entirely sure which timebase it is using behind the scenes to generate the desired output frequencies. 

 

I also will look into your solution in LabView as I assume that is the less abstracted more straight forward way. My application is very sensitive to timing so I assume I might have to use this to synchronize everything later on.

 

Thanks again!

0 Kudos
Message 4 of 4
(597 Views)