Author Topic: PID PWM  (Read 22595 times)

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
PID PWM
« on: January 20, 2013, 07:08:23 PM »
Could any one advise the programming steps to configure the first channel  3,4 output pins for the PWM from the putput od PID for the control of 100rpm 24VDC, 190mA motor?. Assume the setpoint is 50rpm.
Please also advise the connections and the voltage/current required for the outputs.

I have tried the SetPWM and PID sample programs. But it does not work. I may need to change the values of frequency.

please advise.


Thank you.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PID PWM
« Reply #1 on: January 21, 2013, 10:38:15 AM »
What do you mean by SETPWM does not work?

Try SETPWM 1, 5000,1000

That should create 50% duty cycle at 1KHz frequency. If you connect your motor to it, it should run at a slower speed than when you connect to it at 100% duty cycle.

As for PID, do you have a techcometer that you can use to measure the RPM of the motor? Or if you have an encoder that output pulses to the PLC you can use the PMON function to measure the frequency which can be converted to the RPM. PID is a mathematical formula you apply to the difference between the setpoint and the measured value and adjust the output so to regulate the speed to converge to the setpoint value.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PID PWM
« Reply #2 on: January 22, 2013, 12:39:12 AM »
what would be the voltage (amplitude) level of PWM pulses when we connect 24V, 1A DC power source?. Could you please advise the 24V motor current rating for a stable PID based PWM control ?.

which solution is less complicated ,Tachometer or encoder?

please advise


roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PID PWM
« Reply #3 on: January 22, 2013, 12:50:47 AM »
if I used SETPWM 1, 5000,1000 as advised, how can I troubleshoot whether the statement is working ?
Will I get a 24V pulse or can I measure a frequency.



If I simply connect the power supply accross the output 3,4 ,will the motor respond?

what are the necessry changes that needed to combine SETPWM program and PID program provided in the sample?



support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PID PWM
« Reply #4 on: January 22, 2013, 09:05:30 AM »
Which PLC models are you using?

Please refer to Chapter 1 of your PLC's User Manual on how to wire the power to the load and the PLC output.

Most PLC outputs are 24V NPN. It sinks current when turned ON. It means you connect 24V to the high side of the load and the low side of the load to the PLC's output. Current flow from +24V through the load to the PLC output.

If you simply connect power supply direct to the PLC output and turn on the output you risk blowing out the driver IC.  So please check your wiring before turning on power supply.

The best way to observe the PWM is using an oscilloscope which shows you the waveform as well as the frequency.

If you don't have a scope then a simple volt meter should give you some indication of the average voltages presented to the voltmeter. When output is OFF it is measuring around 22V (due to 2V drop across LED) and when turned on at 50 duty cycle you should get around 11V. It may not be perfectly proportional on a voltmeter because what you measure is only an average and is affected by circuit inductance and capacitance. But it should give you an indication.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PID PWM
« Reply #5 on: January 23, 2013, 01:29:47 AM »
I found the 24V encoder with 500pulses to count the speed of the motor. One rotaion is 500 pulses. I am not sure whether the nano can detect 500pulses for each rotation. The motor is 100RPM motor consuming 130mA and encoder consuming 80mA.

The power supply to PLC is 24V, 2.2Amp rating.

Do you see any issue if I used PWM to drive motor using PID control with anoove specs and encoder of 500pulse/revolution?


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PID PWM
« Reply #6 on: January 23, 2013, 04:15:40 PM »
100 rpm = 100/60 = 1.667 revolution per second.

The encoder output 500 pulses per revolution? That means the pulse generation is at a speed of 500 x 1.667 = 833Hz.

Nano-10 PMON can handle 10KHz incoming pulses easily. So it should have no problem capturing the pulses correctly.

The hardware appear to work (if the output current is ok) so the rest is your programming skill and experience.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PID PWM
« Reply #7 on: January 29, 2013, 04:54:39 PM »
The PWM and motor workss fine without PIDcompute function.

The PIDcompute function does not work.
what should be the P ,I, D value for a motor with RPM of 100.
The encoder will give 500 pulses for one revolution.

With the sample SetPWM program the motor responds for different frequency. In the documentation, there is a demonstration of PID and PWM for DC motor speed control . But The frequency parameter is missing in the SetPWM function.

please advise what values should I use to control the motor in the entire frequecy range supported by the Nano10.

My requirement is to control 100rpm motor with PID closed loop and PWM.

Thank you.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PID PWM
« Reply #8 on: January 29, 2013, 08:20:59 PM »
In order to use PID control effectively you will need some digital control knowledge as it is unfortunately not simply plugged and play. You have to know that that PID is a mathematic function that computes the amount of control based on the error it measures current (the P term), previously (the I term) and what it anticipate the change to be (the D term).  The control output is then used to control an analog value such as PWM or AO.

You will likely need to use a P variable that is a fractional value (represented  by a fixed pint value) that the the historic cumulated error will not end up having too big a control factor on the output.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PID PWM
« Reply #9 on: January 30, 2013, 04:45:07 PM »
I have used PID blocks in many PLC logic designers. But here when I apply the same principle, it does not work.

Could you please give some tips to make it work?.

Pulse count or frequency representing the motor speed is the input. I need to control speed output. What should be the P,I and D. My typical setpoints will be 50RPM,25RPM,75RPM 100RPM.

The maximum RPM of motor is 100RPM.


The interesting thing is the PID compute function does not produce any value when there is a change. Currently the P is 20000, I=20, D=0

please help
Thank you


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PID PWM
« Reply #10 on: January 31, 2013, 08:35:40 AM »
Can you be specific what value does PIDcompute produce since "PIDcompute does not produce any value" has no meaning. PIDCompute will always return something (even if it is a zero it is still a value).

Does the computed value already exceed the control limit set by the PIDDEF command? If so it will stay at the limit and will not change.

What duty cycle output correspond to the RPM? For the PLC it does not "output" the RPM. It outputs the duty cycle for the PWM which is a value between 0 and 10000.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PID PWM
« Reply #11 on: February 01, 2013, 12:25:01 AM »
PIDDEF command set at 0 and 10000 . Always it stays at 10000

The SetPWM command has duty cycle and frequency. PID can be generated for Duty cycle, but how about the frequency?.

The maximum RPM value is 100, the encoder for rotation will generate 500pulses.

please advise


Thank you


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:PID PWM
« Reply #12 on: February 02, 2013, 10:48:23 AM »
What frequency to use for the PWM depends on the dynamics of the motor + load and you have to determine it from experiment. Try different frequency and see what work best over the entire speed range.

The encoder will generate a series of pulses. The maximum pulse rate = 100*500/60 = 833 Hz which the PLC can read using the PULSEFRQEUNCY after enabling the PMON for the channel. Your set point RPM can also be converted to pulse per second equivalent for the encoder. E.g. If you want to set it at 50 RPM, the expected pulse rate = 50*500/60 = 416Hz.

First of all you need to determine an operating point which is around the midway speed of the range of speed that motor is expected  to run. E.g. If the motor speed need to be adjustable between 0 and  100 RPM, your operating point can be 50 RPM

Now you need to manually adjust the PWM duty cycle until the motor reaches the operating point speed. Note the PWM duty cycle at this operating point.

Assuming the motor speed vary linearly with respect to the duty cycle (at least within the neighborhood of the operating point), you can then calculate the PWM duty cycle required for the motor to run at any set point speed. This is the open loop gain that you use to determine the duty cycle for a particular speed.

Assuming a new SETPOINT speed S is required. Based on the open loop gain you can calculate the duty cycle (D) of the SETPWM needed to achieve this speed.  

Now the close-loop part: The measured pulse rate from PULSEFREQUENCY is subtracted from the SET POINT frequency value which will give you the error E (which can be positive or negative).  You then feed this error value into PIDCompute() which will output a positive or negative number. The output value is the offset value that you add to the open loop duty cycle value (D). In other words PIDcompute() give you the correction that you need to add/subtract to the open loop duty cycle value in order to adjust the speed to reach the close loop speed.

You need to periodically measure the motor speed and change the SETPWM duty cycle until the error E = 0.

You will need to experiment with the P & I value to find out what works for you. This is the control loop tuning that need to be done empirically.


Email: support@triplc.com
Tel: 1-877-TRI-PLCS

roypthomas

  • Newbie
  • Posts: 18
  • I'm a llama!
    • View Profile
Re:PID PWM
« Reply #13 on: February 06, 2013, 10:38:54 PM »
Thank you for your advise.

I had experimented with various nan010 supported frequency starting from 16.7Hz to 320kHz range.

I found that at 16.7Hz, it will support duty cycle 5% minimum speed to 60% for maximum speed.

Now I am trying to mesure the speed of the motor.
Either I need a tachometer or rotary encoder or a wheel with optical sensor.

Could please advise the model number of NPN optical sensor that can do the job for 100RPM at various duty cycle from 5% to 60% .

When the duty cycle is 5% the voltage across motor is around 7V where as when the duty cycle is 60^ it is around 23.45V.

Insted of optical sendor I tried to use a 50ohm resister to generate 5V that represents the speed. But using series resistor with motor generates 5V at full speed and 0V at minimum speed, it is not accurate and not linear.

Therefor I must use a NPN optical senor and wheel coupled to shaft of the motor.  

Can I use any LED as ligh source and the NPN sensor to detect the light through the wheel to generate pulses of 24V?

1. please advise the model numbers of LED and the NPN optical sensor.

I must get the speed count  for PID to generate the PWM.  
2. Please also advise the starting P,I values for the duty cycle range 500 to 6000 for the frequency 16.7Hz?