Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate a Continuous Digital Pulse Train With a Variable Frequency Governed by PID

Hello,

 

As the title suggests I need to produce a continuous digital pulse train with a dynamic frequency similar to the example here:

 

https://decibel.ni.com/content/docs/DOC-8382

 

However, the main difference is that the frequency is governed in real-time by a PID system.  The .vi has 5 DAQmx tasks in total (all running concurrently); 2 A/I (one of which is the input for the PID system), 2 D/O plus the digital pulse train.

 

The problem that I am experiencing is that all the digital pulse train examples I have found are inside loops.  This means that the other DAQmx tasks cannot perform as required.  I can break out of the loop perform the other tasks and jump back in but then the pulse train is interrupted.  If other tasks are included in the pulse train loop the frequency in affected by the processing time.

 

I am looking to perform the tasks in timed loops using multiple processors.  Am I on the right track?

 

Thanks,

Charlie

0 Kudos
Message 1 of 8
(3,971 Views)

Hi Charlie,

 

What hardware are you using to to generate this output?

What kind of frequencies do you require?

 

Depending on exact program requirements and speed dependencies you have we have a few options


In terms of updating the pulse train this can be done a few different ways

 

Timed loops is one way to implement this.  If you need things to happen at different speeds of some tasks not to be interrupted then multiple loops is the way to go.

 

If you need further questions answered then please feel free to post back.

Matt Surridge

National Instruments
0 Kudos
Message 2 of 8
(3,941 Views)

Please also see this KB that I think is applicable.

 

Best Regards

Matt Surridge

National Instruments
Message 3 of 8
(3,935 Views)

Hi Matt,

 

This is really useful stuff.  Thank you. 

The frequency I need to produce will range from 0-5kHz.  The hardware is a DAQPad6015.

I will try to work with the information you have provided and get back to you if I require any further assistance.

 

Thanks again,

Charlie

0 Kudos
Message 4 of 8
(3,916 Views)

Hi,

 

Ive looked into the suggestion...

 

I need to parrallel loops as I see it:  One to write the continuous pulse train and the second to collect A/I data, record, write other D/O and most importantly for this problem - calculate the frequency of the pulse train in the first of the two parallel loops.

 

If I understood correctly I have used the method Matt suggested (thank you Matt)...

 

If the event change occurs inside the first of the parallel loops the frequency of the pulse train updates (please see MotorControlRealTimeVariable.vi).

 

However, if the change occurs in the second loop then the change is not detected in the first and the frequency is not updated (please see MotorControlRealTimeVariableNotWork.vi).  Why is this and can I work around this?

 

Obviously the attached .vi's do not include everything that I have discussed, just the parts that are nessesary for this discussion.

 

Thanks,

Charlie


 

0 Kudos
Message 5 of 8
(3,908 Views)

Hi Charlie,

 

I have had a look at your vi's and I think that your DAQmx programming needs to be changed as the task should be configured outside of then started.  If you have a look in the example finder this can be found on the getting started screen on the right hand side.  

 

Under Hardware Input and Output > DAQmx > Generating Pulses you will find some useful examples.

 

 In terms of programming architecture I would suggest looking at the producer/consumer architecture.  A Template of this can be found by selecting File > New... in LabVIEW this will open the New window.  From here expand VI > From Template > Frameworks > Design Patten's > Producer consumer (Data).

 

This architecture has the producer loop that will acquire your data then this data is passed to the consumer loop where the processing can happen.  The Queue ensures no data is lost,  the consumer loop will only run when it has data being passed to it.  

 

This link will also be worth a read and give some great information on producer/consumer.

 

I hope this helps with your application development

Matt Surridge

National Instruments
0 Kudos
Message 7 of 8
(3,902 Views)

Hi Matt,

 

I took your advice and I have moved this on further (please see attached).  I have a program that is now working although it is flaky and produces error -200301 'The pulse generation with previous property settings must complete a full cycle before the property can be updated'.  I have read on this error and as I understand - a fix for this is to include a wait in the loop longer than the maximum counter period time.  However, this is not possible in this case as the minimum frequency is 0.6Hz.  This would be too long to wait for more dynamic situations.  The other problem is that when the .vi enters the sequence sometimes (apparently randomly) the output frequency through the DAQmx does not match the specified frequency.  I suspect this is realated to error -200301.

 

I you could have a quick I would be very grateful.  And if you have any suggestions for how to rectify these issues I would be even more grateful.

 

Regards,

Charlie

0 Kudos
Message 8 of 8
(3,830 Views)