10-09-2012 06:00 PM
I am a relative LabVIEW novice and I'm not sure if what I'm trying to do should be simple, or is actually quite difficult. I'm much more used to Matlab and thus am relatively inexperienced with how LabVIEW handles arrays and doing things sequentially.
What I'd like to do is record some analog data using a MyDAQ and the DAQ Assistant block and then play this data back to control a motor (the type of sensor is irrelevant for this post, it just goes into the analog ins in the MyDAQ). This was easy enough if I just wanted to record and play back the same series of analog voltages to control the speed of a DC motor (after a little troubleshooting, in one of my other posts).
Now what I'd like to do is convert that recorded signal to a PWM signal to control the position of a servo motor instead. I'm able to do this easily enough real-time just using a slider control and the "Basic Function Generator" block - the slider controls the "square wave duty cycle" input to the block (see attached). Where I get confused is figuring out how to do this with my recorded data. It doesn't seem like the Basic Function Generator will accept an array as an input to the "square wave duty cycle", so I tried putting it inside a for loop and feeding the indexed array into it (doing some simple map to convert the value of the analog voltage into a duty cycle %). However, this ran incredibly slow. I'm not sure if using the Function Generator inside a for loop while sending an analog out through the DAQ Assistant is just a terrible idea and I should pre-calculate the PWM signal as an array, THEN send it to the DAQ, or do something else entirely (including making my own PWM signal brute-force instead of using the built-in Function Generator block, if that won't be happy about receiving a changing duty cycle input).
Any pointers much appreciated.
10-10-2012 02:48 PM
Checking your code, it runs too slow but the problem is not the use of the indexed array, actually I think this a good way to use your recorded data. I recommend you to look for this link: http://www.ni.com/white-paper/2991/en
There you can see some examples of Pulse Width Modulation Using DAQmx and LabVIEW. So you can use those examples, and for use the recorded data, you can use a “for loop” to create an array reading data before configure the DAQmx task, and then you can use index the array to read each value to set the duty cycle.
You can put attention to your code and check the use of an express VI inside a loop because it is not a good idea if you want your VI to run faster.