0% found this document useful (0 votes)
55 views4 pages

Te Controller v1-6

Program to fermentation cooling project.

Uploaded by

heintze3
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views4 pages

Te Controller v1-6

Program to fermentation cooling project.

Uploaded by

heintze3
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

' File: TE_Controller_v1-6

' Author: AHeintzelman


' Date: 2/22/09
' Description: This program reads the temperature from a
' LM34 analog sensor and turns on a "peltier cooler"
' which is idealized as an LED on once the temperature
' gets too warm. It turns it off when it gets too cold
' as well. The actual temp is compared to the setpoint.
'
' This program also checks to see if the "set temperature" button
' is pressed and flashes an LED to let you know you are entering
' the "set temperature" function. The LED remains lit while in
' the function. Upon exiting the function, the LED flashes again
' and then turns off. Within the temperature set function, the
program
' reads the potentiometer value and converts it into a temperature
' set point in Fahrenheit.
'
' This program displays the set temperature and TEC temperature
' on an 7-segment LED display.
'
' This program uses PWM to control a TEC idealized as an LED with
' a proportional control technique.
'
' Dual LED display added.

'-----[ Definitions ]-----

Symbol SetTempLED = 1 ' LED that flashes upon entering set temp
function
Symbol PowerLED = 2 ' LED that shows power is on to system
Symbol SetTempButton = pin0 ' set temp button to enter set temp function

Symbol TEC_OnOff_LED = 0 ' LED that shows when TEC is on or off

Symbol AD0_Val = W0 ' temp read variables


Symbol Sum = W1 ' sum of ADCread values
Symbol TE_Temp_10 = W1 '
Symbol N = B4 ' number of values to attain to create TEC temp
average
Symbol TE_Temp = B5 '

Symbol AD1_Val = W0 ' temp set variables


Symbol SetPoint_10 = W1 ' set point temperature from pot x 10
Symbol TempSetPoint = B6 ' set point temperature

let TempSetPoint = 80 ' initial startup value for setpoint


temperature

high PowerLED ' power-on LED

' ****** 7 segment display LED variables and set up


Symbol DispEnable = 7 ' display driver enable pin
Symbol DispClock = 5 ' display driver clock pin
Symbol DispData = 6 ' display driver data pin
Symbol DispDig10 = b7 ' tens place of the temperature to display
Symbol DispDig1 = b8 ' ones place of the temperature to display
gosub DispConfigure ' initialize and configure LED display

' ****** proportional control variables


Symbol PropError = b10 ' proportional error
Symbol PropGain = 25 ' proportional gain (should be ~1/8 of PWMMax)
Symbol SignBit = b11 ' sign of proportional error (0 = pos, 1 = neg)
Symbol DutyCycle = b12 ' duty cycle = PropGain * PropError MAX PWMMax
Symbol PWMPeriod = 49 ' PWM wavelength or period
Symbol PWMMax = b13 ' Maximum for the duty cycle, this is 100% duty
Symbol TEC_PWM_LED = 1 ' PWM1 (pin12), illuminates according to
voltage supplied

PWMMax = PWMPeriod + 1 * 4 ' PWM Max calculation

'-----[ Main Routine ]-----

Main:

low SetTempLED
high DispEnable
low DispClock

Sum = 0
For N = 1 to 32 ' sum 32 readings
ReadADC10 0, AD0_Val
Sum = Sum + AD0_Val
Next

AD0_Val = Sum / 32 ' calculate the average

TE_Temp_10 = AD0_Val * 4 ' y = 4.88x


TE_Temp_10 = AD0_Val * 8 / 10 + TE_Temp_10
TE_Temp_10 = AD0_Val * 8 / 100 + TE_Temp_10

TE_Temp = TE_Temp_10 / 10 ' TE temp


debug TE_Temp

DispDig10 = TE_Temp / 10
DispDig1 = TE_Temp % 10

gosub DispTemp

if SetTempButton = 0 then LED_Flash

PropError = TE_Temp - TempSetPoint


SignBit = PropError / 128

if SignBit = 0 then gosub PropControl


if SignBit = 1 then gosub PropControlOff

if TE_Temp < TempSetPoint Then TurnOffPeltier


if TE_Temp > TempSetPoint Then TurnOnPeltier

goto Main
'-----[ Subroutines ]-----
PropControl:
DutyCycle = PropGain * PropError MAX PWMMax
pwmout TEC_PWM_LED, PWMPeriod, DutyCycle
return

PropControlOff:
pwmout TEC_PWM_LED, 0, DutyCycle
return

TurnOffPeltier:
Low TEC_OnOff_LED
GoTo Main

TurnOnPeltier:
High TEC_OnOff_LED
GoTo Main

LED_Flash:
For N = 1 to 7
toggle SetTempLED
pause 250
Next
if SetTempButton = 0 then Set_Temp
goto Main

Set_Temp:
pause 1000
do
readADC10 1,AD1_Val
debug AD1_Val
if SetTempButton = 0 then LED_Flash

SetPoint_10 = AD1_Val * 3 / 10 ' y = 0.0392x + 40


SetPoint_10 = AD1_Val * 9 / 100 + SetPoint_10
SetPoint_10 = AD1_Val * 2 / 1000 + SetPoint_10 + 400 ' Temp set range
from 40 to 80 deg F

TempSetPoint = SetPoint_10 / 10

DispDig10 = TempSetPoint / 10
DispDig1 = TempSetPoint % 10

gosub DispTemp
loop

DispConfigure:
low DispEnable
spiout DispClock, DispData, 1, (%00000001)
high DispEnable
return

DispTemp:
low DispEnable
spiout DispClock, DispData, 1, (%00000000,DispDig1,DispDig10)
high DispEnable
return

You might also like