Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
AgwanII
PostPosted: Oct 15, 2006 - 12:45 PM
Resident


Joined: Mar 17, 2005
Posts: 788
Location: Stockholm, Sweden

Hello,

Im just wondering if any of you guys made a autotuning PID in C I can use for one of my projects?

Thanks
/Anders
 
 View user's profile Send private message  
Reply with quote Back to top
Guillem Planisi
PostPosted: Oct 16, 2006 - 07:13 AM
Raving lunatic


Joined: Jun 11, 2004
Posts: 2326
Location: Vilanova (Barcelona)

The autotuning routines for commercial PID's are the most important code that the companyes have, and it is usually protectec, copyrighted, etc.

Probably you need to write your own, since I believe that you wouldn't find anything on the net, except some good theoretical explanations about classical aproaches to this subjects.

Guillem.

_________________
Guillem.
"Common sense is the least common of the senses" Anonymous.
 
 View user's profile Send private message  
Reply with quote Back to top
zainka
PostPosted: Oct 16, 2006 - 08:36 AM
Hangaround


Joined: Nov 16, 2001
Posts: 362
Location: NO(r)WAY!

Heres some PID c sources. Try to squeeze something usefull out of them.

http://www.linuxcnc.org/handbook/filere ... ource.html
http://home.att.net/~jackklein/C_Unleas ... _list.html

Last shows several other c sources, but PID is located in there somewehere

_________________
Regards
Vidar (Z)

"There is nothing new to be discovered in physics now, All that remains is more and more precise measurement." Lord Kelvin
 
 View user's profile Send private message  
Reply with quote Back to top
AgwanII
PostPosted: Oct 16, 2006 - 12:04 PM
Resident


Joined: Mar 17, 2005
Posts: 788
Location: Stockholm, Sweden

zainka, I can only find standard PIDs on those pages. Ive implemented a PID allready. Its not that hard, just a few lines of code.

Guillem Planisi, you are probably right. When Ive searched the internet for relay autotuning PIDs Ive only found reports that I need to pay for. Ill report back here if I find somthing or if I make my own.

/Anders
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 16, 2006 - 04:36 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 13578
Location: Orlando Florida

Your request was for a relay autotuning algorithm. I wondered how I missed out on learning how to tune relays, let alone autotune them. I suppose you meant you wanted an algorithm that 'really' works? Autotuning is 'adaptive control' right? You perturb the coeffcients while asserting a known input and measuring the output? Sounds complicated.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
ezcomp
PostPosted: Oct 16, 2006 - 11:36 PM
Hangaround


Joined: Dec 28, 2003
Posts: 356
Location: Oklahoma

Bob, maybe he means the pulse output is low enough frequency to be used with a relay (not a 'FET)...
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 16, 2006 - 11:58 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi there,

I am working on PID PWM output(with auto tune) algorithm right now.I am currently using Bascom 8051 with AT89C51ED2. I am highly impressed by TI's TLC1543 10bit data converter although ASM 'talk' routine took me 24hour + to get working, but it was worth struggle.
Since the plastics industries worldwide use multi PID pwm loops(16AMP relay's), I have the idea of porting not one interactive pid loop but 22 loops per micro since I have 64k flash to play with @ 5mips, lousy by avr standards (I know). The next problem I had was trying to achieve at least 12bits of pwm resolution, the AT89C51ED2 is equipped with 5, 8 bit pwm out puts which is woefully inadequate, I have consequently ordered 25 MCP4922 from digikey, these are dual 12 bit d/a's, pity they are not 4 or 8 converters per chip, but it's the best low cost effective device I could find.Again, it's a pity there is no serial load 8 channel 12 bit pwm chip on the market?
Okay, so you want some starting point of how to implement pid loops on a micro?
Your best port of call is to understand 2ODE(N.H.) and then learn how to quantize this equation, next you need to know what is meant by the past, present and future for time varying signals speaking classically of course.It would also help if you understood how integration stores potential energy and how differentiation stores kinetic energy.
I said, I wan't 22 loops with one micro, for a quantized 2ODE(NON.HOM.) to work precise cpu timing are needed. Try root(22) of complex number, giving equally spaced 22 phasors in a circle, this as far as I have got so far.
Good luck
Darren
P.S. that avrmega128 with 6 16 bit pwm outputs looks good to me.
 
 View user's profile Send private message  
Reply with quote Back to top
ezcomp
PostPosted: Oct 17, 2006 - 01:59 AM
Hangaround


Joined: Dec 28, 2003
Posts: 356
Location: Oklahoma

Darren a $5 CPLD can give you all the PWM your heart desires. Way elegant IMHO.
 
 View user's profile Send private message  
Reply with quote Back to top
Guillem Planisi
PostPosted: Oct 17, 2006 - 07:25 AM
Raving lunatic


Joined: Jun 11, 2004
Posts: 2326
Location: Vilanova (Barcelona)

PWM and relays are not good friends if you use 'high frequency' of let's say 1Hz. That means that the best relay wouldn't last longer than two days. For this such frequency, a soft PWM can be used very precisely without any problem using a single 16 bit timer and some soft in your m128.

If you are using solid state relays, with a much longer life, then perhaps you can increase the frequency, and then again the CPLD or another CPU (ie: m16, mCool can do part of the PWM with some outputs. But again, the main frequency is a really important factor to think about.

Guillem.

_________________
Guillem.
"Common sense is the least common of the senses" Anonymous.
 
 View user's profile Send private message  
Reply with quote Back to top
AgwanII
PostPosted: Oct 17, 2006 - 11:31 AM
Resident


Joined: Mar 17, 2005
Posts: 788
Location: Stockholm, Sweden

Relay autotuning PID does not have anything to do with using relays for PWM. The relay part is where you, in software, use a P regulator to induce stabile oscillations in the system. Then by measuring the oscillation time and some other parameters the PID parameters can be derrived.

I know there is a system for this where the P regulator has infinite gain (the relay form gain). There is also similar systems which use as low gain as possible that still induce stabile oscillations.

Ive found some information about the last of these too, but the writer of the information forgot to explain how one of the parameters is calculated. He just sais that the D gain is calculated as X/8 but does not say what X is. Sad
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 17, 2006 - 02:25 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi Guys,

Thanks for your reply's, with regards to using cpld as a multi 12bit pwm, thats a good point, but unfortunately I do not have hardware/programming support for cpld's, secondly, I wan't my multi pid controller to be flexible.At the moment I have a 555 generating a linear ramp which is level shifted to around 0.5...3.5V, since the mcp4922 is 12 bit(4096,vref=4.096V, 1 bit=1mV), it's going to output in the window of my ramp.The output board will consist of 10 or 11 16amp relays mounted in replaceble interchangable bases, however should the end user require 4..20mA output instead, then this will involve a simple output board exchange, the mcp4922 will be valid for any type of output.
With regard to relays burning out, they are found to work continously for about 1 year delivering 2kW of power.When the relays fail, unplug the old and in with the new for another years service, alternatively ssr are available at 20X the price of a standard $2.00 16amp relay.
Assuming correct pid parameters, plastics extrusion lines take about 15 to 20 minutes to reach set point, the pwm frequency or duty cycle time span is around 4 secs when compared to 15..20 minutes, the pwm quantization will appear continous.

Keep well and best regards to everyone
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
AgwanII
PostPosted: Oct 17, 2006 - 03:24 PM
Resident


Joined: Mar 17, 2005
Posts: 788
Location: Stockholm, Sweden

Darren, the relays does not burn out becaus alot of current run trough them. They burn out becaus they switch. Each relay has only a number of switches before they brake. And if a switch has 1 000 000 switches, and you switch once a second, the life for the relay is about 12 days.

Also note that high power troughput brakes the switch faster.

Not that this has anything to do with this thread.
 
 View user's profile Send private message  
Reply with quote Back to top
microcarl
PostPosted: Oct 17, 2006 - 03:51 PM
Raving lunatic


Joined: May 30, 2004
Posts: 7801
Location: Cincinnati, Ohio

One thing, if you use arc suppression (also called snubbers) across the relay contacts, they will last much longer. It is when the relay contacts open up that they are destroyed.

This is because electrons are basically mass in motion. With all mass, it takes time and energy dissipation to stop the movement. When the contacts open up, the electrons jump across the small opening. Once the flow of electrons bridge the contact gap, they continue until the contact gap is large enough to suppress their movement. It is the arcing that destroys the relay contacts. In effect, the relay contact material is destroyed due to heat and removal of the material that they are made of.

By using an arc suppresser or snubber, the electrons are shunted around the contacts in a controlled maner, saving the contacts.

In fact, pretty much every quality solid state relay incorporates a snubber circuit of some kind in their output.

Do a google search for relay arc suppression or contact snubber, or something similiar. There are about a dozen useful circuit configurations out there that will give you some ideas as to how to implement them in your particular application.

_________________
Carl W. Livingston, KC5OTL
microcarl@roadrunner.com

It's a fundamental law of nature... All things gravitate toward total chaos!!!

The original Dragon Slayer !

Long live the AVR!!!
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
darren
PostPosted: Oct 17, 2006 - 04:27 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi guys,

Yes, I agree that relay contact(s)(spdt) decomposition is due to the contacts relay making and breaking, however under normal operation they do last from 6 months to year, bearing in mind production might only use the extrusion line perhaps for 12 hours once a week, i.e., as production/jobs dictate. The relays in question have been used in analogue pid controllers for decades, the only problem I have seen is that these relays should be mounted in a plugin bases to make maintantence alot easier other than having to desolder relay from the board.
I experimented with various types of cr snubbers to try and lengthen the life of the particular contacts but unfortunately, I found, snubbers are unwarranted. Remember guys, these relays can be had for $1.50 in quantity, if they last for 6 months or more who cares?

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Oct 17, 2006 - 05:07 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 19089
Location: Wisconsin USA

Quote:

I found, snubbers are unwarranted. Remember guys, these relays can be had for $1.50 in quantity, if they last for 6 months or more who cares?


Hmmm--

One of our controllers uses relays, and these go into commercial products that are situated in a retail environment. It is VERY important in our app to have varistors in the proper places. The switching loads are modest so the relay life isn't greatly affected without them. But the noise generated with "unprotected" switching is very important, and causes no end of unpredictable operation.

Let's put that part aside for now. Consider that [say] 100/month of these machines are shipped. If a random relay fails after 6-12 months and thereafter, are you expecting minimum-wage Joe Hamburger to diagnose and swap relays? Not. You end up with endless service calls, and the reputation for unreliable units will soon kill the product line.

Let's also consider Carl's industrial production line situation, where each minute of downtime costs many $$$.

Relays under modest switching loads will last for a million cycles, give-or-take a factor of 10 depending on the app. That doesn't mean one should play fast-and-loose with snubbing.

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 17, 2006 - 06:16 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

But the noise generated with "unprotected" switching is very important, and causes no end of unpredictable operation.

Excellent point Lee, I must admit I only gave this a brief consideration... Thanks for a very valid tip. Further to this, I think I can live with blue disc mov along side each relay. With regards to relay exchange, you raise more valid points. May I suggest that the relay bank is mounted on seperate output pcb board which plugs into the main motherboard(mpu)with plugin/out terminal connectors, i.e., for fast style McDonalds turn around, assuming of course the maintenance staff have plenty of spare output boards.
Once the production heat is off, maybe the maintenance staff can test the faulty output relay board on a test jig back at the workshop and repair it down to single relay level(optional of course).

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Oct 17, 2006 - 06:48 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 19089
Location: Wisconsin USA

Quote:

May I suggest that the relay bank is mounted on seperate output pcb board which plugs into the main motherboard(mpu)with plugin/out terminal connectors, i.e., for fast style McDonalds turn around, assuming of course the maintenance staff have plenty of spare output boards.


Nope.
1) Cost-sensitivity dictates less components
2) Pluggable relays (or other componets) introduces more points of failure at the connections

The nature of the apps is that x years of normal operation will not trigger the relay anywhere near the normal life. E.g., one cycle per hour 24/7 is 8700 operations/year, or about a 100 year life. Even 1 cycle/minute during a 12 hour business day will take 4-5 years to reach a million operations. Anything switching faster than a comforatble lifetime--don't use a standard relay.

YMMV.

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
AgwanII
PostPosted: Oct 17, 2006 - 06:50 PM
Resident


Joined: Mar 17, 2005
Posts: 788
Location: Stockholm, Sweden

The problem that is beeing solved using varistors or diodes is if the load is inductive. It is when an inductive load is turned off using a relay that the voltage over the relay can go very high, (thousands of volts depending on inductance) and cause sparks that damage the relay.
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 17, 2006 - 09:28 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

theusch wrote:
Quote:

May I suggest that the relay bank is mounted on seperate output pcb board which plugs into the main motherboard(mpu)with plugin/out terminal connectors, i.e., for fast style McDonalds turn around, assuming of course the maintenance staff have plenty of spare output boards.


Nope.
1) Cost-sensitivity dictates less components
2) Pluggable relays (or other componets) introduces more points of failure at the connections

The nature of the apps is that x years of normal operation will not trigger the relay anywhere near the normal life. E.g., one cycle per hour 24/7 is 8700 operations/year, or about a 100 year life. Even 1 cycle/minute during a 12 hour business day will take 4-5 years to reach a million operations. Anything switching faster than a comforatble lifetime--don't use a standard relay.

YMMV.

Lee


Hi Lee,

Hmmm..., you are really squeezing me into a corner here?
With regards to extra cost considerations, whats wrong with a little extra cost for flexibility/easy maintentance as a return?
Secondly, whats wrong with specifically designed 16 amp relay base, alternatively and since the relay base pcb footprint is identical to the actual relay, if customer don't like pluggable relays then solder them directly to the board, options, options abound...
From actual practice, $1.50 relays can give anything from 6 months or more switching life spans, of course there are more expensive relays around, you could go one up on that even and design a full bridge thyristor stack, but the latter would involve alot of complicated hardware not to mention the extra expence.

yes, I agree with your points Lee, but I challenge you to come over here and look at the U.K.'s, dire engineering/business freternity, why it's an absolute shambles.You must come and see for yourself at the existing equipment thats in use, it's like something out of Charles Dickens time and it's nationwide at that.

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
John_A_Brown
PostPosted: Oct 17, 2006 - 09:47 PM
Raving lunatic


Joined: Sep 20, 2003
Posts: 2745
Location: Surrey, England

Quote:
yes, I agree with your points Lee, but I challenge you to come over here and look at the U.K.'s, dire engineering/business freternity, why it's an absolute shambles.You must come and see for yourself at the existing equipment thats in use, it's like something out of Charles Dickens time and it's nationwide at that.

That's a bit strong... I assume from your strange spellings and shoddy punctuation that you are not indigenous to the UK?
But even if it were true that "it's like something out of Charles Dickens time", is that a justification for you to cut corners?
 
 View user's profile Send private message  
Reply with quote Back to top
microcarl
PostPosted: Oct 17, 2006 - 11:00 PM
Raving lunatic


Joined: May 30, 2004
Posts: 7801
Location: Cincinnati, Ohio

The thing to remember is this...

You want absolute reliability! In order to achieve that extended level of reliability, you have to design it in or, stated to Lee's requirements to meet cost, design the un-reliability out of the system. For Lee, this could actually round out to be a cost reduction as volume is in play. For me, reliability is always designed in. I.E. Using a 30 ampere relay where a 5 or 10 ampere relay would have surficed.

I just designed a "Hand Wash" basin controller for work. Being in a food plant, it's very important for employees to wash their hands just before they enter the work area. Imagine not being able to handle frozen pizza with clean hands. These hand wash sinks HAVE TO WORK. My choice, I did just that! I chose to use a 30 ampere relay for a 17 watt 24VAC solenoid valve coil. Rediculas! You can say that, but I only had to manufacture 18 of these devices. The extra dollar for the 18 controllers was trivial compared to the troubly that failures would generate due to a failure of that relay. Without a doubt, this is over-kill. But, it is over-kill that was calculated against the risk of untimely failure any the consequences.

At some point, you will have to decide the risk you can bare. If the customer requires absolute reliability, you will have to design it in or, design the un-reliability out of the system, as Lee does.

It's all a trade off. If the customer wants absolute reliability, the customer must bare the added cost in hardware or engineering effort.

_________________
Carl W. Livingston, KC5OTL
microcarl@roadrunner.com

It's a fundamental law of nature... All things gravitate toward total chaos!!!

The original Dragon Slayer !

Long live the AVR!!!
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
darren
PostPosted: Oct 17, 2006 - 11:05 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

That's a bit strong... I assume from your strange spellings and shoddy punctuation that you are not indigenous to the UK?
But even if it were true that "it's like something out of Charles Dickens time", is that a justification for you to cut corners?

Hi John,

I am indigenous to the U.K., but wish I'd been born either French,German or Dutch and dare I say it, I am very pro 'Old Europe'. Disregarding British engineering, just compare stats. with 'Old Europe' with regard to say child poverty. In fact, if you can wade yourself through the very excellent British propaganda machine(it's the only thing we British are good at), then I'm afraid anything thats good we come bottom of the list, anything thats bad we come top of the list, see for yourself.Do you have a dentist??
60% of voters don't bother voting, is that perhaps saying something?? Wink

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
mneary
PostPosted: Oct 17, 2006 - 11:43 PM
Raving lunatic


Joined: Sep 25, 2003
Posts: 2189
Location: Los Angeles, USA

Did you find a PID algorithm that you can work with?
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 18, 2006 - 12:54 AM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi Carl,

Your hand washing machine sounds interesting, over engineered perhaps, but the military use over engineering all the time since peoples lives maybe at risk, theres nothing wrong with over engineering anything so long as one can afford to do so. Did your pizza company give you an award for your design. I certainly hope so??

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
microcarl
PostPosted: Oct 18, 2006 - 01:13 AM
Raving lunatic


Joined: May 30, 2004
Posts: 7801
Location: Cincinnati, Ohio

darren wrote:
Hi Carl,

Your hand washing machine sounds interesting, over engineered perhaps, but the military use over engineering all the time since peoples lives maybe at risk, theres nothing wrong with over engineering anything so long as one can afford to do so. Did your pizza company give you an award for your design. I certainly hope so??

Best Regards
Darren


Well, my job is akin to that of a manufacturing engineer. I don't have the actual title because I have a BSEET and not a BSEE - the fools... (Oh! That must be me!!!)

Well, I am paid to have ideas and incorporate technology that will provide the highest bang for the buck. The catch is, everything that I do, while it may not have a direct pay-back in dollars and cents, must work reliably. The down-time for each line is between $57.00 and $93.00 per minute, depending on which line.

Most of the work I do evolves around improving quality of the product, throughput, reduction of waste or, actual product cost reduction.

I wish I did get awards for the ideas that I've incorporated into the manufacturing process at work. Better yet, I'd like to get even 1% of the money that I have saved them over the past 5 years. My typical cost savings to the company that I work for is in excess of $1,000,000.00 per year. In fact, I have to state yearly goals, in $$$, that I intend to save them. That isn't so hard as, there is a lot to make better. The hard part is the politics involved in getting the ideas into practice.

_________________
Carl W. Livingston, KC5OTL
microcarl@roadrunner.com

It's a fundamental law of nature... All things gravitate toward total chaos!!!

The original Dragon Slayer !

Long live the AVR!!!
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
darren
PostPosted: Oct 18, 2006 - 01:20 AM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

mneary wrote:
Did you find a PID algorithm that you can work with?


Hi,

My PID algorithm is based on an approximate(time quantized) 2ODE Non.homogenous(pls excuse spelling) equation. I am still waiting for my MCP4922 2 channel 12 bit d/a converters to arrive.Delta time is estimated at about 10Msec upwards. It will work, but the main question is how many pid loops can I squeeze into one MPU?, the other point I wish to raise is that MPU's such as the 89S52 are almost as cheap as 741 op amps, that said reading an SAR a/d's are quite noisy and indeterminate for the last 2 or 3 (lsb)bits.
Doing some software integration on a/d data converter stabilises the output somewhat but requires Msec of cpu time to do this, perhaps a low cost 89S52 support MPU can be used dedicated to just reading the TLC1543 a/d data converter, just an idea.
I am currently thinking of migrating towards AVR atmega128, since the compiler route is open to me, I am still undecided on this score, we shall see....
Any Ideas anyone...
Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
mneary
PostPosted: Oct 18, 2006 - 04:07 AM
Raving lunatic


Joined: Sep 25, 2003
Posts: 2189
Location: Los Angeles, USA

It looks like you must be using floating point if software integration of a few values takes a Msec (msec?). Save a lot of time using fixed point.
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 18, 2006 - 01:07 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

It looks like you must be using floating point if software integration of a few values takes a Msec (msec?). Save a lot of time using fixed point.


Hi Mneary,

Hmmm..., no, I use averaging(fixed 16bit words), take 50 samples, add 'em all up, and then finally divide the sum by the number of samples, i.e., 50.
Works great, but consumes lots of mpu time.

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 18, 2006 - 02:12 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 13578
Location: Orlando Florida

You know that if you keep the running sum, and the data points in an array (32 or 64) then with each new sample you subtract off the oldest sample from the running total, add in the new and save the sample in the array, advance the index, right shift the total 6 places to get new avg. This gives you a new avg every sample with only an add and subtract instead of 64 adds. Do you have a link where I can read up on 'relay autotune' or '2ODE equation'? Fascinating that a forum thread reveals a whole new parallel universe of stuff I've never heard of before.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
theusch
PostPosted: Oct 18, 2006 - 02:22 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 19089
Location: Wisconsin USA

Quote:

Hmmm..., no, I use averaging(fixed 16bit words), take 50 samples, add 'em all up, and then finally divide the sum by the number of samples, i.e., 50.
Works great, but consumes lots of mpu time.


Hmmm---

Many of my apps do exactly the same thing. I do continuous A/D conversions (round robin); every 10ms. there is a new sample on each channel and I add it into the total. Every half second I compute the average as you described and "close the loop". This averaging code
Code:

//   adc_total[] now has a 50-conversion total.  Calculate the average into
//   ad_value[] for processing.
//
      for (looper = 0; looper < ad_count; looper++)
         {
         ad_value[looper] = adc_total[looper]/TICKS_PER_TOCK;
         adc_total[looper] = 0;
         }

takes 2324 cycles, or 232us. at 10MHz. "Lots" of time? Perhaps. If this is the critical path, then it could certainly be shortened. One way is to make the number of samples a power of 2, so shift instead of dividing. Probably a few cycles would also be saved with pointers vs. the repetitive subscripting that I used. It was fast enough so I don't need to fuss with it.

The simplest way is to not average at all--just use the raw total as a 16-bit number vs. a 10-bit number, and retain all the fractional precision. You actually gain a bit or two of resolution that way.

For work where "best" results are needed then the input results need to be filtered anyway, right? Kalman & such. Whole different ballgame. This app didn't need it.

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 22, 2006 - 01:08 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi Folks,

First of all, I would like to apologise to all those that have posted new replies, I thought my email notification flag was set when clearly it wasn't consequently my thoughts were that everyone had lost interest.Again, I am deeply sorry for this, I more than anybody enjoy friendly arguments. Even though I use Atmels 8051 type MPU's I have been made to feel very welcome here, I thank you all for that.

Best Regards
Darren
P.S. I have made doubley sure this time that my email notification is switched ON.


Last edited by darren on Oct 22, 2006 - 02:17 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 22, 2006 - 01:53 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

bobgardner wrote:
You know that if you keep the running sum, and the data points in an array (32 or 64) then with each new sample you subtract off the oldest sample from the running total, add in the new and save the sample in the array, advance the index, right shift the total 6 places to get new avg. This gives you a new avg every sample with only an add and subtract instead of 64 adds. Do you have a link where I can read up on 'relay autotune' or '2ODE equation'? Fascinating that a forum thread reveals a whole new parallel universe of stuff I've never heard of before.


Hi Bob,

You make a good point regarding averaging a SAR a/d, but what you take off the roundabouts you gain on the swings, i.e., for your scheme to work 50 16bit words would be required which gombles up much needed variable ram space.
Regarding a good PID link, I'm afraid the only good one that had substance has dissapeared, nevertheless, I derived my own from 2ODE (non.hom.) mathematics.
Here's an excellent maths link which I found a couple of weeks ago...http://tutorial.math.lamar.edu/AllBrowsers/3401/3401.asp

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 22, 2006 - 02:09 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi Lee,

Sorry for the delay, as already exlained, yes, I cannot see anything conflicting with my own thoughts.My Microchip MCP4922 12 bit d/a arrived safely, one of the four sent to me free by Microchip are busy ticking away in my prototype with much success. Last night, I had fun and games trying to get timer2 auto reload to work, after about two hours of effing and blinding I finally have it running, it interrupts the cpu every 10mSec, this is only approximate at this stage in the game.
With regards to averaging a/d sar samples, I am always happy with a good approximation no matter what, I gave up the ghost regarding absolute exactitude long ago.
If I want greater stability and accuracy then their are other a/d candidates such as single/dual slope integrating type a/d, but they take about 130mSEC for one conversion!.

Keep well
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 22, 2006 - 03:10 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 13578
Location: Orlando Florida

OK....'2ODE' means 'Second Order Differential Equation' for any freaks wondering what it meant. I thought 2ODE was an SMS abbreviation for some new mathematics algorithm or something until I looked at the link.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
darren
PostPosted: Oct 22, 2006 - 08:42 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

OK....'2ODE' means 'Second Order Differential Equation'


Hi Bob,

Thanks very much for making things clearer for others to follow, I would also like to add that there are two types of 2ODE's...
(1)...Linear homogeneous (always decay to zero)
(2)...Linear non homogeneous

There are many others aswell such as ellyptic differential equations but I am no where near that sort of math level yet.The equation I'm proposing as a PID algorithm, is 2ODE non homogeneous approximation.It's an approximation because MPU time is finite. As long as the output element(heaterband), energy charge time is much longer than MPU PID algorithm execution, delta time or pass time, then there should be no problem. Charge time for a typical heater band is around 15 minutes as apposed to MPU delta time of around 100mSec.There will be 10 PID loops in total, each serviced successively every 10mSec, the MPU is interrupted every 10mSec by timer2.
Just one other point to think about, each extrusion line contains 10 heater bands, imagine now that you have a particular heater band and one either side of the former, since heat permeates through the entire line, each heater band will be getting heat energy from it's adjacent partner and vice versa.
So, given the situation, may I propose a single common ramp generator for all 10 PID loops as apposed to having a separate ramp generator dedicated for each PID loop.
Both the MCP4922 and the ramp gen. are fed into a comparator ('393) whose output furnishes the final pwm towards the relay driver or switch.
How does this sound so far...?

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
tpappano
PostPosted: Oct 22, 2006 - 11:27 PM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


Quote:
Both the MCP4922 and the ramp gen. are fed into a comparator ('393) whose output furnishes the final pwm towards the relay driver or switch.
How does this sound so far...?


Maybe I'm missing something, but I don't understand
why you would be mixing discrete comparators and
(I'm guessing) analog ramp generators into what should
be a purely digital system. Why aren't you going to
do all your pwm in software? Also, why are solid state
relays not being used to control the heaters?

Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 23, 2006 - 12:40 AM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

Why aren't you going to
do all your pwm in software? Also, why are solid state
relays not being used to control the heaters?


Hi Tpappano,

You post an extremely valid point with regards to pwm implementation in software. I spent quite a few days pacing up and down my workroom trying to think of a way to implement a software ramp, unfortunately, I concluded that the MPU would have 'watch' and continously compare the calculated value against some type of software ramp(e.g. a counter, which the software would have to update continously with precise timing) and then have make decissions as to when the output should go high or low. Have a think about it, I assure you it is not as easy as it seems.Indeed, both the AVRMega64/128 sport a total of six 16 bit pwm for the very reason that it is encredibly difficult to implement in software, very frustrating, I know...
Regarding SSR vs Mag.relays, it's simply down to cost, this has been discussed if you read all the post's

Hope this put's you in better light.
Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 23, 2006 - 12:50 AM
10k+ Postman


Joined: Sep 04, 2002
Posts: 13578
Location: Orlando Florida

So far I've figured out this is an industrial temperature controller. If you were going to buy one, what specs would you look for? Evidently, you have some tight requirements that warrant a custom controller. I know that the thermal time constant of the thermocouples probably sets the loop time of the PID calcs... What temp range? What resolution? How many channels? How many volts and amps on the heaters?
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
tpappano
PostPosted: Oct 23, 2006 - 12:55 AM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


Quote:
I concluded that the MPU would have 'watch' and continously compare the calculated value against some type of software ramp(e.g. a counter, which the software would have to update continously with precise timing) and then have make decissions as to when the output should go high or low. Have a think about it, I assure you it is not as easy as it seems.


Actually, it is very simple, I do this a lot. Just
insert code such as the following into your 10ms interrupt service, and you are off and running.

As for the relays, cheap mechanical relays that need
periodic replacement might not be more economical
than solid state ones that don't.


Code:
    static uint8_t   htrmod=0;             // heater pwm counter
    static uint8_t  htr0pwm=0;             // Heater 0 PWM setting
    static uint8_t  htr1pwm=0;             // Heater 1 PWM setting
    static uint8_t  htr2pwm=0;             // Heater 2 PWM setting
    static uint8_t  htr3pwm=0;             // Heater 3 PWM setting
    if(++htrmod>htrtop)                    // pwm 4 heaters on pb0,pb1,pb2,pd2
    {                                      // at 1 sec rate
        htrmod=0;                          // turn heaters on as needed
        if(htr0pwm>0)PORTB &= ~htr0;       // heater 0 on?
        if(htr1pwm>0)PORTB &= ~htr1;       // heater 1 on?
        if(htr2pwm>0)PORTB &= ~htr2;       // heater 2 on?
        if(htr3pwm>0)PORTD &= ~htr3;       // heater 3 on?
    }                                      // turn heaters off as needed
    if(htrmod>htr0pwm)PORTB |= htr0;       // heater 0 off?
    if(htrmod>htr1pwm)PORTB |= htr1;       // heater 1 off?
    if(htrmod>htr2pwm)PORTB |= htr2;       // heater 2 off?
    if(htrmod>htr3pwm)PORTD |= htr3;       // heater 3 off?


Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 23, 2006 - 11:29 AM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

bobgardner wrote:
So far I've figured out this is an industrial temperature controller. If you were going to buy one, what specs would you look for? Evidently, you have some tight requirements that warrant a custom controller. I know that the thermal time constant of the thermocouples probably sets the loop time of the PID calcs... What temp range? What resolution? How many channels? How many volts and amps on the heaters?


Hi Bob,

We have a 1kW or 2kW heater band with a type k thermocouple embedded in it. As thermo couples go, they are one the quickest responding temperature sensors in town, it's not the thermocouples time constant thats the problem but more like the time required to heat up the actual heater band to around 200 deg.C which turns out to be about 15 minutes, if you were to graph the response, temperature against time,it has the same characteristic as a charging capacitor except Volts are exchanged with temperature.
Off the shelf mag. relays, 16 amp(max)@230Vr.m.s. are available and are currently in use the world over due to their low cost.I am proposing a multi 10 channel PID controller with as much flexibility as possible, i.e., to give the end product the best chance of life.

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 23, 2006 - 01:06 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

Actually, it is very simple, I do this a lot. Just
insert code such as the following into your 10ms interrupt service, and you are off and running.


Hi Tom,

Thanks for your post, I am not 100% conversant with c syntax, so please bear with me on this score. As far as I can make out, every 10mSEC interrupt, I give the ramp counter a tick which starts from 500 to 3500 this totals 3000 ticks, which will result in a ramp time of 30 Secs, correct?
Also, there will be a 11 tick delay between 1st PID loop and back to the 1st PID loop, there will be a 100mSec delay from 1st PID loop and back to 1st PID loop, in other words, my software ramp will have chunks of dead time embedded in it.
Another reason for using a 12bit d/a, is to make the entire setup flexible whereby the output analogue ramp/relay board can be exchanged for 10(of) 4..20mA outputs, in which case the d/a's would be justified and valid. Next, 30 secs for ramp time is too long, I am shooting for 4 Secs, given an analogue ramp, this time can easily be changed by a simple trimmer pot or it can be brought under MPU control.Flexibility is the name of the game here.
Lee, where are you, can someone please give his cage a rattle for me? What does Lee think about Tom's software ramp arrangement?

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
tpappano
PostPosted: Oct 23, 2006 - 05:59 PM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


Hi Darren,

Basically this is how my example works:

"htrmod" is the "ramp" timer, incrementing at a 10ms
rate from 0 to 100 (for example). This establishes
1 second pwm rate for the heaters and a 1% resolution
for the settings (0-100%). The "top" count setting
for htrmod was not shown, but in this example would
be 100.

"htr(x)pwm" are the setpoints for the heater duty
cycles. These would be updated as needed by your
pid calculations with values from 0-100 for minimum
to maximum heat.


At each 10ms interrupt, the pwm setpoints are compared
with the counter and the conditionals determinine if
it is time for any heaters to turn off.

Each time the timer is rolled over to zero, all heaters
are turned on. This of course happens within a single
interrupt service call, so essentially they all turn
on at the same time. All conditionals are also tested
every 10ms.

There are no undesired "dead" times or delays. Operation is the same as if you had a bank of
hardware pwm timers.

By choice of interrupt interval and "top" count,
any pwm frequency and precision you need can be set up. Duplicate the lines of code for as many heaters as you need to control.

Hope this explains it a little better.

Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Oct 23, 2006 - 06:13 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 13578
Location: Orlando Florida

Still trying to figure out if 10 single channel temp controllers would be cheaper/better/simpler/more reliable than one 10 channel controller. If the AVR costs a couple bucks and the relay costs 10x that, then, there is no clear winner. If the 10 ch controller has some additional smarts, because all the channels can see what the others are doing (tightly coupled), and this is a unique feature, then you just need an AVR with enough cpu and io to run the 10 channels. I'd still like to know the specs for the PID performance... what is the acceptable overshoot, response time, etc. Would regular old proportional control be good enough? If you buy the Maxim thermocouple preamps, the AVR a/d can read the temperatures. Doesnt one of the newer AVRs have a 10 ch a/d?
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
tpappano
PostPosted: Oct 23, 2006 - 07:12 PM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


Quote:

Still trying to figure out if 10 single channel temp controllers would be cheaper/better/simpler/more reliable than one 10 channel controller.


One advantage of a multi-channel unit is savings from
not having to duplicate the human interface.

Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 23, 2006 - 07:31 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

what is the acceptable overshoot, response time, etc.

Hi Bob,

Thats for the end user to decide, If the end user understands PID and enters the correct P.I.D. parameters then he will get a critical damped system, if he has trouble understanding PID for a particular loop then option is open for auto tune, where the MPU will test the heaterband or whatever its regulating, and calculate the required PID parameters.
The AVR64/128 does have a 10bit a/d 8 channel with 6 16 bit pwm channels, if you read the previous posts, I've been drooling over them as I am using Atmels other 1/3 namely AT89C51ED2.

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 23, 2006 - 07:48 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

"htrmod" is the "ramp" timer, incrementing at a 10ms
rate from 0 to 100 (for example). This establishes
1 second pwm rate for the heaters and a 1% resolution
for the settings (0-100%).

Hi Tom,

You are using 7 bit resolution against my twelve, also my proposed 10 PID loops are going to be totaly independent of one another, each having it's own set of PID parameters, end user defined.The only common to all 10 PID loops will be the ramp.Your relays are all turning on together and all turning off together, right?, in effect thats only one loop.

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
tpappano
PostPosted: Oct 23, 2006 - 08:03 PM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


Quote:
Hi Tom,

You are using 7 bit resolution against my twelve, also my proposed 10 PID loops are going to be totaly independent of one another, each having it's own set of PID parameters, end user defined.The only common to all 10 PID loops will be the ramp.Your relays are all turning on together and all turning off together, right?, in effect thats only one loop.

Best Regards
Darren


All the heater pwm channels are independent, and drive
each heater with the duty cycle written into each
individual setpoint variable. The pwm resolution
is not (and need not be) related at all to the
resolution of the a/d subsystem. The code I have
shown just takes the "Pouts" from your pid function(s)
and converts them to pwm signals to turn the heaters
on and off. FWIW, you can make the pwm resolution
and rate anything you want, within reason.

I could show you how to do the whole thing, but
that is how I make my living Cool

Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 23, 2006 - 10:18 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

The pwm resolution
is not (and need not be) related at all to the
resolution of the a/d subsystem

Hi Tom,

Yes, I agree that the pwm is not related to the bit field of the a/d system, but the output d/a data converter does set the pwm resolution, I am proposing 12 bits, but you are using 7 bits or 0..100%, dont you find this resolution a little low. For example and assuming your PID loops are working, if I place my scope probe on your pwm signal then surely the quantization would be apparent?(descreet sudden changes).
That said, I am highly pleased that you consider the single or multi PID a trade secret, great stuff!
I assure you, you are not the first, on this thread, to post such a remark. However, I have to grant you 5 stars for your shear honesty, well done!, clearly PID embedded in a MCU has some value assigned to it.All the more reason for me to continue...

Keep well
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
tpappano
PostPosted: Oct 23, 2006 - 11:58 PM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


Quote:
I am proposing 12 bits, but you are using 7 bits or 0..100%, dont you find this resolution a little low.


Not at all. We are after all, talking about closed
loop control. The pid loop will modulate the heater
to produce whatever average power is needed. For an
example, one of my products has a sensor maintained
at 1450 DegF, and that temp is held within 0.5 degree,
even with substantial variation in thermal load as
the process runs. In any case, as I have shown above,
you can set the pwm resolution up to be anything you
want. If this is to be a new design, I would dump
the whole d/a/ramp generator/comparator scheme because
it gets you nothing that can't be accomplished in
software, with a much lower overall component count,
cost, and better reliability.

Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 24, 2006 - 12:37 AM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

If this is to be a new design, I would dump
the whole d/a/ramp generator/comparator scheme because
it gets you nothing that can't be accomplished in
software, with a much lower overall component count,
cost, and better reliability.

Hi Tom,

It is a new design, that said, a few years back, I developed an analogue controller whereby the PID parameters where calculated and the components hard wired or soldered into the controller, as such, the PID parameters were fixed, anyhow the entire exercise was to test my own understanding of PID. After this, I could compare my own findings with those who claim to understand PID and write books on the subject and by this I'm sure you are aware of what I mean.
With regard to the software ramp, your idea sounds good and I am in total agreement with you in regards to the benefits attained under software.
Just one question, does your PID allow PID parameter alteration whilst it is on the fly or busy regulating?

Look forward to your reply and best regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
tpappano
PostPosted: Oct 24, 2006 - 01:01 AM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


Quote:
Just one question, does your PID allow PID parameter alteration whilst it is on the fly or busy regulating?


Yes, I generally keep the setpoints and pid parameters
in arrays. This is so that one process can adjust
another, as some of my systems need this capability.

Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 24, 2006 - 02:18 AM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Quote:

Yes, I generally keep the setpoints and pid parameters
in arrays.

Hi Tom,

Thanks for your reply, with regard to arrays, I was just checking earlier on if Bascom 8051 supports multi dimentional arrays and it appears only 1 dimentional arrays are supported, Oh well..., I guess I can live with that. I am going to have a rethink about your software ramp and pwm resolution... and do some more pacing in my workroom. Thanks for the info. Tom

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
tpappano
PostPosted: Oct 24, 2006 - 02:40 AM
Posting Freak


Joined: Dec 01, 2003
Posts: 1884


You are welcome!

I use single dimension arrays, one for each parameter
with the number of elements corresponding to the
number of channels. I also put the pid formula
into a form that accepts a channel index value,
then when pid(n) is called, channel n gets updated.
The index is incremented, and pid() called from the
interrupt service.

Tom Pappano
Tulsa, Oklahoma
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 24, 2006 - 11:15 AM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi Tom,

I thought maybe c supports multi dimentional arrays, that said, yep, your thinking is right on track with mine, Bascom supports (one Dim.)array index increment/decrement as I checked this a few days ago.
This is one heck of a friendly/quality forum that has substance.

Keep well Tom and Others
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
darren
PostPosted: Oct 26, 2006 - 04:33 PM
Wannabe


Joined: Nov 04, 2004
Posts: 51
Location: N.Wales U.K.

Hi All,

For those interested, heres a reasonable link to PID control, dont let the equations scare you.


http://www.flightgear.org/Docs/XMLAutop ... 0000000000

Best Regards
Darren
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits