NI Home > Community > NI Discussion Forums

Signal Generators

Showing results for 
Search instead for 
Do you mean 
Reply
Member
ashwintrr
Posts: 13
0 Kudos

Re: Custom analog signal Generation

@ Daniel

I incorporated your suggestions and it worked exactly I want it to. However I have one small problem on which I need your suggestion.

 

I am trying to run this "user defined custom Analog Signal" for some definite number of cycles as per user requirement. I mean, - if the user wants to export the entire Analog voltage signal 10 times, then I want my VI to run 10 times and stop.

 

I have a for loop in place for the whole cycle with "no. of cycles" being the control variable (Please find attached VI). However inspite of having a "for loop" the program run indefinitely as if it were running in a while loop with a stop condition as the end statement.

 

I am not able to figure out where I am going wrong!. Any pointers?

 

Thanks

Ashwin

Member
ashwintrr
Posts: 13
0 Kudos

Re: Custom analog signal Generation

[ Edited ]

Oops..I forgot the attachment in my earlier post

Member
Daniel_H1
Posts: 82
0 Kudos

Re: Custom analog signal Generation

Hi Ashwin,

 

This is because your analog output task is configured for continuous samples, so the task is never "done." The VI is getting stuck in your while loop.

 

You'll need to have the DAQmx Timing Configured for "Finite" samples, with the samples per channel set to however many samples you will want in each iteration of your output. Then in your while loop, have the output of Is Task Done? wired to the stop terminal.  This will stop the while loop once all the samples have been written, and it will start over again. 

 

One more thing: you should have the for loop around just the data acquisition part. This way, it won't have to go through and generate your array again, it can just use the one it already generated. So it will generate the array once, then do the analog output section N times.


Regards,

Daniel H. 

Customer Education Product Support Engineer
National Instruments
Certified LabVIEW Developer
Member
ashwintrr
Posts: 13
0 Kudos

Re: Custom analog signal Generation

Daniel,

 

I was to able to fix the Analog Output (AO) issues to run my power supply. It works fine. I want to attach one last feature to this.

 

I am trying to collect data from a load cell as an analog input (AI) channel. I want to collect analog data continuously as long as the for loop for the AO section is active (Here for loop count "N" is no of cycles in my code).

 

I want to collect "x" samples (0<x<200) from the AI for every for loop iteration of the analog output and save it continuously as a ".lvm file". The AI data collection must stop as soon as the last loop iteration for the AO is reached!.

 

I am using NI myDAQ for both AI & AO channels.

 

My present code runs coorectly for a max of 5 cycles and then shows either of these errors (highlighted in blue).

 

Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.
Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem.

Property: RelativeTo
Corresponding Value: Current Read Position
Property: Offset
Corresponding Value: 0
Task Name: _unnamedTask<72>


Both the AI & AO codes run without errors when executed separately. I am having issues when they are combined as I am trying in this code. Can  you please have a look when you find time

 

Thanks

Ashwin


Member
Daniel_H1
Posts: 82
0 Kudos

Re: Custom analog signal Generation

Hi Ashiwn,

 

Your analog input is not reading samples out of the buffer fast enough, so it is overwriting your data. What you need to do is have DAQmx Read read the correct number of samples. In your VI it looks like you have the wrong wire connected to the "number of samples per channel" input of DAQmx Read (also, don't divide it by two). You should make sure that the "samples per channel" input of DAQmx Timing and "number of samples per channel" input of DAQmx Read are the same value. That way, the entirety of the buffer established by DAQmx Timing will be read by DAQmx Read each time.

 

Regards,

Daniel H.  

Customer Education Product Support Engineer
National Instruments
Certified LabVIEW Developer
Member
ashwintrr
Posts: 13
0 Kudos

Re: Custom analog signal Generation

Daniel,

 

I have made changes according to your suggestion. The "array length" is connected to "samples per channel" input of DAQmx Timing and "number of samples per channel" input of DAQmx Read thus ensuring the same value for both of them. I have also modified it from a "CASE structure" to a simpler while loop. Find VI attached 

 

I typically use the value for sample rate in the range 20 to 40 Hz's for my application. My array length varies between 800 to 2000 (Depending on the analog Ouput signal defination)  which would be samples per channel input value also.

 

I am also using a Measurement Computing USB 2416. The entire code here is the same except for the DAQ mx is replaced with corresponding ULx of Measurement computing. I have attached the "for loop part" of the code for this as an image. I tried running the same there too.

I get the same error (in blue belowafter each for loop iterationI guess I am going wrong somewhere with the Analog Input read part of it.

 

Measurements: The generation has stopped to prevent the regeneration of old samples. Your application was unable to write samples to the background buffer fast enough to prevent old samples from being regenerated.

To avoid this error, you can do any of the following:
1. Increase the number of samples you write each time you invoke a write operation.
2. Write samples more often.
3. Reduce the sample rate.
4. Reduce the number of applications your computer is executing concurrently.
Ashwin
Member
Wee-Bey
Posts: 173
0 Kudos

Re: Custom analog signal Generation

Hi there Ashwin,

 

So it looks like with your read, you are creating and closing the task each time in the while loop. First off, I would recommend taking the Create, Sample Clock, and Start VIs otuside the while loop to the left, and the Clear Task outside the while loop to the right, so you're not closing and opening these every time.

 

To address the actual error, it seems you're basically trying to read too many pieces of data that aren't sitting in the buffer ready to be acquired. Notice the input into your Read entitled "Number of Samples per Channel." If the number of samples waiting in the buffer is less than what's in this parameter, the program will basically throw an error because there isn't enough data to grab. If you don't care exactly how many samples you get, I'd leave this unconnected or set to -1 (the default), which basically grabs as many pieces of data as are in the buffer. If not, I'd check your loop rate to see if you're sampling too fast for how much data the system is generating. You might have to try putting a longer wait in your while loop. What are the typical values that would come in for the sampling rate?

Ravi A.
National Instruments | Applications Engineer
Member
ashwintrr
Posts: 13
0 Kudos

Re: Custom analog signal Generation

Hi Ravi,

 

I had tried your suggestion earlier (i.e moving the create, Sample clock , start and clear VI's) outside the while loop. However it was still showing the same error. I have attached the updated VI's

 

As per your suggestion, I have unconnected any wires to "Sample per channel" for the "read VI". I also tried increasing the wait time. For all the options it is showing the same error.

I also reduced my sample rate. I was earlier multiply the "input sample rate" (The same sample rate used for analog ouput signal generation) by a factor of ten. I have now reduced the multiplying factor to 2. 

 

Typically the input sample rate from the user is in the range of 20 to 40 Hz's for the Analog Output signal generation. This thus becomes 40 to 80 Hz's for the Analog Input signal.

 

For any changes made it shows the same error after executing "ONE" for loop iteration. 

I dont know if its my VI or my DAQ system (USB 2416 from Measurement Computing) that is causing the problem

 

Thanks

Ashwin


Member
Daniel_H1
Posts: 82
0 Kudos

Re: Custom analog signal Generation

Hi Ashwin,

 

Just to clarify, does your code work with DAQmx after you made the changes I suggested? Are you only getting these errors now with the Measurement Computing device? 

 

If you are only getting the error with the Measurement Computing device, then you might want to contact Measurement Computing's technical support. However, I have taken a look at the help documents for some of the ULx functions you are using, and the only thing that jumps out at me is that for the ULx Timing VI, you will need to set the "clock source" input to "OnboardClock." I can't be sure, but if unwired it may default to "NoClock," which could then cause some strange issues because it will ignore other parameters you set.

 

Regards,


Daniel H.

Customer Education Product Support Engineer
National Instruments
Certified LabVIEW Developer
Member
ashwintrr
Posts: 13
0 Kudos

Re: Custom analog signal Generation

Hi Daniel,

 

I have had a chance to test the updated VI with only the measurement computing device. My NI device is not available now for me to check if the VI works with DAQ mx.

 

I have tried setting the "onboard Clock"  earlier in my code (as per a ULx example), however it still gives the same error. It excecutes one for loop cycles and throws up the error. So I presume the problem is definately with the AI VI using UlX.

I will check once with a NI device and let you know.

I might have to contact the Measurement Computing guys to sort out this.

 

Thanks

Ashwin