Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

PID controller for the duty cycle of Counters

I work on a closed loop PID controller problem (lab experiment) and I have some questions for anyone who can help me about any of them. Firstly I have to announce that I work on Labview 8.5. Please from control.llb open the main.vi.

Now, my Closed Loop algorithm is composed of 2 AI channels (2 accelerometers), 1 AO channel (excitation channel-shaker), and 2 CO (for pulse creation-PWM controllers). The idea is very simple. When the AI value (from AI channel 1) surpass or underpass a predetermined threshold value, then the appropriate CO should be activated in order to apply the necessary control pulses. Simultaneously all the data values of both AI channels are copied in binary style files (for CPU velocity reasons)! BUT, with the PID controller I want to optimize the Duty Cycle value of the pulses in Counter Outputs. That’s it!

Looking the Block Diagram of the main.vi, there are some numbered places from 1 to 11.

1: For the DAQmx Timing of the AI Channels I have chosen the Sample Mode to be Hardware Timed Single Point as I want to control every single point (pt by pt) with time step 10ms (Wait until next ms multiple), of the acquired values from the accelerometers in order to check if any of them is over or under the predetermined threshold values in order to activate the controller or not. Is it ok?

2: For the DAQmx Timing of the AO Channel I have chosen the Sample Mode to be Finite Samples as I want to run my experiment for 30 sec. I have put 3000 samples with a sampling rate 100 samples/sec. That’s it.

3: I have used the Get Terminal Name with Device Prefix.vi in order to timely synchronize the AI with the Counter Outputs. Is that ok?

4: For the DAQmx Timing of the CO I have chosen the same one as in the AI Channels for the same reasons as in 1. I have experimented a lot using Implicit with Continuous Samples rather than Sample Clock with Hardware Timed Single Point with no progress! Maybe the fault is in another place of the vi! Any idea about that?

5: I have chosen DAQmx Writing as Analog Wfm 1Chan NSamp as I want the experiment excitation be a smooth waveform from 1 AO Channel with 3000samples total and sampling rate 100samples/sec. I think it’s ok here.

6: I have used the Flat Sequence Structure in order to put the necessary DAQmx Start Tasks with that order for time priority reasons! Is that structure necessary? Is it ok?

7: In DAQmx Read I have chosen the Analog 1D Wfm NChan 1Samp, because as I said in 1 I want point by point check form my AI values. Is that ok or I have to use the Analog 1D DBL NChan 1Samp or something else?

8: After splitting the Channel values I filter both of them. Any comment here with Get Waveform Components and afterwards Building Waveform? I do this because I have to transform the Volts into acceleration values (g) with the appropriate transforming factor.

9: Here I think is the most crucial point of my algorithm. My acceleration values acquired, some of them are positive and the other negative. So, according to the polarity of each value I want to drive them to the appropriate PID controller through the Case Structure and simultaneously to drive all the values to the binary file! Are all of them ok? The case structure?

10: To be clearer, here is the area of the PID controller for the negative values! It has different setpoint, output range and PID gains from the other PID controller (for positive acceleration values). That's why I have used two PID controllers and not one! Is it correct?

11: And finally, the PID output values are compared in the ‘equal within tolerance.vi’ and if it is in a predetermined tolerance compared with the previous value (that’s why the shift registers) then the Duty Cycle value of the counter remains the same with the previous loop, if not then in the new loop the Duty Cycle value is equal to the new PID output value trying in that way to reach the acceleration values the setpoint ones and so on! I have to mention that in the bottom case structure I have put the absolute value transformer because in that PID controller there are the negative values but the duty cycle values as we know are only positive ones!

 

I know that after solving these problems I have to face the PID tuning which is the most important task…

I know that I wrote too much but I have tried a lot for this algorithm construction and I hope to work it fine! Any suggestion / notification is welcome and valuable!!!

 

Best regards to everyone!

 

Grigoris

0 Kudos
Message 1 of 5
(7,126 Views)

Hi Grigoris,

 

Is determinism important in your application, or do you need your loop to iterate fast? In order to use the Hardware Time Single Point affectively you should couple that with a “Daqmx wait for next sample clock.VI” as is demonstrated in the example: “PID Control-Single Channel.VI” or in “PID Control-Single Channel-Alternate.VI”. You are also starting your AI task first when it’s clear you intend it to be the master. Alternatively you can remove the time from your tasks and have and AI read happen whenever called in software and make PID decisions based on this data. You mentioned in you post some faults you were experiencing. Are you getting errors when you run your code? If so what?

Matt
Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(7,095 Views)

Hello Matt!

 

 First of all I have to thank you for your kind interest about my problem.

 Yes, determinism is important into my problem as I want, first take the acceleration value (from AI), then check if it is inside or outside the predetermined thresholds and if it is outside then the PID controller take action in order to apply the necessary control action through CO (PWM). The basic problem up to now is that as I want to write and read 3000samples with rate 100samples/sec, when the run is finished in my binary file there are less points (about half of them) and if I try to activate the controller by putting some values in Kp or TI or Td  then I have much less points! I now that I have to work in point by point mode and I would like to check one point value per about 10-25msec of the acceleration time history! Do I have to have 2 PID controllers for my application? In point 9  of my questions I think there is one of the main problems. Is it?

 With that sentence ''Alternatively you can remove the time from your tasks and have and AI read happen whenever called in software and make PID decisions based on this data.'' what do you mean. Please make it more clear!

 

With best regards!

 

 Grigoris

0 Kudos
Message 3 of 5
(7,088 Views)

Hi Matt for one more time!

 

I send you the most recent trial results and notificatations in order to help you for your answer.

I also used the Real-Time Property node to set the Report Missed Samples attribute. This property, signals the analog input task to return an error if new samples are available before the read operation finishes converting samples from the previous iteration. After applying that the vi gives me the error:

 

''Error -209802 occured at DAQmx Wait for Next Sample Clock

 

Possible reasons:

 

Measurements: DAQmx Wait for Next Sample clock detected here were missed sample clocks since the last call to Wait for Next Sample Clock which indicates that your program is not keeping up with the sample clock. To remove this error slow down the Sample Clock or else change your application so that it can keep up with the sample clock. Alternatively, consider setting the convert errors to warnings property to true and then handling the working case appropriately.''

 

I have also tried the DAQmx Wait For Next Sample Clock (in the AI branch inside the While Loop and after the DAQmx Read) and its ‘is Late?’ light indicator lights on! But I think that 1 point per 25msec which I want to be checked, is not an extreme condition for my PCI (PCI 6289 – M series).

I have also tried the ‘On Demand’ timing to AO and CO with no progress! Any suggestion for timing generally into my application? I just want pt by pt check into my AI values and afterwards the control application through CO and simultaneously the AO applies the excitation of my structure!

 

One more thing is if all this algorithm is not being capable for working because I have never seen in any example code application with simultaneous AI, AO and CO! What do you think? Please, if you have any vi with these three different tasks working together, would you like to send it to me?

 

With best regards!

 

Grigoris

0 Kudos
Message 4 of 5
(7,082 Views)

Hi Greg,

 

The examples provide framework, a basic architecture for you to model you code on. The error you received is explained quite well by the error message; basically your code is too computationally intensive to allow your main while loop to iterate in the allotted time, ie: between sample clock edges. If determinism is indeed as important as you mention then knowing your computer is not keeping up is important feedback. To fix this you can alter your code so that there is less computationally involved ( you have a 2 software filters and 2 writes to disk in addition to your PID computation and calls to the DAQmx driver in order to update your PWM signal). These tasks will take time and it looks like it may be taking more than the 10 ms period dictated by the 100 Hz sample rate you have configured for the AI task.

 

The other suggestion I mentioned was to have software timed, one sample on demand, AI reads. Each loop iteration, you would read one sample from the AI channels, configure your PID accordingly and then modify the CO task if needed. Is that more clear? Only you as the system designer can determine if that would give you an acceptable loop speed to control your system.

 

The basic concept of PID control can be applied to AO and CO output; it’s not limited by type. I don’t have an example that demonstrates use of all three, but I seems like your code has had some success. I hope this gives you some idea about how you can modify your code so that it operates more like you expect.

Matt
Applications Engineer
National Instruments
0 Kudos
Message 5 of 5
(7,052 Views)