Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing Duty Cycle from a PID controller output

Solved!
Go to solution

Hello everyone,

 

My goal is to be able to change the duty cycle of a PWM signal using the output from a PID controller.

 

I am working with this example provided by NI:

Change Duty Cycle on a Continuous Pulse Train of NI-DAQmx Task 

questiond.png

 

This example works as was intended, I am able to change the duty cycle from the front panel. The problems begin when I substitute the Duty Cycle Control for the output of the PID controller. 

 

How can I adapt this code so that the Duty Cycle is changed according to the PID output instead of the Duty Cycle Control as it is now? My guess is that the problem lies with the Event Cases. I have tried changing the Duty Cycle Control to an indicator and wiring it to the PID output and then that to the input at Create Channel vi but no success.

 

Thanks,

Junekers

0 Kudos
Message 1 of 5
(4,220 Views)

You probably want to attach the actual VI, because it is very difficult to debug a picture. (e.g. what's in the timeout case? Are there other events?)

 

(Events are primarily for user interactions.)

0 Kudos
Message 2 of 5
(4,205 Views)

Thanks for your response. I have attached the VI to the original post. 

0 Kudos
Message 3 of 5
(4,190 Views)
Solution
Accepted by topic author junekers

Sticking with a single loop for now to illustrate most simply, you'd need to change to a polling structure instead of being event-based.

 

Here's a bare outline.  Your real PID function will need inputs (of course).  You'll most likely want to set a different loop rate via the Wait timer.  But the main idea is to update the task's duty cycle if and only if the desired duty cycle coming from the PID calculation changes.

 

 

-Kevin P

 

Change_Duty_Cycle_Property_Node_polling.png

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
Message 4 of 5
(4,127 Views)
Thank you very much Kevin_Price. This works wonderfully with a small caveat. The initial value coming out of the PID controller needs to match the initial value for Duty Cycle. I will try to post a follow up solution for posterity. 
0 Kudos
Message 5 of 5
(4,101 Views)