Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronizing two counters output with a USB-6212

Dear all,

 

I'm new with DAQmx and I have troubles with counters. I've seen a lot of messages in forums about synchronization, but none of them really helps with my particular application and hardware.

So here is what I'd like to do:

1. Generate a clock of period T

2. Generate a pulse of duration T/2 every 100 period of the clock

3. Read an analog input synchronously with the clock

 

For points 1 and 2, I tried to use counters (on the same USB-6212). I can generate the two signals, but there are not synchronized with each other. In my last attempt, I tried this: signal 1 uses a "Start Trigger (none)" and signal 2 a "Start Trigger (Digital Edge)" using the output of signal 1 (PFI12). Is it possible with 6212 to generate signals 1 and 2 ?

 

For point 3, I wanted to use the same device. Is it possible to read one analog sample synchronously with a clock generated with a counter ?

 

Thanks a lot for your help!

 

 

____________________
JB
0 Kudos
Message 1 of 26
(7,783 Views)

Hi tycho,

 

Yes, all of this should be possible.

 

Synchronizing 1 and 2 should be achievable with the trigger method you proposed.  You would want to start task 2 before task 1 in software so that it is armed and ready by the time the first pulse is generated from task 1.  Other than that it should just be a matter of making sure the high times and low times are correct for each of the tasks so that they line up appropriately. Since both counters use the same timebase there will be no drift in the tasks over time.

 

You can certainly use the counter output for the AI Sample Clock:

 

22717iE4B688B06A814A08

 

To have Ctr0InternalOutput show up in the drop-down list of terminals, you need to right-click on the constant/control and select I/O Name Filtering, then choose to Include Advanced Terminals.

 

 

If you're still having any problems, feel free to post your code and we can take a look.

 

 


Best Regards,

John Passiak
0 Kudos
Message 2 of 26
(7,780 Views)

Hi John and thanks for your answer.

 

I put in attachment my vi, where only points 1 and 2 are developped.

Could you please have a look and tell me if there is a better/smarter way to achieve the same result ?

Also is there any difference between /Dev1/Ctr0InternalOutput and /Dev1/PFI12 ?

When I try to use something else than "Implicit" for the timing, I get an error.

 

Thanks again !

 

____________________
JB
0 Kudos
Message 3 of 26
(7,778 Views)

Your VI is close, but it's important to start the slave task before the master task.  This way it is ready for the trigger by the time the first pulse is generated:

 

22731i1B4DD903008BD23B

 

I think it's a little more straightforward if you think of both CO tasks in terms of Time. There's not a practical difference beteen using the Internal Output or referencing the PFI line, but using the Internal Output would let you use PFI12 for another purpose if you desired.

 

 

You should set the counters to Implicit Timing.  This means that the timebase of the counter is what regulates how quickly the pulses are updated and no external clock is necessary.  The Sample Clock Timing I was referring to in my previous post is meant for the AI Task.

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 26
(7,775 Views)

Hi John,

 

When I try this solution, I still see with a scope that my two signals are not synchronized.

I don't know what can happen...

 

Best regards,

Julien

____________________
JB
0 Kudos
Message 5 of 26
(7,762 Views)

Are the signals drifting over time?  Perhaps the high and low times aren't even multiples of the counter timebase period (default of 12.5 ns) and the values are being coerced.  To be safe, you might want to convert the output to ticks rather than seconds so you can tell exactly what is going on.

 


Best Regards,

John Passiak
0 Kudos
Message 6 of 26
(7,750 Views)

 

When I synchronize the scope on the first output, the second is drifting over time.

I tried to use the ticks (see attachment) but it gives the exact same thing.

 

Cheers,

Julien

____________________
JB
0 Kudos
Message 7 of 26
(7,746 Views)

 

Could the problem come from the configuration of the 6212 ?

I left the default configuration everywhere, but maybe this kind of application requires a different setting ?

____________________
JB
0 Kudos
Message 8 of 26
(7,720 Views)

In that example (Essai_Sync_5.vi) the two counters should not be drifting over time if the task is run continuously.  However, the initial phase of the counters will be inconsistent from run to run since there is no start trigger for the slave task (the non-determinism of your OS will cause the relative phase of the two counter starts to be randomized).

 

Running the program on my end gives two outputs that do not drift over time (but the initial phase is not consistent).  I'd like to know more about how you're measuring the phase drift.

 

 

Best Regards,

John Passiak
0 Kudos
Message 9 of 26
(7,718 Views)

 

Well, I see the drift on the scope, I don't really measure it.

For example, I put the clock on channel 1 and I set the scope trigger on channel 1. Then I see the channel 2 drifting.

When I set the trigger of the scope on channel 2, I don't see the drift... But in my opinion, if the 2 signals are really synchronized, they should be stable for both trigger settings, shouldn't they ?

I also tried with different scopes to be sure...

 

I tried to add a start trigger on the slave task as the delay between the two signals should be always the same for my application, but it didn't work either...

 

Cheers,

Julien

____________________
JB
0 Kudos
Message 10 of 26
(7,716 Views)