Picaxe or Arduino for PID coffee roaster controller?

greencardigan

Senior Member
Hello,

I'm planning to build another PID controller for a new hot air coffee roaster I have just built.

I'm wondering if I would be better off using an Arduino for this application? Would they make the PID math calcs easier?

Unfortunately I know very little about Arduino and their math capability.

Any thoughts?
 

ciseco

Senior Member
And maybe the arduino forum would say go ask the picaxe forum ;)

It's down to your choice GC, the arduino has better maths but a worse IDE. Want the best of both, I'd suggest you try downloading Swordfish, can do everything an Ardy compiler can but it's in a more friendly BASIC syntax.

The picaxe is more than man for it if you can put up with the maths, Jeremy Leach even posted some maths routines somewhere, this might help you along a touch.
 

Dippy

Moderator
Yes it would make your maths easier and so would a PIC compiler.

But can you afford to spend over a tenner on this project?

Do you really need some mathematically fancy PID for a blooming roaster?
A smart thermostat would be fine surely , and you could easily do a simple change by half the difference kid-pid control. No overshoot and asymptotic appraoch.
 

BeanieBots

Moderator
I too would question the need for PID with a toaster.
After you have done the maths (with pen and paper) you will more than likely find that P=infinity, I = 0 and D = 0.
With those co-efficients, the PICAXE maths will bemore than up for the task with no more than a few lines of code.

As for Arduino vs PICAXE for PID, the quickest easiest solution (and cheaper than learning a new micro) would be .... well... um... a PID contoller:rolleyes:
 

greencardigan

Senior Member
Thanks for the quick responses

Do you really need some mathematically fancy PID for a blooming roaster?
A smart thermostat would be fine surely , and you could easily do a simple change by half the difference kid-pid control. No overshoot and asymptotic appraoch.
My usual approach is 'cheaper is better' but I struggled a bit last time with the picaxe math. This time I'm playing with 4.8kW of heating and would like some fairly tight control.

And here's a interesting quote from my 1st PID thread from a few years back :p

One question I really must ask re PID: Is this not a little OTT to be looking at some convoluted PID when all you need is a posh thermostat? If you can work out the heating-up-speed-after applying power (to pre-empt overheating) you could make a semi-PID. If it's for educational purposes then fire away with the Full Monty.
 

Dippy

Moderator
Well, I'm almost consistent :D

I see so many occasions on this Forum where OTTisationability is rampant and Mountainsoutofmoehillsification is common. :rolleyes:


I'm still annoyed by the people who wrote the firmware for my Hotpoint washing machine. No damned imagination.
 

greencardigan

Senior Member
A smart thermostat might be suitable but I assumed others were using PID for coffee roasters for a reason. It requires closely following a preset temp profile with no decreases in temp.
 

Dippy

Moderator
I've never roasted my beans so I merely follow what you say. :)

Approach the project correctly.
Consider what you need to achieve. (Accuracy, time , tolerance etc.)
Then consider how you can go about it.

Start planning it out in plain English and then consider how to code it up.
But starting off with diving in to some possibly unneccessarily over-rigorous maths is not the way to approach this.

What's stopping you writing some code with a damped feedback to follow a profile in a lookup table?
You'll have physical delays in the system (conductivity , power heat distribution and heat capacity) and you can introduce delays and feedback delays in your code. Some of this can only be discovered with the suck-it-and-see approach.


"...others were using PID..." - I'm sure we've all seen examples of products where the designers and technical authors have been a little glamorous with the accuracy of the descriptions of the guts.... ;)
 

ciseco

Senior Member
@Dippy

"But can you afford to spend over a tenner on this project?" SF lite is free, a suitable board + 25K20 or 22, including VAT and P&P is certainly less than a tenner, come to think of it, it's probably less for those bits delivered than it is to buy a single 28x2, this assumption used to be true, isn't any longer.

I second the lookup table, unless you put in radically different weights of beans.

@beanie "and cheaper than learning a new micro", sorry, wildly disagree, especially now that the later axe's have more PIC orientated port/pin numbering system, the similarities are even closer. Basic is Basic, the 18F25K22 that is now the cross voltage 28x2 as a bare PIC is under £2 (free if you ask for samples), there's 3 different basic's that have free downloads from the UK alone, looking further afield I can think of 5 more, I bet with a few hours on google you'd be well into double digits. If you want to program a bare pic with a picaxe cable there's stuff "out there" that'll do it so you needn't even buy a hardware programmer.

Miles
 

ciseco

Senior Member
"Do you really need some mathematically fancy PID for a blooming roaster?
"

Dip, your wife sounds "open minded" :D
 

Dippy

Moderator
When I was on about cost I was referring to the 'ardweeny. :)
I wouldn't waste my time with one personally.
I'd get a dsPIC or PIC32, the full blown HiTech compiler and some dev boards.

PICs are cheap as chips I hear. I've never bought one so I'm only going on what someone down the pub said.:rolleyes:

This "suitable board" ... where can we buy one? Who makes it? ;);)
 

ciseco

Senior Member
Dip, you need to get out more, there's a UK source for an ardweenie compatible xino for around £7 + P&P

"This "suitable board" ... where can we buy one? Who makes it?"

I couldn't possibly confirm or deny such things, you ever loyal servant "CISECO" :rolleyes:
 

hippy

Ex-Staff (retired)
Let's not go too far in the 'this is is better than a PICAXE' stakes and potentially suggesting people are better off elsewhere. Fair comments and recognition that there are alternatives and some solutions may be better than another are one thing but let's not over-step the boundaries and get into promotion of competitors.
 

ciseco

Senior Member
:)

You misunderstand, I was saying if you want more options than the 8 PIC basics I can remember off the top of my head it'll take some time on google. This is because the word PIC is rather generic in english.

If I stepped into "my compilers better than yours" then I need a spanking as I hate this type of rhetoric, I was merely trying to point out that there's options.

I like the PICAXE, it has it's place and it's great value. What it isn't is the answer to everything or the least cost option or the easiest to learn. These are illusions I've heard many times on the forum and they should stop it's misleading people.

The virtues of the PICAXE should be extolled not scare tactics, it's a strong enough product to carve it's own niche.

Miles
 

ciseco

Senior Member
@hippy

I just re-read, I don't think I stepped into "this is better than that" in any way at all. The question was about the lack of anything but integer maths in a PICAXE, I think the answers in that context were valid.

The subject of cost I didn't introduce, in my opinion it was stated in a way which could make the reader believe something untrue.

The subject of ease I also didnt introduce, in my opinion it was stated in a way which also could make the reader believe something untrue.

Miles
 

krypton_john

Senior Member
Would temperature be likely to overshoot anyway? Where's the inertia?

I'm sure your regular kitchen oven has no PID control and has a simple thermostat - do they tend to overshoot?

Cheers
JohnO
 

greencardigan

Senior Member
Yes, it will overshoot if using a standard thermostat setup. The environment temperature will remain above the bean temp for a while after the heating elements turn off.

Also complicated by the coffee beans undergoing exothermic reactions and producing their own heat at certain stages.
 

hippy

Ex-Staff (retired)
I'm no control system expert so a question I have is - would a PID system pre-emptively handle over-shoot ? I was of the understanding it was more an 'error correction' or 'tracking' feedback system at or after the event.

I guess any 'target value' could be set lower than required so it's right when catering for over-shoot but then you'd have to know what over-shoot there would be and I wouldn't have thought that was consistent, depends on number of beans, type, and other factors.

Maybe PID systems are more complicated / powerful than I understood.
 

hippy

Ex-Staff (retired)
Missed earlier ...
Is there any possibility that Picaxe will have enhanced math ability in the future?
Everything is possible, but there's no guarantee of it. It perhaps depends on what enhanced math capability is considered to be, and how that could be fitted in with what a PICAXE currently is.
 

Andrew Cowan

Senior Member
How about Cubic equation solving including complex roots?

PID will overshoot far less than a simple on/off system, as it slows the rate of increase as the temperature approaches the target. However, it will still overshoot - especially if it is programmed for a sharp temperature profile, rather than a slower, more rounded profile.

Andrew
 

greencardigan

Senior Member
Missed earlier ...


Everything is possible, but there's no guarantee of it. It perhaps depends on what enhanced math capability is considered to be, and how that could be fitted in with what a PICAXE currently is.
Well, it's the positive integer limitation that stops me sleeping. But I don't really know what other microcontroller systems are capable of either. Picaxe is the only micros I've experienced (not counting the wasted hours I spent stumbling through 500 pages of PIC assembly language manual/tutorial. :mad:)

I always thought a properly tuned PID would not overshoot but approach the setpoint asymptotically. It should minimize it at least.

Andrew, for a few moments I thought you were suggesting I use cubic equations and complex roots to help me roast coffee. :eek: What about laplace transform functions?
 

hippy

Ex-Staff (retired)
Most micros were 8-bit, integer math but that has grown to include 16-bit or 32-bit and with signed number support.

It's often the case though that it's the compilers which hide the reality and present the impression chips are more capable than they are. You can do the same on PICAXE but you have to do it yourself and it's not so hidden.

Floating point maths usually has high overheads and for most micros the algorithms will therefore be designed for integer numbers which can often work just as well. Apart from being an interpreter design, PICAXE 16-bit integer maths is really no less capable than any other.
 

BeanieBots

Moderator
Would temperature be likely to overshoot anyway? Where's the inertia?

I'm sure your regular kitchen oven has no PID control and has a simple thermostat - do they tend to overshoot?

Cheers
JohnO
The 'inertia' is the time lag between heater and object being heated.
Domestic ovens overshoot dramatically. That is why most recipes state "place in a pre-heated oven". It's not so much so that temperature has been reached but that excessive temperature will not be experienced.

@Andrew & Hippy.
A PID temperature controller can be tuned for ZERO overshoot.

PID explained (again).
P = Proportional. This is the amount of power applied which is proportionall to how far away you are from the desired setpoint.

I = Integral. This is the sum (over time) of the errors. That is, a gradual increas in power. The amount of each increase being proportional to how far you are away from setpoint. This term keeps increasing all the time there is an error and is the part which eventually ensures ZERO error.

D=Derivative. This is also a time related term. It is rate at which you are approaching the setpoint. It works AGAINST the other two terms. If you are approaching setpoint quickly, this term will reduce the power to slow things down. It makes the system stable and is used to prevent overshoot. It is often left out of many controllers where overshoot can be tollerated.

A simple "on if it's under" and "off if it's over" type controller is a PID controller where P=infinity, I=zero and D=zero.

A controller which puts out an amount of power proportional to how far off is the next step up. However, this type of controller will NEVER quite reach the required setpoint because when the error comes down to zero, so does the power.

An integral only controller keeps adding a little more power until setpoint is reached. This type of controller will ALWAYS OVERSHOOT because the power will not be reduced until it HAS overshot.

I am not aware of any derivative only controllers and cannot think of any use for one. The closest I can think of is a car shock absorber. The derivative term's function is to resist change. ie dampen. Even in that example, it works together with the suspension which is a proportional control.

Even a simple bi-metallic type control with several degrees of hysterisis can be made to control to within less than a dgree with a simple mod. It's called an "accellerator resistor" and is used by many domestic heating systems to make them look like PID controllers.

The "accellerator resistor" heats up the bi-metallic sensor making it trip early. If the environment is cold, it will cool down quickly and come back on. If it's warm, it will stay off longer. The result is a much closer and finer temperature control than can be achieved with the sensor alone.

Hope this explains PID and simple controls for those interested.
 

hippy

Ex-Staff (retired)
An integral only controller keeps adding a little more power until setpoint is reached. This type of controller will ALWAYS OVERSHOOT because the power will not be reduced until it HAS overshot.
I think it's after this where I lose understanding. I'm happy with it up to that point, and adding D pulls that back, prevents the overshoot, but what I perhaps cannot understand is that D is based upon what has been which isn't necessarily what will happen from that point on.

For coffee making, you don't know what type of exothermic reaction or how much will occur until it starts to happen.
 

BeanieBots

Moderator
EDIT @post #29

Not quite.
D does not (and cannot) 'pull it back'.
It prevents it from getting there.
As such, it attempts to predict what WILL happen based on what HAS happened. Over a short period of time, very few systems will behave very unpredictably.
This is where 'tuning' comes in and why it's sometimes called a 'black art'.
The control analyst (PID tuner) will set the derivative such that setpoint cannot be approached at a speed that is likely to cause overshoot. More often than not, this is determined by experimentation but for simple cases it can be calculated.
If there are genuinely unknown things at play, then you can either be very cautious (at the expense of long run up times) or you add extra terms into your PID loop. A common one being called 'feed-forward'.
Eg. you might have a very critical temperature that needs to ramp up.
Rather than let the PID loop do all the hard work. The heater is ramped up at close to what is required from experimentation, leaving the PID loop to just make fine adjustments.
This can be further refined. For example, the mains voltage might vary. Again, instead of letting your PID loop do the work, simply add in the amount of extra power required to compensate for a dip in mains voltage based on the monitored value and a simple calculation .

EDIT:
As for endo &/or exo-thermic events. In something simple like coffee bean roasting, it will be the same reaction every time. If weight changes each time and has a large effect, then it needs to be entered into the controller prior to each start. There is very little out there that is genuinely 'unknown'. It's simply that many people just dont' take it into account.
 
Last edited:

greencardigan

Senior Member
And all of this for a cup of coffee!
Says he as a palate-limited coffee-drinker.
All this and more! :p

Just wait until I ask for help building my coffee fruit processor contraption.


While we are discussing PID control I have a question.

What kind of control is best if I've already reached the desired setpoint but the setpoint keeps increasing by a certain amount every second. i.e. I want my bean temps to ramp up at a defined rate. Would I still require P I and D? I'm thinking D would not provide much benefit in this case?
 

BeanieBots

Moderator
You should keep with the PID control but add in 'feedforward' as described earlier.
The derivative is just as important once setpoint is reached. In steady state, it prevents any disturbances (a gust of wind or power surge) from having a dramatic effect.
 

sniper887

Member
Just curious: for this roaster project will relays be used to control the heating elements or some other method, like rectifying the power and pulse width modulating with logic-level MOSFETs? Seems like the latter route might lend itself better to PID control. I've used a fairly simple code to regulate current through an LED, where on start up the pwm duty cycle is low and increments itself up until sensed current is slightly higher than setpoint, then, decrements the pwm duty cycle. If sensed current is lower than setpoint, then the code increments the duty cycle. That code would cause overshoots in the roaster project, but of course can be modified.
 

greencardigan

Senior Member
My old roaster used a SSR to pulse power to the heater. Sort if very slow PWM at 1Hz.

With the new roaster I might use the PID to control the blower speed instead of the heaters.

The other option I have been considering is some triac phase dimmers the same as I am using with the blowers.
 
Top