Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

multichannel synchrobized counter output daqmx C#

Solved!
Go to solution

Hello,

 

I am facing the following problem:

 

I am operating a piezocontroller to move a microscopic sample. The piezo allows me to scan X-Y areas of the sample. At each position of the scan (at each "pixel") I count photons to image the sample. The photon counting is a simple pulsewidth measurement and is not important here.

 

What is important though is that I have two kinds of piezo controllers in different setups. One controller is digital and I can send it the coordinates of the area to scan. The controller then allows me to define 4 output triggers to sync piezo movement with other operations such as opening and closing shutters, photon counting after each move of the stage to a new positon etc...

 

However, the second controller is an analog one that only allows me to set voltages to move the stage. If I want to recreate the functionality of the digital controller I have to create the four trigger lines myself.

 

My solution therefore needs to look like this:

 

a) I have one "master clock" that ticks with a cycletime of 200 microseconds. At each tick of this clock the voltages to my piezo for X and Y motion are incremented. The master clock ticks are also the triggers for the photon counting tasks at each position.

b)  The four trigger lines, used for various purposes, should behave as described in both of the attached screenshots (images say more than a million words!).If it takes for instance 1000 ticks of the master clock to complete one scanline, then trigger line 1 should for instance be set high the first 500 ticks, trigger line 2 should be high the next 500 ticks while trigger line 3 should be high the whole time. This behavior should repeat every scanline etc etc...

 

Is it possible to have this kind of coordination betweeen the output of 4 counters on say, a 6601 board?

 

Any help would be greatly appreciated!!!

0 Kudos
Message 1 of 15
(8,538 Views)

Hi KrisJa,

 

It sounds like this should be achievable with counters.  Parameters used to configure a counter output task consist of an initial delay, high time, and low time,  by adjusting these you can configure the relative start times of each of the trigger signals, as well as the duration of the pulses in terms of ticks of the 200 us clock.

 

Do you have the option of starting the master clock after the counters or is this a "free running" clock?  If the clock is free running, you would have to trigger the counters off of the same signal so they start at the exact same time.  If the clock is not free running, you could simply start it after you start all of the counter tasks.

 

 

Depending on what hardware you have available, another option would be to use hardware-timed digital I/O.  With an external clock (which it sounds like you have), you can do clocked digital I/O on our 622x, 625x, and 628x M Series boards.  The benefit of using clocked Digital I/O instead of counters is that you could generate an arbitrary digital waveform to be clocked off of the sample clock.

 

If you are purchasing new hardware for this application, I would recommend taking a look at our new X Series line of Multifunction DAQ devices.  These boards have 4 counters available with more features than the older 6601 and M Series and are priced very comparably.  The X Series boards also support Hardware-Timed Digital I/O and Analog Input/Output, so you could likely control the entire application with a single board (PCIe-6321 for example).

 

 

-John

John Passiak
0 Kudos
Message 2 of 15
(8,496 Views)

Hello John,

 

Thanks for the input. The clock does not need to be free running at all. So I can set up loads of counter tasks and trigger them all from my master clock or something similar. I already considered this option. It will be a bit tedious todo but it should work in the end although I might have to buy anoter 6602 board to have enough counters.

 

Regarding the X series. Would it be possible to do something like the following;

 

1) Have a digital line

2) Have a counter count some event

3) When the counter hits some pre set (but changeable) value, switch the state of said digital line.

 

If this were to be possible it would make things a lot easier for my application...

 

I had some contacts with local NI engineers here in Belgium but they were leaning more to recommending use of an FPGA board for things like this (because in principle, I could program the FPGA to behave exatly like the custom built digital controller I use on some setups), but this seems overkill to me. Also I do not think it would be possible to use some kind of C# api to program the FPGA or to adjust some values (like no. of counts before switching a digital line) during its operation... I would really like to keep my application pure C# or C++ without having to venture too much into labview itself.

0 Kudos
Message 3 of 15
(8,483 Views)

Hi KrisJa,

 

You may use the digital lines of the X series to accomplish this.  One way you could do so is to set the external event to be the sample clock for the digital line.  Then, build an array of digital values to generate such that the line will go high after the desired amount of ticks.  For example, to have the line go high on the 5th event--generate the array [0, 0, 0, 0, 1, 1 ...]. 

 

You could also use a counter to accomplish something similar--one method to look into would be a "Pulse Generation" task.  Another may be to take advantage of the fact that our counters generate an event when they roll-over.  You could set the initial value of the counter to (Max_Value - N), so that an event is generated after counting N events--this way you could still use a "Count Edges" task.

 

I agree that an FPGA board would likely be overkill for what you need to do.  I think using the digital lines of the X series would be worth looking into since they offer up to 32 clocked lines.  Although all output lines must share the same sample clock and trigger, you could find the "lowest common denominator" clock to use as your sample clock.

 

With Best Regards,

John

John Passiak
0 Kudos
Message 4 of 15
(8,472 Views)

I took part of this discussion to another topic (which maybe was not so smart 🙂 but to keep the overview I will post this content here:

 

Hi guys,

I drew up a schematic of one of the applications I need to get running in our lab. To recap:

1)      We have several piezo controllers for nanopositioning of samples under a microscope, some of them driven by a digital circuit that handles coordinate programming and trigger line programming (for syncing detectors to the piezo motion), other controllers are analog and need to be driven by voltages.

2)      We would like to emulate the behavior of the digital controller using the analog HW (we have much more analog controllers than digital ones).

3)      The basic implementation is like this (see also slide one in the attached pdf file) and runs perfectly:

a.       A global pulsetrain ticks with a certain frequency

b.      At each tick a voltage is written on an AO line and this tick is also sent to an RTSI line to sync multiple detectors

4)      To fully emulate the digital controller we also need to implement 4 trigger lines that exist on the digital controller. These trigger lines allow for fully programmable pulsetrain output that is in sync with the movement of the piezo. Slide two in the attached pdf illustrates what is needed. These trigger lines allow for much more intricate syncing of our detectors (only measure during certain parts of the motion instead of all the time).

After a lot of thinking and experimenting with the existing M series boards back here I came to the conclusion that the desired behavior is not possible with an M series board since they only allow for the output of “simple” pulsetrains with a given frequency.

Looking at this webpage (https://www.ni.com/en/support/documentation/supplemental/06/timing-and-synchronization-features-of-n...) however, I think that the X series board would offer exactly what we need since it allows for buffered counter output that enables definition of very complex pulstrain “shapes”.

Looking at the schemes I provided, could someone confirm that the X-series covers our needs? If this is the case, we would be interested in purchasing these kinds of boards.

Cheers,

Kris Janssen
 

0 Kudos
Message 5 of 15
(8,409 Views)

Now in reply to the idea that my application could in theory also be run on an M series board (I have some 6602's):

 

When I set up a digital line on port 0 of my 6602 I can indeed tell it to output some pattern of 0's and 1's in relation to an external clock. However, am I wrong in assuming that I can only accomplish trigger lines (see attach of my previous post: trigger line 2 and 3 on slide 2) that are constantly high during a certain amount of ticks from my masterclock? 

 

I ask because for some measurements I would also need trigger line output in relation to my masterclock that behave like trigger line 1 and  4 in my illustration...

0 Kudos
Message 6 of 15
(8,408 Views)

Pressed that submit button to early...

 

Another problem I might forsee with this approach would be that the behavior outlined in my illustartion will repeat many times, there will be 64*64 all the way to 512*512 pixels in my image, so the pattern on the trigger lines need to be repeated many many times. Constructing an array that will hold the whole pattern at once will therefore be either tedious or not practical at all. The masterclock is just a continuous pulsetrain with a given frequency so I can also not have some retriggerable finite pattern on my digital line (unless I use even more counters probably, making things even harder to setup).

 

Would it be too much to ask for some kind of minimal example in any of the .NET languages (or if need be, in a vi, I could translate it rather easily) that does what I need on an X-series board?

 

1) One master clock that runs with for example a tick every 200 microseconds

2) One  trigger line that is low the first 100 ticks of the master clock, then continuously high for 128 ticks of mc, then low again for 150 ticks, after which this process should be able to be reproduced indefinitely (mc and triggerline should in essence be continuous pulses). Note that the low time in ticks of mc are not equal before and after high. This would be similar to line 2 and 3.

3) One trigger line that is low for 100 mc ticks, then produces 128 pulses in sync with mc, then low again for 150 ticks. This would be similar to trigger line 1 and 4. Again, this should repeat indefinitely.

 

mc, and both trigger line tasks should start at exactly the same time so I'll probaly need an additional task to serve as start trigger, but this is trivial and I can surely manage that...

 

Any help with an example like this would be greatly appreciated!

 

0 Kudos
Message 7 of 15
(8,406 Views)

Hi Kris,

 

The 6602 is not an M series board, but is actually part of our Counter/Timer family of products.  From what I can tell I still think you can do this on your 6602 (which does not have hardware-timed digital I/O, but does have 8 counters).  Let's go through all of the requirements to make sure we are all on the same page:

 

1)  Global Timebase (Counter 0):  Generate a continuous timebase signal at 200 us (5 kHz).  This would require just the single counter, configured for Continuous Pulse Generation.  There is an example that does this that ships with DAQmx.

 

Note: here is a good resource to help you find available .NET examples for DAQmx

 

 

 

2)  Counting Trigger Pulse (Counter 1):  This looks like a delayed version of the global timebase with a possibly different duty cycle (from slide 1 of your .pdf).  One of the input parameters when configuring a Continuous Pulse Generation task is "initial delay".  So, you could use a second Continuous Pulse Generation task with the same frequency as the Global Timebase but configure an Initial Delay to allow time for the movement to complete.

 

 

 

3)  Trigger Lines (Counter 4, 5, 6):  Based on the diagram in the .pdf, you should be able to do all 4 trigger lines with just the three counters:

 

KJ_Trigger Lines.PNG

 

Trigger line 2 and 3 should be easy as far as I can tell, since they look like a Continuous Pulse Generation.

 

Trigger line 1 (and 4) looks like a faster pulse generation that is gated off of Trigger line 2.  So, you could configure another Continuous Pulse Generation task, but with a Pause Trigger, so that the signal is not generated when Trigger line 2 is low.  You could get by with just one counter for this since it looks like lines 1 and 4 are identical and can simply be split from the same output of the DAQ device.

 

The key is synchronizing everything so that it starts at the same time.  If you don't have an external signal to do this, you may have to use one of the remaining counters to generate a Single Pulse to trigger all of the counters at the same time. You would generate this pulse after all of the other tasks have started.  There is actually a shipping example that shows how to use a digital start trigger with a continuous pulse train generation which should prove very useful.

 

One other caveat is the routing on the 6602.  In a sense you can think of the 6602 in two halves--Counter 0:3, and Counter 4:7.  There is a trigger bus that connects the two halves together, but you cannot route multiple signals across halves without having to make external connections. For more information, you can look at the Device Routes tab within Measurement and Automation Explorer.

 

 

Granted this might not be as straightforward as opening an example and pressing the run button, but everything should be doable on the 6602 (based on my understanding of the application).  The application would also be doable on most M series and any X series (62xx or 63xx respectively), although it would be achieved in a different manner.  If you run into any specific issues along the way please let us know.  Also please let me know if I have misunderstood any of the requirements.  I hope this was helpful.

 

 

With best regards,

 John

John Passiak
0 Kudos
Message 8 of 15
(8,383 Views)

Hi John,

 

Thanks for the feedback.

 

Most of the assumptions you make are correct but the devil is in the details 🙂

 

1) The global timebase I have Covered. It is being generated as you suggested. I am developing a universal application that can handle different kinds of HW so I am wrapping all functionality in custom classes. The one for the global pulsetrain is in "TimingClock.cs"

 

2) The measurement tasks for photon counting and the like are also handled correctly by a pair of counters ("APD.cs") 

3) Other measurements, such as photodiode readouts for recording different kinds of images are also handled, much in the same way as in the APD class ("PhotoDiode.cs").

4) The class supporting the piezo movement is handled by "PIAnalogStage.cs". The stage object holds a TimingClock member object just as the digital controller that I intend to emulate also holds its own internal hardware clock.

 

What you will see is that when I call Start() on the stage object, the TimingClock is started and it's pulses trigger the APD's (there are 2 or more, depending on the measurement) and photodiode(s). 

 

This all works as I intended and I am quite happy with what I could accomplish.

 

The problem however, lies in the fact that I use the piezo for scanning sample areas using X-Y motion. The pattern I use to cover the area can differ;

 

1) I could scan a line from left to right, move up one position and scan the next line from right to left, continually recording image data(zigzag)

2) I could also start from left to right, move back from right to left, move up one position and scan again  (I call this unidirectional scanning).

 

Method two is actually preferred due to some hysteresis effects on the piezo actuator. More complex patterns are also possible, depending on the application. My code handles all these scanning patterns in a universal manner.

 

What this means however, is that if I use scanning mode "zigzag", there is no problem with just recording data at every tick of the TimingClock. Because all positions covered are unique positions within the sample. With unidirectional there is a problem though; I need only the image data for the left to right motion and not for the returning right to left motion...

 

In the digital controller I would like to emulate all scans are defined by programming waveforms on the X and Y axes. You just define coordinates for one period of the waveform and it is repeated a user defined number of times. Additionally you are able, for each of the available 4 trigger lines, to tell the controller on which points of the waveform to be high or low and to choose if it should emit a pulse on the trigger line at each point of the waveform or to just stay at a high level for a number of points. This system is quite powerful and allows for doing some pretty cool measurements so I'd like to copy it on other setups.

 

In the example slide I gave the output is given for a hypothetical experiment where I do a unidirectional scan:

 

1) The amplitude of the X waveform is 0 for a while to allow the stage to "equilibrate". Then there is a slow rise so the stage moves in X. After that again a resting period and then a fast(er) return motion after which the whole thing starts again.

2) Trigger line 1 and 4 pulse at the same rate as the global pulsetrain because I want a reading for each individual point on the forward scanline. 1 and 4 are low however on the returning scanline because I obviously don't want that data again... I have 2 trigger lines with the same behavior here because there are two detectors (and I am too lazy to split cables). Anyway it is just an example, it could also be that these trigger lines pulse in sync with TimingClock at different moments during the X motion.

3) Trigger line  2 and 3 are level triggers and the keep a shutter in one position during the datapoint recording and in another during the return motion (hence they are level triggers and not pulsed ones)...Again, the times at which they are high/low could be at completely different moments during the X motion, they don't necessarily start at the same time and are also independent of what 1 and 4 are doing. That is also why I cannot use your suggestion to use trigger line 2 and 3 to pause the tasks for trigger line 1 and 4...

 

Maybe my example was not the best in the world but it all comes down to the fact that I need 4 trigger lines for external hardware that I need to be able to set completely independently of each other but their timebase should be the global timingsource.

 

I can see how triggerline 2 and 3 are almost trivial to do with my NI board but 1 and 4 are still giving me headaches... this is why I thought I needed X series hardware so tha I could define a sort of "pulsetrain period" that holds moments of low time, moments of high time and moments where pulses are generated and that I could then run continually. Something like that would solve my problem completely. However I have no thourough knowledge of the X series, let alone programming knowledge for this specific type of board, that is why I was wondering if there are examples that do something similar on the X series using it's buffered counter output functionality (if it is actually possible).

 

I think triggerline 1 and 4 are not doable on my current hardware, lest I add even more counters for various kinds of pause triggers... but that's just cumbersome, not to mention that I'll run out of 6602 boards real quick 🙂

Message Edited by KrisJa on 09-02-2009 12:05 PM
Download All
0 Kudos
Message 9 of 15
(8,365 Views)

Hi Kris,

 

I still think the 6602 would work since you could use the extra counters to generate pulses to gate trigger lines 1 and 4 independently of the other trigger lines.  In any regard, the programming might be a bit more intuitive on the X series so it's not a bad idea to look into these boards as well.

 

All X series boards have Hardware-timed Digital Outputs along with 4 counters.  So, you can generate an arbitrary waveform of digital data to be generated based off of your timebase.  You would build the digital waveform, call DAQmx Write to put the waveform into an output buffer, then start the task.  Each sample clock would generate the next point in your digital waveform.

 

 

As far as examples go, I would look at the ContWriteDigPort_ExtClk example which will show you how to generate digital data coming from an external clock (in your case one of the on-board counters).  The counter programming should be the same on the X series for what you want to do--like the 6602 the X series boards are programmed in DAQmx.

 

 

Best Regards,

John
John Passiak
0 Kudos
Message 10 of 15
(8,322 Views)