Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronized time loops

I have two NI PCI-6251 cards with an NI SC-2345 and NI BNC-2110.  I have the 2345 timers to create frequencies for two Time Loop structures with Ticks.

 

These two Time Loops are synchronized with the Synchronize Timed Structure Starts vi.  The 2110 is used to control a stepper motor in step/direction as well as read an angular optical encoder, with both functions having their own Time Loops (which are synchronized).

 

Here's my problem:  I have the motor loop running with a period of 50ms with each period reading a different line of an input file telling the motor what to do.  On the second time loop I have the encoder which is read once every period and writes to a file.  However, when I have a period for the encoder loop which is less than the period of the motor loop (say 25ms for encoder loop), the encoder written file has only two entries when it should have hundreds. 

 

Additionally, when I have the the encoder loop period equal to or greater than the motor loop period (say >=50ms for encoder loop), the motor loop will come to completion but the vi will continue to run, stuck indefinitely in the encoder loop (until I manually stop it).  It will have a correct output file though.  Now I know I can use the Stop Time Structure vi to make the encoder loop stop once the motor loop stops but can anybody explain this discrepancy?

 

Am I just sampling the encoder too fast under 50ms for labview to write to the file? 

 

I'm using a HEDS-5500 A06 encoder if that helps.

 

Thanks in advance for any input.

0 Kudos
Message 1 of 5
(6,713 Views)

Jihen,

 

Thank you for using the forums.  I have a couple of questions about your application to be able to answer this better.  

 

1) Are you using a Windows or Real-Time OS?

2) When you run the loops, are either of the loops finishing late?

3) Could you post your code so everyone can get a better understanding of what exactly is going on?

 

Thank you in advance for answering these questions, it will make everything a lot easier to debug.

 

Regards,

 

Brian P.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(6,707 Views)

Hi, thanks for the reply.

 

I am using windows XP.

 

Now that you mention it, the encoder loop was not finishing.  Originally I was sampling the encoder for one sample in each period of the loop and also writing that data to a .txt file in the same loop.  When I removed the writing to file vi from the encoder, the loop now finishing.  So I guess writing to the file was taking too long.

 

Attached is the vi I'm using.  I removed the write to vi in place of an Insert Into Array vi and writing the entire array to a spreadsheet afterward but I think memory might be an issue, I'm not entirely sure.  I'm anticipating the attached vi to be running for roughly 5seconds total with the encoder loop period 1-10ms.  Can you foresee anything wrong with my approach?

 

I'd appreciate any help and ideas.  Thanks.

0 Kudos
Message 3 of 5
(6,699 Views)

Jihen,

 

Thanks, for posting your code.  I am glad that you were able to get it working the way that you wanted.  As for your code, I am kind of confused as to why you are using timed loops.  If you would like to achieve synchronization, this can be done without the time loops and will probably be a lot easier.  Here is a tutorial on synchronization that can explain it a little bit more in detail.  As far as writting to a file is concerned, I would consider a producer consumer architecture, so that your acquisitiona and generation can run at one rate and then processing the data can run at a different rate.

 

Regards,

 

Brian P.

Applications Engineer
National Instruments
0 Kudos
Message 4 of 5
(6,692 Views)

Hi,

I also have similar problem. I am communicating the Host PC with cRIO based RT Target using TCP communication. In my host PC I am using my all controls , indicators, graph, file writing etc. I am sending the control value to the RT target(cRIO) using TCP/IP communication and In RT target i am reading the control and using the same control value in two independent timed loop. One timed loop I am using for timing calculation for DC motor and another timed loop using for PID control of motor.

When I run the program in RT target and operate the motor front RT target front panel itself, its work fine but when ever I communicate through Host PC and try to operate the motor , motor gets flicker and stuck in some position and after some time RT target get lost.

 

I have attached the vi and block diagram's snap shot for your reference. Please help me here find the problem.

 

 

Thanks

Srikant

0 Kudos
Message 5 of 5
(6,529 Views)