Discussion:
close loop control using usb 6259bnc in dc motor and sensor
(too old to reply)
Diora
2008-08-12 21:40:24 UTC
Permalink
I have a usb 6259bnc DAQ and want to create close loop control for a dc motor and feedback will be provided by analog sensor. Attached is the main vi of the controller. There are 3 subvi inside the loop:&nbsp;p controller, sensor and pwm. Every time I run the main vi, the while loop will not start next iteration until each subvi finished. I'm using this pwm vi as subvi in the main vi: <a href="http://zone.ni.com/devzone/cda/epd/p/id/5043" target="_blank">http://zone.ni.com/devzone/cda/epd/p/id/5043</a>. Every time I push the stop button in this pwm vi, error pop up. I think 6259 belongs to m series and it should work fine. Is there something I need to do to use this pwm vi? As I mention before, the loop in main vi will not continue unless the sub vi is finished, but in that pwm vi I could not stop it except push the stop button, and once I push the stop button error pop up. Even I could stop the pwm subvi normally, the speed to run the main vi will very slow and not continue because the pwm generation will be stop while other parts are running. So, any good suggestion to build up a close loop control with labview and usb 6259bnc?
&nbsp;
Thanks in advance!


Presentation11.gif:
Loading Image...
Paul C.
2008-08-13 15:40:11 UTC
Permalink
Hi Diora,&nbsp;You're correct that all subvi's must finish for your main loop to iterate.&nbsp; Is this not what your intending on doing?&nbsp; In regards to the error in the subvi, can you please post the error number?&nbsp; Are you able to run that example seperately without any errors?&nbsp; Make sure that you have all valid inputs to the subvi.&nbsp; It requires an input for Digital lines, Counter line, counter internal output, duty cycle, stop, and frequency.&nbsp; If you are missing these inputs that could be the reason you're getting errors.&nbsp; From the picture, it shows you only have one input to the subvi.&nbsp; Please add wire inputs for all of the inputs (most importantly the stop button). &nbsp;The program flow you have presented in the picture will&nbsp;generate PWM signal, control signal, and read from sensor each iteration.&nbsp; It is important to note that when you make the PWM example into a subvi it will create and destroy the task each iteration of your main vi.&nbsp; This might be somewhat slow for a faster operation, but as long as your ok with slower speeds of your main loop, this should work fine. I'd fix up the inputs to the subvi and see if this vi meets your needs without errors occuring.&nbsp; If it doesn't work, please include some more details on the behavior you need between the dc motor and sensor.&nbsp; From the picture, I don't see how the sensor provides any feedback to the DC motor at this point. &nbsp;I hope this helps,Paul C.&nbsp;
Diora
2008-08-13 23:40:22 UTC
Permalink
Hi Paul,Thanks for your reply! I didn't descript my problem clearly. I run the pwm seperately and when I push the stop button, error pop up: Warning 200015 occurred at DAQmx Write (Digital 1D U32 1Chan NSamp).vi:3. &nbsp;The&nbsp;pwm settings are:1. digital lines:Dev2/port0/line0:7
2. counter: Dev2/ctr0
3. counter Internal Output: Dev2/Ctr0InternalOutput4. duty cycle: 50%5. frequency: 500HzHere Dev2 is the DAQ6259bnc.The one input to pwm vi is duty cycle. The frequency is set to 500 defautly. Others are defautly set into the setting above (I think).&nbsp;&nbsp;Now, the&nbsp; first problem is seperatly run pwm, push stop, and have error 200015. The second problem is, in main vi, I don't want the pwm stop running while reading from the sensor and doing other calculation. I need the pwm&nbsp;keep running&nbsp;in the duty cycle&nbsp;generated in&nbsp;the x iterate when x+1 iterate is running the sensor reading and p controller, then when send the x+1 signal to change the pwm, it will keep this signal running while doing x+2 iterate. Is that possible? Because I'm using h bridge to control the dc motor, when pwm stop running, the signal will just stay in 1 or 0. This lead to the motor run in full speed in one direction when the sensor is reading and doing othre calculation. To sum up, I'm designing a servo system using a dc motor and analog sensor. The output to the dc motor should be pwm using DIO. Is there a good example?Thanks,Diora
Paul C.
2008-08-14 16:10:10 UTC
Permalink
Hi Diora,&nbsp;I believe what you need to do is place the sensor code inside the PWM application as shown in the below picture.&nbsp; This will keep the PWM task running while you change the duty cycle each iteration of the loop.&nbsp; In regards to the error, it is actually just a warning and will not stop the execution.&nbsp; It will just show up after you stop the application.&nbsp; This warning occurs because your sampling rate is too high for the buffer size you have defined.&nbsp; When you first start a digital output task, the DAQmx driver uses the initial waveform size to determine buffer size unless you use the DAQmx configure output buffer to specify a larger size.&nbsp; I would recommend wiring in a DAQmx output buffer vi to specify a larger buffer size.&nbsp; The example by default uses 1000 as the buffer size.&nbsp; I would recommend trying 10000 and that should make the warning show up less frequently.&nbsp;
<img src="Loading Image..." border="0">
Regards,Paul C. Message Edited by Paul C. on 08-14-2008 10:46 AM


PWM.JPG:
http://forums.ni.com/ni/attachments/ni/250/42339/1/PWM.JPG
Diora
2008-08-15 00:10:29 UTC
Permalink
Hi Paul,I try to put sensor code inside the loop, it works. Thanks! To avoid the warning pop up, I try to add the output buffer vi to the original pwm vi (as shown in the picture I attached), set the buffer size as 10000, and error pop up (code 200016) when I run it. Am I doing this wrong? Please have a look.&nbsp;I have another question. If I'm going to control more than10 motors parallelly with the similar control system (pwmvi based with sensor and p controller added in the while loop), how could I do it with fixed frequecy and different duty cycle in different DIO channels?&nbsp;Thanks a lot!&nbsp;Diora&nbsp;&nbsp;


buffer_error.jpg:
Loading Image...
Paul C.
2008-08-15 19:40:21 UTC
Permalink
Hi Diora,&nbsp;I've actually just verified that the warning will show up regardless of whether you increase the buffer size.&nbsp; The error is just a warning and increasing the buffer size will help avoid the glitching from actually happening but you will still receive the warning.&nbsp; One way to remove the warning is to clear that error message and just ignore it.&nbsp; Another option would be to turn off regeneration.&nbsp; Regeneration is used to regenerate previous samples if newer samples have not been written to the buffer fast enough.&nbsp; If the loop where you call the DAQmx write is iterating fast enough (this avoids the buffer underrun error -200016), you can turn off regeneration and the program will behave the exact same way without the warning.&nbsp; This is all done through a DAQmx property node wired in very similiarly to the DAQmx Configure Output Buffer vi I previously suggested.&nbsp; The property node you're looking for is the DAQmx write property node.&nbsp; The property is called regeneration mode.&nbsp; All you need to wire is the &quot;Do Not Allow Regeneration&quot; enum to the property prior to starting the task. &nbsp; In regards to the error code -200016.&nbsp; This is typically due to not calling the DAQmx write fast enough with regeneration turned off. &nbsp; What frequency are you using?&nbsp; I haven't seen this error running the PWM example code here.&nbsp; Have you made any other modifications to the code?&nbsp;In regards to the second question, only port 0 of the digital lines can be used to output hardware-timed signals.&nbsp; This means that you will only be able to control 8 motors in this fashion.&nbsp; The way this can be done is by slightly modifying the PWM example.&nbsp; Below is the way the old data was generated.&nbsp;<img src="Loading Image..." border="0">&nbsp; &nbsp;This needs to be modified to with the below changes.&nbsp;&nbsp;<img src="Loading Image..." border="0">&nbsp; &nbsp;Basically, instead of writing the same duty cycle data to all 8 channel, this breaks it down and writes different data to each line.&nbsp; This is simply done by writing your high cycles to the proper bit location.&nbsp; For example, to write a 1 to line 0 you need to write the 8 bits 0000001.&nbsp; To write to the second line high you need to write 00000010.&nbsp; All I've done is multiply the 1's to make the 2nd line's duty cycle by 10 to place him in the correct row.&nbsp; Please let me know if this needs more clarification. &nbsp;Regards,Paul C.Message Edited by Paul C. on 08-15-2008 02:25 PM


old.JPG:
http://forums.ni.com/ni/attachments/ni/250/42390/1/old.JPG


new.JPG:
http://forums.ni.com/ni/attachments/ni/250/42390/2/new.JPG

Diora
2008-08-14 22:40:20 UTC
Permalink
Thank you, Paul. I will try to put sensor code inside the loop. I'm using DAQ Assistant to obtain reading from the sensor, so I don't know if it will work in that loop. And I'm pretty new in learning Labview, could you please tell me where to put daqmx output buffer in the pwm vi? Thanks a lot!Diora
Loading...