MrDEB
Well-Known Member
when it comes to math I was the last person in line but here is my present code for a PIC controlled soldering iron.
The temperature sensor is an RTD type.
Not having an accurate temperature measurement I found that solder melts at aprox 157C.
My voltage readings at (see X on schematic, Port 1 is my RTD sensor)
Room temp = 28.4mv
at solder melt = 52-53mv
Ignore the case section as I plan to put values for deg_R and deg_S AFTER I find out what voltage per mv or C temp is.
Contemplating inserting another ADC buggy section for the sensor input.
My Vsensor at rt = 100 at melt = 200-220(it jumps from 200 to 220)
any guidance would be appreciated
When I get this project done I will post full details
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 10/6/2011 *
* Version : 1.0 *
* Notes :compute voltage to temperature. Start with sensor at 50ohms.
* : 180-200 ohms melts solder *
* : *
*****************************************************************************
}
Device = 18F4520
Clock = 8
Config OSC = INTIO67
// some LCD options...
//#option LCD_DATA = PORTD.4 // Assign the LCD connections
//#option LCD_EN = PORTD.3 //
//#option LCD_RS = PORTD.2 //
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// #option LCD_INIT_DELAY =100
// import LCD library...
// uses LCD and AD libraries...
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
Include "InternalOscillator.bas"
Include "math.bas"
Dim ADVal As Word
Dim LED_g As PORTC.0 // GREEN LED tip desired temp
Dim LED_r As PORTC.1 // HEATER ON
Dim opti As PORTE.0
Dim Vref As Integer //want whole numbers
Dim Vsensor As Integer
Dim deg_S As Word //Sensor variable
Dim deg_R As Word // Vref variable
Dim gate As PORTC.6 // pin 25 controls mosfet gate
Dim beep As PORTC.5 //pin 24 beeper sound controlled by counter
Dim iron_sense As PORTC.4 // check iron sense switch pin 23
Dim counter As Word
Dim count_down As Integer // count down timer
// Read the AD ports...
Function REF_V() As Word
result = (ADC.Read(1))*375/1024 //9 to 203 ADC.Read rsults
End Function
Function sensor() As Word
result = (ADC.Read(0))*20 //14 (RT) to 37 (melt)
End Function
// COPY / PASTED from Tetris code. The ADC readings were jumping out of order
// I found the ADC.ReadMedian routine was buggy with the 18F4520. Instead of debugging it
// I've created my own routine to do the job. Also, the program below takes 3 samples instead
// of 64 (as performed by ADC.ReadMedian).
Function ReadMedian2(pChannel As Byte) As Word
// define local variables
Dim Results(3), tmpWord As Word, i, ReSort As Byte
// make a number of samples
For i = 0 To Bound(Results)
Results(i) = ADC.Read(pChannel)
Next
Repeat
ReSort = 0
For i = 0 To Bound(Results)-1
If Results(i) > Results(i+1) Then
tmpWord = Results(i)
Results(i) = Results(i+1)
Results(i+1) = tmpWord
ReSort = 1
EndIf
Next
Until ReSort = 0
Result = Results(Bound(Results)/2)
End Function
//###################################################################
// Start Of Program...
//###################################################################
Input(PORTA.0) // temp ref voltage desired temp
Input(PORTA.1) // tip sensor
Low (LED_g) //pin 15 set lEDs OFF
Low (LED_r) //pin 16
High(opti)
Output(PORTC.6)
Output(PORTC.5)
Input (PORTC.4)
count_down=0
gate = 1
ADCON1 = %10000000 //set up ADC regesters
ADCON0.7 = 1
ADCON0.6 = 1
ADC.RightJustify = true
DelayMS (150)
LCD.Cls // clear LCD
//lcd.write(1,1,"temp")
//####################################################################
// main program loop.. .
//###################################################################
// call function REF_V() and assign the result to word variable 'Vref'
//#################################
// count down timer
//###############################
//#######################################
//voltage reference look up table
//#######################################
//#######################################
// sensor look up table
//#########################################
// Select Vsensor
// call function REF_V() and assign the result to word variable 'Vref'
While true
Vref= REF_V() //Reference voltage
Vsensor = sensor() // tip sensor
//#######################################
//voltage reference look up table
//#######################################
Select Vref //41-56 range for Vref
Case < 250 deg_R =21
Case < 260 deg_R =101
Case < 270 deg_R =157
Case < 300 deg_R =350
Case < 350 deg_R =400
Case < 400 deg_R =450
Case < 450 deg_R =480
{
Case < 16 deg_R =161
Case < 17 deg_R =174
Case < 18 deg_R =187
Case < 19 deg_R =200
Case < 20 deg_R =213
Case < 21 deg_R =226
Case < 22 deg_R =239
Case < 23 deg_R =252
Case < 24 deg_R =265
Case < 25 deg_R =278
Case < 26 deg_R =291
Case < 27 deg_R =304
Case < 28 deg_R =317
Case < 29 deg_R =330
Case < 39 deg_R =343
Case < 31 deg_R =356
Case < 32 deg_R =369
Case < 33 deg_R =382
Case < 34 deg_R =395
Case < 35 deg_R =408
Case < 36 deg_R =421
Case < 37 deg_R =434
Case < 38 deg_R =447
Case < 39 deg_R =460
Case < 40 deg_R =473
Case < 41 deg_R =486
Case < 42 deg_R =499
Case < 43 deg_R =512
Case < 44 deg_R =525
Case < 55 deg_R =538
}
End Select
//#######################################
// sensor look up table
//#########################################
Select Vsensor
Case < 80 deg_S =21
Case < 220 deg_S =101
Case < 240 deg_S =157
{
Case < 7 deg_S =350
Case < 8 deg_S =122
Case < 9 deg_S =135
Case < 10 deg_S =148
Case < 21 deg_S =161
Case < 22 deg_S =174
Case < 23 deg_S =187
Case < 24 deg_S =200
Case < 25 deg_S =213
Case < 26 deg_S =226
Case < 27 deg_S =239
Case < 28 deg_S =252
Case < 29 deg_S =265
Case < 30 deg_S =278
Case < 31 deg_S =291
Case < 32 deg_S =304
Case < 33 deg_S =317
Case < 34 deg_S =330
Case < 35 deg_S =343
Case < 36 deg_S =356
Case < 37 deg_S =369
Case < 38 deg_S =382
Case < 39 deg_S =395
Case < 40 deg_S =408
Case < 41 deg_S =421
Case < 42 deg_S =434
Case < 43 deg_S =447
Case < 44 deg_S =460
Case < 45 deg_S =473
Case < 46 deg_S =486
Case < 47 deg_S =499
Case < 48 deg_S =512
Case < 49 deg_S =525
Case < 50 deg_S =538
}
End Select
//DESIRED TEMP DESIRED TEMPDESIRED TEMP DESIRED TEMP
// call function REF_V() and assign the result to word variable 'Vref'
//################################
Vref= REF_V()
// LCD.Cls
LCD.MoveCursor (1,1)
LCD.Write("Degrees = ", DecToStr(Vref)," " ) // DecToStr(deg_R)) DecToStr(Vref)," "
DelayMS(200)
//TIP TEMP TIP TEMP TIP TEMP TIP TEMP
// call function sensor() and assign the result to word variable 'Vsensor'
Vsensor = sensor() // tip sensor
LCD.MoveCursor (2,1)
LCD.Write("sensor = ",DecToStr(Vsensor)," ") // DecToStr(deg_S)) 14 to 37
DelayMS(250)
// compare Vsensor and Vref values
High(beep)
If Vsensor < Vref Then // not hot enough If Vsensor < Vref
LED_r=1
LED_g=0
opti=0 // turn on opti couplier by going low
Else // Vsensor must be >= Vref, so desired temperature
LED_g=1
LED_r=0
opti=1 // turn off opti couplier by going high
End If
//When Vref is set to 215 then solder melts (160C aprox.) Vsensor jumps from 200 to 220
// readings at sensor = 28.4mv room temp 52-53mv solder melts
{
counter = count_down
// If (iron_sense)=0 Then // if LOW then iron in holder HIG if iron out of holder
//DelayMS(250) //debounce your holder switch
While (iron_sense)=1 // iron in holder start counting for 10 miniutes
If (count_down < 500) Then
DelayMS(250)
count_down = count_down + 1 //start counting to 60 then off
ElseIf(count_down >= 500)Then //10+ miniutes since iron used
Low(gate) // shut off iron
count_down = count_down + 1
EndIf
Wend
count_down = 0 //counter reset
// TurnOnIron
// EndIf
// LCD.Cls
// DelayMS(250)
// LCD.MoveCursor (1,1)
// LCD.Write("sensor = ",DecToStr(counter)," ") // DecToStr(deg_R)) DecToStr(Vref)," "
}
Wend
The temperature sensor is an RTD type.
Not having an accurate temperature measurement I found that solder melts at aprox 157C.
My voltage readings at (see X on schematic, Port 1 is my RTD sensor)
Room temp = 28.4mv
at solder melt = 52-53mv
Ignore the case section as I plan to put values for deg_R and deg_S AFTER I find out what voltage per mv or C temp is.
Contemplating inserting another ADC buggy section for the sensor input.
My Vsensor at rt = 100 at melt = 200-220(it jumps from 200 to 220)
any guidance would be appreciated
When I get this project done I will post full details
Code:
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 10/6/2011 *
* Version : 1.0 *
* Notes :compute voltage to temperature. Start with sensor at 50ohms.
* : 180-200 ohms melts solder *
* : *
*****************************************************************************
}
Device = 18F4520
Clock = 8
Config OSC = INTIO67
// some LCD options...
//#option LCD_DATA = PORTD.4 // Assign the LCD connections
//#option LCD_EN = PORTD.3 //
//#option LCD_RS = PORTD.2 //
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// #option LCD_INIT_DELAY =100
// import LCD library...
// uses LCD and AD libraries...
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
Include "InternalOscillator.bas"
Include "math.bas"
Dim ADVal As Word
Dim LED_g As PORTC.0 // GREEN LED tip desired temp
Dim LED_r As PORTC.1 // HEATER ON
Dim opti As PORTE.0
Dim Vref As Integer //want whole numbers
Dim Vsensor As Integer
Dim deg_S As Word //Sensor variable
Dim deg_R As Word // Vref variable
Dim gate As PORTC.6 // pin 25 controls mosfet gate
Dim beep As PORTC.5 //pin 24 beeper sound controlled by counter
Dim iron_sense As PORTC.4 // check iron sense switch pin 23
Dim counter As Word
Dim count_down As Integer // count down timer
// Read the AD ports...
Function REF_V() As Word
result = (ADC.Read(1))*375/1024 //9 to 203 ADC.Read rsults
End Function
Function sensor() As Word
result = (ADC.Read(0))*20 //14 (RT) to 37 (melt)
End Function
// COPY / PASTED from Tetris code. The ADC readings were jumping out of order
// I found the ADC.ReadMedian routine was buggy with the 18F4520. Instead of debugging it
// I've created my own routine to do the job. Also, the program below takes 3 samples instead
// of 64 (as performed by ADC.ReadMedian).
Function ReadMedian2(pChannel As Byte) As Word
// define local variables
Dim Results(3), tmpWord As Word, i, ReSort As Byte
// make a number of samples
For i = 0 To Bound(Results)
Results(i) = ADC.Read(pChannel)
Next
Repeat
ReSort = 0
For i = 0 To Bound(Results)-1
If Results(i) > Results(i+1) Then
tmpWord = Results(i)
Results(i) = Results(i+1)
Results(i+1) = tmpWord
ReSort = 1
EndIf
Next
Until ReSort = 0
Result = Results(Bound(Results)/2)
End Function
//###################################################################
// Start Of Program...
//###################################################################
Input(PORTA.0) // temp ref voltage desired temp
Input(PORTA.1) // tip sensor
Low (LED_g) //pin 15 set lEDs OFF
Low (LED_r) //pin 16
High(opti)
Output(PORTC.6)
Output(PORTC.5)
Input (PORTC.4)
count_down=0
gate = 1
ADCON1 = %10000000 //set up ADC regesters
ADCON0.7 = 1
ADCON0.6 = 1
ADC.RightJustify = true
DelayMS (150)
LCD.Cls // clear LCD
//lcd.write(1,1,"temp")
//####################################################################
// main program loop.. .
//###################################################################
// call function REF_V() and assign the result to word variable 'Vref'
//#################################
// count down timer
//###############################
//#######################################
//voltage reference look up table
//#######################################
//#######################################
// sensor look up table
//#########################################
// Select Vsensor
// call function REF_V() and assign the result to word variable 'Vref'
While true
Vref= REF_V() //Reference voltage
Vsensor = sensor() // tip sensor
//#######################################
//voltage reference look up table
//#######################################
Select Vref //41-56 range for Vref
Case < 250 deg_R =21
Case < 260 deg_R =101
Case < 270 deg_R =157
Case < 300 deg_R =350
Case < 350 deg_R =400
Case < 400 deg_R =450
Case < 450 deg_R =480
{
Case < 16 deg_R =161
Case < 17 deg_R =174
Case < 18 deg_R =187
Case < 19 deg_R =200
Case < 20 deg_R =213
Case < 21 deg_R =226
Case < 22 deg_R =239
Case < 23 deg_R =252
Case < 24 deg_R =265
Case < 25 deg_R =278
Case < 26 deg_R =291
Case < 27 deg_R =304
Case < 28 deg_R =317
Case < 29 deg_R =330
Case < 39 deg_R =343
Case < 31 deg_R =356
Case < 32 deg_R =369
Case < 33 deg_R =382
Case < 34 deg_R =395
Case < 35 deg_R =408
Case < 36 deg_R =421
Case < 37 deg_R =434
Case < 38 deg_R =447
Case < 39 deg_R =460
Case < 40 deg_R =473
Case < 41 deg_R =486
Case < 42 deg_R =499
Case < 43 deg_R =512
Case < 44 deg_R =525
Case < 55 deg_R =538
}
End Select
//#######################################
// sensor look up table
//#########################################
Select Vsensor
Case < 80 deg_S =21
Case < 220 deg_S =101
Case < 240 deg_S =157
{
Case < 7 deg_S =350
Case < 8 deg_S =122
Case < 9 deg_S =135
Case < 10 deg_S =148
Case < 21 deg_S =161
Case < 22 deg_S =174
Case < 23 deg_S =187
Case < 24 deg_S =200
Case < 25 deg_S =213
Case < 26 deg_S =226
Case < 27 deg_S =239
Case < 28 deg_S =252
Case < 29 deg_S =265
Case < 30 deg_S =278
Case < 31 deg_S =291
Case < 32 deg_S =304
Case < 33 deg_S =317
Case < 34 deg_S =330
Case < 35 deg_S =343
Case < 36 deg_S =356
Case < 37 deg_S =369
Case < 38 deg_S =382
Case < 39 deg_S =395
Case < 40 deg_S =408
Case < 41 deg_S =421
Case < 42 deg_S =434
Case < 43 deg_S =447
Case < 44 deg_S =460
Case < 45 deg_S =473
Case < 46 deg_S =486
Case < 47 deg_S =499
Case < 48 deg_S =512
Case < 49 deg_S =525
Case < 50 deg_S =538
}
End Select
//DESIRED TEMP DESIRED TEMPDESIRED TEMP DESIRED TEMP
// call function REF_V() and assign the result to word variable 'Vref'
//################################
Vref= REF_V()
// LCD.Cls
LCD.MoveCursor (1,1)
LCD.Write("Degrees = ", DecToStr(Vref)," " ) // DecToStr(deg_R)) DecToStr(Vref)," "
DelayMS(200)
//TIP TEMP TIP TEMP TIP TEMP TIP TEMP
// call function sensor() and assign the result to word variable 'Vsensor'
Vsensor = sensor() // tip sensor
LCD.MoveCursor (2,1)
LCD.Write("sensor = ",DecToStr(Vsensor)," ") // DecToStr(deg_S)) 14 to 37
DelayMS(250)
// compare Vsensor and Vref values
High(beep)
If Vsensor < Vref Then // not hot enough If Vsensor < Vref
LED_r=1
LED_g=0
opti=0 // turn on opti couplier by going low
Else // Vsensor must be >= Vref, so desired temperature
LED_g=1
LED_r=0
opti=1 // turn off opti couplier by going high
End If
//When Vref is set to 215 then solder melts (160C aprox.) Vsensor jumps from 200 to 220
// readings at sensor = 28.4mv room temp 52-53mv solder melts
{
counter = count_down
// If (iron_sense)=0 Then // if LOW then iron in holder HIG if iron out of holder
//DelayMS(250) //debounce your holder switch
While (iron_sense)=1 // iron in holder start counting for 10 miniutes
If (count_down < 500) Then
DelayMS(250)
count_down = count_down + 1 //start counting to 60 then off
ElseIf(count_down >= 500)Then //10+ miniutes since iron used
Low(gate) // shut off iron
count_down = count_down + 1
EndIf
Wend
count_down = 0 //counter reset
// TurnOnIron
// EndIf
// LCD.Cls
// DelayMS(250)
// LCD.MoveCursor (1,1)
// LCD.Write("sensor = ",DecToStr(counter)," ") // DecToStr(deg_R)) DecToStr(Vref)," "
}
Wend