DIY PID controller - beginner Arduino project - Page 2 - Home Brew Forums

 Home Brew Forums > DIY PID controller - beginner Arduino project

05-29-2012, 12:36 AM   #11
bolts
Recipes

Sep 2009
Portland, OR
Posts: 306
Liked 8 Times on 7 Posts

If you decide to get PCBs made, take a look at http://dorkbotpdx.org/wiki/pcb_order. He's local (to me) and the boards are quite good. Prices are good for hobby sized batches too.

05-29-2012, 06:19 PM   #12
crane
Recipes

Sep 2011
San Diego, CA
Posts: 686
Liked 95 Times on 80 Posts

One way to implement this would be to manually implement all 3 outputs with a timer ISR. Set up the timer at 100Hz for a 1 second PWM period. If you wanted a 3 second PWM period then go with 33Hz. Have a function that gets triggered from the ISR. In this function do the following:

count++; // increment our counter. There are 100 counts per period.

// check to see if we are at the end of the PWM cycle
if (count >= 100)
{
// we are at the end so reset everything
count = 0;
output1 = 0;
output2 = 0;
output3 = 0;

// enable the highest priority output that is on
if (duty_cycle1 > 0)
{
output1 = 1;
}
elseif (duty_cycle2 > 0)
{
output2 = 1;
}
elseif (duty_cycle3 > 0)
{
output3 = 1;
}
}
else // we are not at the end of the period
{
//check to see if we are at the end of the first duty cycle
if (count == duty_cycle1)
{
output1 = 0;
// check to see which output to turn on next
if (duty_cycle2 > 0)
{
output2 = 1;
}
elseif (duty_cycle3 > 0)
{
output3 = 1;
}
}

//check to see if we are at the end of the second duty cycle
if (count == (duty_cycle1 + duty_cycle2))
{
output2 = 0;
if (duty_cycle3 > 0)
{
output3 = 1;
}
}

//check to see if we are at the end of the third duty cycle
if (count == (duty_cycle1 + duty_cycle2 + duty_cycle3))
{
output3 = 0;
}
}

There are probably some bugs that need to be ironed out here as I am just coding this on the fly. This assumes that the duty_cycle variables represent a throttle percentage of 0 to 100.

You will probably run into a number of corner cases if you try to change any of the duty cycles in the middle of the period. You could get around this a couple of ways. 1 - pull out the code in the first if statement and create a separate function for it. Call this function inside the if statement as well as any time you change the duty cycle. 2 - have 2 sets of duty cycle variables. One set that is changed by external PID algorithms and one that is only changed by this function. At the end of each period when you reset the outputs assign the values of the external duty cycles to the internal duty cycles.

Either solutions would be easy to implement. The first one might not work very well if you change the duty cycles often.

I am not a SW or FW engineer so there is probably a more elegant way to implement this.

 #\$&* editor won't preserve my indentations. Copy and paste to a c editor like notepad++ and you can add the indentations back in to make it readable

06-02-2012, 11:17 PM   #13
chuckjaxfl
Recipes

Feb 2010
Jacksonville, FL
Posts: 327
Liked 22 Times on 14 Posts

I trying to auto tune this keg today.

06-03-2012, 01:40 AM   #14
jpalarchio
Recipes

Jan 2009
Holly, MI
Posts: 562
Liked 50 Times on 41 Posts

Quote:
 Originally Posted by crane #\$&* editor won't preserve my indentations. Copy and paste to a c editor like notepad++ and you can add the indentations back in to make it readable
FYI- You can wrap the code in the [ code ] bracket (# icon in the editor) and it works better

06-03-2012, 01:16 PM   #15
carlisle_bob
Recipes

Apr 2012
Carlisle, PA
Posts: 1,206
Liked 29 Times on 28 Posts

Hi

There are a *lot* of places that will do simple PC boards cheap. Some will do overnight processing, others do longer lead for a bit less money.

Bob

06-04-2012, 01:58 AM   #16
chuckjaxfl
Recipes

Feb 2010
Jacksonville, FL
Posts: 327
Liked 22 Times on 14 Posts

This project was going pretty well, until this weekend. I'm having a bear of a time with the autotune library for Arduino.

At this point, I'm receptive to any tips you guys have.

09-05-2012, 10:01 AM   #17
Bonj
Recipes

Jul 2007
Ipswich, QLD, AU
Posts: 10

Sorry to dredge up an old thread, but I am currently fighting with the arduino autotune library and wondered if you made any headway on suitable values for the aTuneStep and aTuneStartValue parameters?

I have built myself a HERMS controller using a custom designed arduino clone and another custom interface board. You may view the build log here. There is also a link to my source code (prior to my attempt to add the auto tune function), and a youtube video of operation.

I'd love some pointers on getting in the ballpark for the aforementioned variables. I'm closing in myself by trial and error, but if someone else has done the hard work already, I'd sure love to benefit from it.
__________________
Mediocrity - It takes a lot less time, and most people won't notice the difference until it's too late.

Hit and Miss Brewery - Ipswich Queensland

On Tap: null
Conditioning: null
In no-chill: null
In Primary: null
In Planning: Vienna / Helles lagery type thing with tettnanger

09-06-2012, 04:36 AM   #18
chuckjaxfl
Recipes

Feb 2010
Jacksonville, FL
Posts: 327
Liked 22 Times on 14 Posts

I have not been out in the garage in forever. I think those pics from June were the last day I was out there. Sorry I'm not more help.

I'm hoping to get back out there again soon and, if I have any success with the autotuner, I'll post it here.

09-06-2012, 04:40 AM   #19
Bonj
Recipes

Jul 2007
Ipswich, QLD, AU
Posts: 10

Well, I've been experimenting with it all day, and I finally have it returning some results. The results aren't particularly useful (5.2°C overshoot on a 10°C ramp, compared to a 0.3°C overshoot from my manual tuning), but getting any results at all is still progress!

I'm testing the unit in an electric jug, so not the easiest rig to tune, but all I have until the actual HEX is finished.
__________________
Mediocrity - It takes a lot less time, and most people won't notice the difference until it's too late.

Hit and Miss Brewery - Ipswich Queensland

On Tap: null
Conditioning: null
In no-chill: null
In Primary: null
In Planning: Vienna / Helles lagery type thing with tettnanger

09-15-2012, 09:03 PM   #20
chuckjaxfl
Recipes

Feb 2010
Jacksonville, FL
Posts: 327
Liked 22 Times on 14 Posts

Well, I am making another attempt at it today. I will let everyone know if I come up with anything useful.

I am really starting to lose my faith in the usefulness of PID for this project. I am starting to think I might just be better off writing my own control script from scratch.