Spike Brewing 12.5 Conical Fermenter Giveaway - Enter Now!

Home Brew Forums > Home Brewing Beer > DIY Projects > ATtiny84 PID

Reply
 
LinkBack Thread Tools
Old 04-30-2013, 11:32 PM   #1
chuckjaxfl
Feedback Score: 1 reviews
Recipes 
 
Join Date: Feb 2010
Location: Jacksonville, FL
Posts: 327
Liked 18 Times on 11 Posts
Likes Given: 23

Default ATtiny84 PID

Here's another little project I did awhile back, without any specific end use in mind yet.



image-2977205875.jpg

__________________
chuckjaxfl is offline
 
Reply With Quote Quick reply to this message
Old 04-30-2013, 11:34 PM   #2
chuckjaxfl
Feedback Score: 1 reviews
Recipes 
 
Join Date: Feb 2010
Location: Jacksonville, FL
Posts: 327
Liked 18 Times on 11 Posts
Likes Given: 23

Default

Photos

image-855306014.jpg   image-1200050153.jpg   image-574624420.jpg  
__________________
chuckjaxfl is offline
 
Reply With Quote Quick reply to this message
Old 04-30-2013, 11:41 PM   #3
chuckjaxfl
Feedback Score: 1 reviews
Recipes 
 
Join Date: Feb 2010
Location: Jacksonville, FL
Posts: 327
Liked 18 Times on 11 Posts
Likes Given: 23

Default

Since the LCD has two rows of 8 and the chip has space for two rows of between the pins, I drew the board so that the pins from the chip would mount on the opposite side, and straddle, the pins from the LCD.

It's running the same PID library that runs on the ATmega, and sensing is via a DS18B20.

__________________
chuckjaxfl is offline
 
Reply With Quote Quick reply to this message
Old 05-01-2013, 02:14 AM   #4
alien
Feedback Score: 1 reviews
Recipes 
 
Join Date: Apr 2012
Location: Philadelphia, PA
Posts: 1,234
Liked 65 Times on 58 Posts
Likes Given: 61

Default

how do you communicate with it?

alien is offline
 
Reply With Quote Quick reply to this message
Old 05-01-2013, 02:21 AM   #5
chuckjaxfl
Feedback Score: 1 reviews
Recipes 
 
Join Date: Feb 2010
Location: Jacksonville, FL
Posts: 327
Liked 18 Times on 11 Posts
Likes Given: 23

Default

To program it? Via the six-pin connector, the ribbon cable.
In use? Two inputs: setpoint up, setpoint down.

I keep messing with the code, and haven't settled on a 'final' version yet. Right now, it takes 7,800 of 8,192 available. Here it is at the moment, it does work, but I'm open to critiques and tips to tighten it up.



Code:
#include <PID_v1.h>
#include <OneWire.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>

const int TEMP_PIN=2;
const int ssrPin=0;
const int upPin=8;
const int downPin=3;
//const int Setpoint_address=0;
const int SvHiByteAddress=10;
const int SvLoByteAddress=11;
int TempF100;

const int WindowSize = 1000;
double Setpoint, Input, Output;
unsigned long EEPROMTime, windowStartTime, markTime, displayTime;

LiquidCrystal lcd(10,1,9,4,7,5,6);
OneWire ds(TEMP_PIN);
PID myPID(&Input, &Output, &Setpoint,120,0.05,1.0, DIRECT);


void setup()
{
  lcd.begin(8,2);
  pinMode(ssrPin,OUTPUT);
  pinMode(upPin,INPUT_PULLUP);
  pinMode(downPin,INPUT_PULLUP);
  int SetpointAsInt = word(EEPROM.read(SvHiByteAddress),EEPROM.read(SvLoByteAddress));
  Setpoint = SetpointAsInt;
  myPID.SetOutputLimits(0, WindowSize);
  myPID.SetMode(AUTOMATIC);
}


void loop()
{
  getTemp();
  displayLCD();
  getOutput();
  controlSSR();
  readButtons();
  saveSetpoint(); 
}



void getTemp()
{
  byte data[12];
  ds.reset();
  ds.skip();
  ds.write(0x44,1);
  byte present = ds.reset();
  ds.skip();  
  ds.write(0xBE); 
  for (int i = 0; i < 9; i++) 
  { 
    data[i] = ds.read();
  }
  ds.reset_search();
  byte MSB = data[1];
  byte LSB = data[0];
  int TempR = ((MSB << 8) | LSB);
  Input = TempR;
}


void saveSetpoint()
{
  if (millis()>EEPROMTime)
  { 
    int SetpointAsInt=(int)Setpoint;
    byte SetpointLoByte=lowByte(SetpointAsInt);
    if (EEPROM.read(SvLoByteAddress)!=SetpointLoByte) EEPROM.write(SvLoByteAddress,SetpointLoByte);
    byte SetpointHiByte=highByte(SetpointAsInt); 
    if (EEPROM.read(SvHiByteAddress)!=SetpointHiByte) EEPROM.write(SvHiByteAddress,SetpointHiByte);
    EEPROMTime+=1000; 
  }
}


void controlSSR()
{
  if ((millis()-markTime)>WindowSize) markTime=millis();
  if ((millis()-markTime)<Output) digitalWrite(ssrPin,HIGH);
  else digitalWrite(ssrPin,LOW);
}



void displayLCD()
{
  lcd.setCursor(0,0);
  TempF100=((Setpoint*90/8)+3200);
  printtemp();

  lcd.setCursor(0,1);
  TempF100=((Input*90/8)+3200);
  printtemp();

}

void printtemp()  
  {
  byte TempF_whole = TempF100 / 100;
  byte TempF_dec   = TempF100 % 100;
  if (TempF_whole<100) lcd.print(" "); 
  lcd.print(TempF_whole); 
  lcd.print("."); 
  if (TempF_dec<10) lcd.print("0"); 
  lcd.print(TempF_dec);
  lcd.print(char(223));  
  lcd.print("F");
  }


void getOutput()
{
  int TempError=abs(Setpoint-Input);
  if (TempError>64) myPID.SetTunings(120,0.0,0.0);    
  else myPID.SetTunings(60,0.05,0.0);    
  myPID.Compute();
}


void readButtons()
{
  if (digitalRead(upPin)==LOW) 
  {
    Setpoint++; 
    delay(5);
  }

  if (digitalRead(downPin)==LOW) 
  {
    Setpoint--; 
    delay(5);
  }
}
__________________
chuckjaxfl is offline
 
Reply With Quote Quick reply to this message
Old 05-01-2013, 04:19 AM   #6
alien
Feedback Score: 1 reviews
Recipes 
 
Join Date: Apr 2012
Location: Philadelphia, PA
Posts: 1,234
Liked 65 Times on 58 Posts
Likes Given: 61

Default

where are the inputs?

alien is offline
 
Reply With Quote Quick reply to this message
Old 05-01-2013, 04:25 AM   #7
chuckjaxfl
Feedback Score: 1 reviews
Recipes 
 
Join Date: Feb 2010
Location: Jacksonville, FL
Posts: 327
Liked 18 Times on 11 Posts
Likes Given: 23

Default

The three pins on the left on the back. The bottom one goes to ground, the middle on to pin 3 on the chip (downPin) and the top goes to pin 8 (upPin).

They are the three pins next to the blank spots, where I will install the vreg and filter caps when I hook this up to 12v instead of running it off of the programmer.

__________________
chuckjaxfl is offline
 
Reply With Quote Quick reply to this message
Old 05-01-2013, 02:21 PM   #8
alien
Feedback Score: 1 reviews
Recipes 
 
Join Date: Apr 2012
Location: Philadelphia, PA
Posts: 1,234
Liked 65 Times on 58 Posts
Likes Given: 61

Default

I see, I was a bit confused because I couldn't see any buttons on the front near the LCD display, but the way you have it makes sense for attaching connectors to remote buttons.

__________________
Magic Smoke brewhouse and grill

Arduino PID controller - Automatic Smoker - Cooler MLT - Counterflow Chiller - SSR demo - PWM timer - Folding Brew Table
alien is offline
 
Reply With Quote Quick reply to this message
Reply


Quick Reply
Message:
Options
Thread Tools