MX009 - PID Control

Forum to discuss articles which have been published in Matrix Multimedia's article zone. If you have any comments or questions regarding the articles please post them here.

Moderators: Benj, Mods

User avatar
DavidA
Matrix Staff
Posts: 1021
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 49 times
Been thanked: 264 times
Contact:

MX009 - PID Control

Postby DavidA » Mon Apr 11, 2011 12:17 pm

Article: http://www.matrixmultimedia.com/article.php?a=56

If you have any questions for the author or comments on the article, please post them below.

cvanhal
Posts: 23
Joined: Wed Aug 26, 2009 8:51 am
Has thanked: 10 times
Contact:

Re: MX009 - PID Control

Postby cvanhal » Mon Apr 18, 2011 8:08 am

The example files are not posible to import in AVR V4 Flowcode..

When we import the file the program say that it is imposible to import because of an peace of program that not is installed..

Greetings.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 7310
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 1984 times
Been thanked: 2874 times
Contact:

Re: MX009 - PID Control

Postby medelec35 » Mon Apr 18, 2011 10:14 am

Thanks for article Ben. Very interesting.
I am interested in setting this up which a motor, that will work with pwm i/p and has a taco o/p.
For this to work, would that mean I have to convert the taco i/p into the equivalent of duty value?
E'g if duty is set for 40% = requested speed = 1200 RPM.
If taco is lower than 1200, then equivalent value that is then fed back into i/p of the system to produce the actual new requested duty value will be lower.
Would it be possible for help to produce a working PID flowchart based on a motor and taco feedback please?
Can the conversion of taco to a feedback value be done via software, or does it have to be hardware, like a integrating filter?

Martin
If your hardware is not working as expected, try looking here first:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

User avatar
Benj
Matrix Staff
Posts: 12619
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3521 times
Been thanked: 3411 times
Contact:

Re: MX009 - PID Control

Postby Benj » Mon Apr 18, 2011 11:01 am

Hi Cvanhal,

The AVR importing problem has been fixed here:
viewtopic.php?f=29&t=8319

Hi Medelec,

Does the tacho generate a analogue voltage or is it simply a digital rev count signal?

If the tacho is an analogue value and greater then 5V at full speed then you could use a potentiometer as a potential divider and then adjust the potentiometer so that when the motor is at full speed the tacho is outputting 5V into the system. If the tacho is under 5V at full speed then you may want to use an op amp or something similar to amplify the signal. Once you have done this your ADC reading should be close enough to your PWM duty cycle setting to give you a decent error.

If the tacho is a digital value then you will need to do something like my lego motor example where you are delaying for a period of time in between carrying out the PID calculations. Change this period of time to suit the number of tacho counts you get when the motor is at full speed. This is a little bit trickier to achieve as you also have to take into account lower speeds and accuracy.

Let me know how you getting on.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 7310
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 1984 times
Been thanked: 2874 times
Contact:

Re: MX009 - PID Control

Postby medelec35 » Mon Apr 18, 2011 11:56 am

Thanks for your reply.
Benj wrote:Does the tacho generate a analogue voltage or is it simply a digital rev count signal?


:oops: I forgot about the type of motors that produce and analogue o/p that is proportional to motor speed.
All I have ever used is the type that have a hall effect device built in. The tacho line is normally pulled up to +Supply. When motor rotates and magnet is close to hall effect, then tacho line is pulled to 0V. Its that type I would like to control.
The problem would be the requested speed could be any value. E.g turn a pot so requested speed is 1200 RPM, or turn pot so a new requested speed is 2300 RPM which could be boost for a motor to a fan.

Benj wrote:If the tacho is a digital value then you will need to do something like my lego motor example where you are delaying for a period of time in between carrying out the PID calculations. Change this period of time to suit the number of tacho counts you get when the motor is at full speed. This is a little bit trickier to achieve as you also have to take into account lower speeds and accuracy


I could not find the lego example.
I have searched for lego & pid.
Would you mind posting a link please.
I will make an appointment for the opticians after :P


Martin
If your hardware is not working as expected, try looking here first:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 7310
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 1984 times
Been thanked: 2874 times
Contact:

Re: MX009 - PID Control

Postby medelec35 » Tue Apr 19, 2011 12:14 pm

I believe I have worked it out?

What I am going to try is:
Setpoint = requested RPM (10bit) = Value ADC X constant = value of RPM
Encoder can be value of RPM measured, using timer0. To increase sample time, will count tacho for 250ms then multiply by 120 (count x 4 x 30 ) since motor has two magnets for tacho

E.g if setpoint = 1200 = 1200 RPM, then there will be no error when measured RPM = 1200.


Edit: I did not realise the lego motor was used for PID_Demo example.. My mistake. I should of read all the attached PDF document...
That will teach me!
Thanks Ben for sending the Link to the file.
If your hardware is not working as expected, try looking here first:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 7310
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 1984 times
Been thanked: 2874 times
Contact:

Re: MX009 - PID Control

Postby medelec35 » Tue Apr 19, 2011 2:45 pm

Here is my first untested attempt of using PID on a motor with taco i/p.
It is using Ben's PID_demo file

Ben would you mind have a look to see if you agree with the way I have modified it for tacho i/p please.
I have done it differently to how you suggested, as I found this way a bit less complex. But with that in mind, it may not even work.
I would like opinions before I connect to an EC motor. Either that or I connect and RUN! :P

Thanks Martin
Attachments
PID_demo_Modified.fcf
(14.01 KiB) Downloaded 1031 times
These users thanked the author medelec35 for the post (total 2):
cvanhal (Tue Apr 19, 2011 5:10 pm) • STibor (Sun Mar 25, 2012 7:46 pm)
Rating: 11.76%
 
If your hardware is not working as expected, try looking here first:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

User avatar
Benj
Matrix Staff
Posts: 12619
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3521 times
Been thanked: 3411 times
Contact:

Re: MX009 - PID Control

Postby Benj » Tue Apr 19, 2011 3:37 pm

Hi Martin,

All looks ok to me should hopefully be a good implementation. Bit of a shame about that multiply by 90 as you will only get feedback in the range of 0-90-180 etc. Hopefully will be enough resolution to keep the motor steady. If I were you I would be cautious too :) need one of those big red shut off buttons :D or maybe just push the plug half way into the mains socket so you can yank it out in a hurry if you need to. When powering up my flying machine I normally get behind something solid in case it decides it wants to stop listening to commands :mrgreen:

User avatar
Benj
Matrix Staff
Posts: 12619
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3521 times
Been thanked: 3411 times
Contact:

Re: MX009 - PID Control

Postby Benj » Tue Apr 19, 2011 4:11 pm

Hello,

Right Sean managed to find out what is causing the second import problem :mrgreen:

Basically what it was is that the port on the 16bit PIC device is essentially port 6 which is unrecognised by the chip I used when doing the AVR import.

The files have been fixed and here are the AVR imported versions.
Attachments
PID_demo.fcf_avr
(15.39 KiB) Downloaded 871 times
PID_sim.fcf_avr
(16.5 KiB) Downloaded 879 times
These users thanked the author Benj for the post (total 2):
cvanhal (Tue Apr 19, 2011 5:05 pm) • quazar (Sun Jul 02, 2017 6:52 pm)
Rating: 11.76%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 7310
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 1984 times
Been thanked: 2874 times
Contact:

Re: MX009 - PID Control

Postby medelec35 » Tue Apr 19, 2011 4:14 pm

Thanks Ben,
It will be fine really, just starting with a small motor lol.
This is using a motor that is rotating at a contstant speed e.g 1200 RPM, not altering position. So no encoders, just two hall effect devices to measure the RPM speed of motor e.g used on a backward curve fan.
The way it works, is it is only counting the pulses for 1/3 of a second. since there will be several rotations in that time, the final RPM is just tacho counts * 30 * 3
Its just like when our pulse is measured. Even though is beats per min. a smaller sample time is use, then like 10 seconds, then multiply beats by 6
I did not think I would loose much RPM using that method?

Martin
These users thanked the author medelec35 for the post:
cvanhal (Tue Apr 19, 2011 5:05 pm)
Rating: 5.88%
 
If your hardware is not working as expected, try looking here first:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

User avatar
Benj
Matrix Staff
Posts: 12619
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3521 times
Been thanked: 3411 times
Contact:

Re: MX009 - PID Control

Postby Benj » Tue Apr 19, 2011 4:56 pm

Hi Martin,

Ah ok I see yes I didn't quite understand how that was working so your probably right on that one, to be fair I couldn't think of a better way of doing it anyway so the way you have it should work well. Let me know how you get on in practise :)

cvanhal
Posts: 23
Joined: Wed Aug 26, 2009 8:51 am
Has thanked: 10 times
Contact:

Re: MX009 - PID Control

Postby cvanhal » Tue Apr 19, 2011 5:04 pm

Hello,

The file just loaded in AVR aim very happy now..

The crazy thing is that Medelec also sent me files he could open in the DEMO version and i could not open them..

i have taken en new Laptop allso, the only thing i had with ionstalling on new laptop W 7 that file DPINS.exe not could be installed..


i was thingking that caus the problem so very happy now

Thx

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 7310
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 1984 times
Been thanked: 2874 times
Contact:

Re: MX009 - PID Control

Postby medelec35 » Tue Apr 19, 2011 6:09 pm

cvanhal wrote:the only thing i had with ionstalling on new laptop W 7 that file DPINS.exe not could be installed..

That is related to installing new drivers. All its saying is they will need to be manually installed due to higher security of operating system.
I have replied the your PM, and gave you a link: viewtopic.php?f=2&t=8097
on installing drivers step by step.
These users thanked the author medelec35 for the post:
cvanhal (Wed Apr 20, 2011 9:26 am)
Rating: 5.88%
 
If your hardware is not working as expected, try looking here first:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

cvanhal
Posts: 23
Joined: Wed Aug 26, 2009 8:51 am
Has thanked: 10 times
Contact:

Re: MX009 - PID Control

Postby cvanhal » Thu Apr 21, 2011 8:13 pm

Thx for the examples..

Question from my side..

When i few the flow and chnge the Main in to ADC read against an SETpoint.

The output drives an PWM port..

My question do we need to maximate and minimate the PWM out put to 0 and 100%

as i see the Interger is counting in minus and start every 255 again positive..

how can i limit the output and have an imediate action on the PWM by changing on the feedback on th ADC??...

Thx

cvanhal
Posts: 23
Joined: Wed Aug 26, 2009 8:51 am
Has thanked: 10 times
Contact:

Re: MX009 - PID Control

Postby cvanhal » Sun Apr 24, 2011 6:38 pm

Hello Ben.

After your inspiration on PID i have got it working i guess.. :idea:


May be you willbe so kind and have a look at my flow and give me some comments on my work..

Thx for inspirating me to bite in this mathematics..

I did it as i have understand it, i do not like to copy and past to easy..

greetings Carlo

PID_controller_atmega32.fcf_avr
(21.42 KiB) Downloaded 883 times

User avatar
misoct
Posts: 64
Joined: Sat Sep 04, 2010 11:03 pm
Location: Egypt
Has thanked: 8 times
Been thanked: 17 times
Contact:

Re: MX009 - PID Control

Postby misoct » Sat Oct 08, 2011 8:43 pm

Hi carlo
I read your flowcode and I have some questions
1-your are using ERROR variables and your are not calculate it as ERROR=setpoint –feedback in cooling interval which equal delta in real or feed back – setpoint in heating interval where is usage of ERROR variable?
2-why are you fixed the setpoint at 500?
3-why are you using LED and PWM at the same time?
4-what the mathematical equation you are build your calculation for P,I,and D specially for heater?

thanks
Tharowat

AKPERRY
Flowcode V4 User
Posts: 18
Joined: Tue Mar 29, 2011 9:30 pm
Contact:

Re: MX009 - PID Control

Postby AKPERRY » Sun Mar 11, 2012 2:18 pm

from: Tony Perry

Hi Ben,
I have been asked to provide a lecture, relating to PID control, using flowcode. I have looked at the Matrix site, & note that you have written a PID document in the past. I have been asked to include some PID maths in the lecture if possible. I have a couple of questions:-

1.... Do you have any flowcode example programmes, describing PID applications?
2.... Are you looking to develop any PID applications at all?
3.... Have any users on the forum done any of this work, that they may be willing to share?

I note that Matrix have developed some Labview I/O VI's, & I also note that Labview have developed some PID VI algorithms, that are available in their Premium Suite, & the LabVIEW Control Design and Simulation Module and the LabVIEW PID Control and Fuzzy Logic Toolkit

Regards

Tony Perry
======================

AKPERRY
Flowcode V4 User
Posts: 18
Joined: Tue Mar 29, 2011 9:30 pm
Contact:

Coretex M3 Support

Postby AKPERRY » Sun Mar 11, 2012 7:44 pm

From: Tony Perry

Hi Ben,
I have a question, & I didn't know who to address it to:-

Is there any intention to support any products using the Cortex M3 core with Flowcode at all? As far as I can see, the various lists for the various devices all support alternate ARM cores.

Regards

Tony Perry
Last edited by AKPERRY on Tue Sep 11, 2012 10:54 am, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 12619
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3521 times
Been thanked: 3411 times
Contact:

Re: MX009 - PID Control

Postby Benj » Mon Mar 12, 2012 10:20 am

Hi Tony,

That specific calculation came from my the control module of my embedded University course.

This is the only Flowcode program I have written to do PID so far.

For our University course we used Excel to model sampled feedback control systems, starting from basic on/off control and working up to full PID.

The Excel file for PID might be available as part of the article download.

margaretdavid
Posts: 2
Joined: Fri Feb 07, 2014 11:49 pm
Location: new york
Contact:

Re: MX009 - PID Control

Postby margaretdavid » Fri Feb 07, 2014 11:53 pm

hello tell me about PID Control

User avatar
Benj
Matrix Staff
Posts: 12619
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3521 times
Been thanked: 3411 times
Contact:

Re: MX009 - PID Control

Postby Benj » Mon Feb 10, 2014 6:16 pm

Hello,

PID control is the combination of control techniques calculated based on difference between the required set point and the feedback signal (proportional error, integral error and derivative error).

Output = P * (Error – Prev_Error + (Error / I) + D * (Error – (2 * Prev_Error) + Prev_Prev_Error))

P, I and D in the above equations are floating point co-efficients which need to be tuned for the algorithm to work correctly on the system it is controlling.

quazar
Posts: 8
Joined: Sun Jun 04, 2017 6:27 am
Has thanked: 11 times
Been thanked: 2 times
Contact:

Re: MX009 - PID Control

Postby quazar » Sun Jul 02, 2017 6:46 pm

Hello Benj,
Sorry, maybe is a silly question, but, I was looking at the PID article, and could not figure out; how calculation on step1 would give a result of 10?
Steps 2 and 3 are correct. Could you please explain?

Here is a part of the PID article for reference:
Setpoint = 5
P = 2
I = 6
D = 1
(Step 1)
Feedback = 0
P * (5 – 5 + (5 / I) + D * (5 – (2 * 5) + 5)) = 10
At step 1 we are far from the setpoint so we have a large output to try and speed up the process to
get to the setpoint.
(Step 2)
Feedback = 1
P * (4 – 5 + (4 / I) + D * (4 – (2 * 5) + 5)) = -2.66

Thank you very much.
Have a great day!