TemperatureC

ftComputing : Programme für die fischertechnik-Interfaces und -konstruktionskästen
  
ftComputing.de
Home
Back
Sitemap
Index
Links
Impressum
Mail
 

Computing Starter Pack : An Introduction

Temperaturregelung Task

"The heating is triggered by lens tip lamp M2. The 'blower' serves as a 'cooling unit' at output M1. We use th NTC resistance at input EX for temperature measurement. Program the model, so that the heating switches off and the blower switches on above a specific temperture. This should cool until the lower threshold value is reached. Then the blower should be switched off and the heating on." So far a quotation from Computing Starter Activity Booklet.

The Solution with LLWin 3.0

as on the LLWin 3.0 CD-ROM

LLWin 3.0 : Temperaturregelung

Visual Basic 6 & FishFa50.OCX

tempar3.jpg (13894 Byte)The two threshold values are shown in the Textboxes txtHeiß (hot) and txtKalt (cold). They can be modified. The actual temperature value is displayed in lblTemperatur. The Names mHeizung, mKühlung, aFühler ... are constants accompanied to the corresponding outlets of the interface. The FishFa50 control is called ft within the program.

Translations : 
mKühlung : Cooling
mHeizung : Heater
aFühler : Sensor, Heizen : heat, ftiEin : On, ftiAus : Off, ftiLinks : Left, ftiRechts : Right, Tempertur : temperature, Zyklus-Ende : to stop the cycle press HALT-Button or ESC-Key.

There are discussed three different solutions :

  1. A solution close to the LLWin solution : the "GoTo Label Solution"

  2. A solution close to the modern constructs of Visual Basic : the "Select Case Solution".

  3. A solution for safe operating of the program : the "Enabled Solution".

The program core is the same in each of them.
You will find the complete sources in the package Starter.ZIP. In addition you need the package FishFa50.ZIP.

Tempar1 : "Goto Label Solution"

Private Sub cmdAction_Click()

ft.AnalogScan = True
ft.OpenInterface "COM1"
Start:
If ft.Finish(0) Then GoTo Ende
Kühlen:
If Temperatur >= Val(txtHeiß) Then GoTo Heizen
ft.SetMotor mHeizung, ftiAus
ft.SetMotor mKühlung, ftiEin
GoTo Start
Heizen:
If Temperatur <= Val(txtKalt) Then GoTo Start
ft.SetMotor mHeizung, ftiEin
ft.SetMotor mKühlung, ftiAus
GoTo Start
Ende:
ft.CloseInterface
End Sub

Private Sub tmrTemperatur_Timer()

Temperatur = ft.GetAnalog(aFühler)
lblTemperatur = Temperatur
End Sub

cmdAction_Click : procedure connected to the click event of the START-Button. It is nearly the hole temperature control.

  1. ft.AnalogScan = True
    The analogous inputs EX/EY are to be scanned in proper intervals.
    ft.OpenInterface "COM1"
    connection to the intelligent interface via port COM1 (to be modified). LLWin will do this things internally.
  2. Start:
    If ft.Finish(0) then GoTo Ende

    Start marks the beginnig of the control loop (LLWin : the 'green man'). Finish ends the control loop with the ESC-Key or, if you add an additional switch on E1, by pressing the switch (Finish must be changed to Finish(1))
    Start markiert den Beginn der Regelungsschleife (das grüne Männchen)
  3. Kühlen: (Cooling)
    If Temperatur >= Val(txtHeiß) Then GoTo Heizen
    ft.SetMotor mHeizung, ftiAus
    ft.SetMotor mKühlung, ftiEin
    GoTo Start
    The actual temperature is asked to be low (higher values of the NTC) than continue heating else change to cooling by SetMotor mHeizung (heating) off and SetMotor mKühlung (cooling) on. GoTo Start directs to the beginning of the control loop. The LLWin has a exchanged if condition for better layout.
  4. Heizen: (Heating)
    Like Cooling. It temperature is ask to be high enough (NTC values are low).
  5. Ende:
    ft.CloseInterface
    End of the control loop, cut the connection to the interface.
  6. tmrTemperatur_Timer
    This is a second task, independed from the control loop, for displaying the actual temperature value (LLWin : the second 'green man'):

Tempar2 : "Select Case Solution"

Private Sub cmdAction_Click()

ft.AnalogScan = True
ft.OpenInterface "COM1"
Do
Temperatur = ft.GetAnalog(aFühler)
lblTemperatur = Temperatur
Select Case Temperatur
Case Is < Val(txtHeiß)
ft.SetMotor mHeizung, ftiAus
ft.SetMotor mKühlung, ftiEin
Case Is > Val(txtKalt)
ft.SetMotor mHeizung, ftiEin
ft.SetMotor mKühlung, ftiAus
End Select
Loop Until ft.Finish(0)
ft.CloseInterface
End Sub

This is the same functionallity once more. But instead of GoTo and Label we use the Select Case statement. Displaying the actual temperature in done in the control loop for more simplicity.

  1. Select Case Temperatur
    Case Is < Val(txtHeiß)
    Case Is > Val(txtKalt)
    End Select

    May be interpreted to be the short form of a multi if. The first according case is executed. The remaining part is skipped. 
    Is < Val(txtHeiß) asks if the NTC value is less than the threshold value for hot (less values : high temperature).
  2. Do
    Loop Until ft.Finish(0)

    Stands for the temperature control loop. It will be executed until the ESC-Key is pressed.
  3. Val(txtHeiß)
    The threshold value for 'hot' is entered in the form as a text. Val() converts it to a number.

Tempar3 : "Enabled Solution"

Private Sub cmdAction_Click()

Dim Temperatur&
ft.AnalogScan = True
If ft.OpenInterface("COM1") = ftifehler Then
MsgBox "Interfaceproblem", vbOKOnly
Exit Sub
End If
cmdAction.Enabled = False
cmdEnde.Caption = "HALT"
Do
Temperatur = ft.GetAnalog(aFühler)
lblTemperatur = Temperatur
Select Case Temperatur
Case Is < Val(txtHeiß)
ft.SetMotor mHeizung, ftiAus
ft.SetMotor mKühlung, ftiEin
Case Is > Val(txtKalt)
ft.SetMotor mHeizung, ftiEin
ft.SetMotor mKühlung, ftiAus
End Select
ft.Pause 500
Loop Until ft.Finish(0)
ft.ClearMotors
ft.CloseInterface
cmdEnde.Caption = "ENDE"
cmdAction.Enabled = True
cmdEnde.SetFocus
End Sub


Private Sub cmdEnde_Click()

If cmdEnde.Caption = "HALT" Then
ft.NotHalt = True
Else
Unload Me
End If
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If cmdEnde.Caption = "HALT" Then Cancel = 1
End Sub

The control loop correponds to that of Tempar2. Additional code is added to make the operating of the program more safe. In the solutions before it is e.g. possible to press the START or ENDE button while the control loop is running. That will confuse the running program. Other case : if you forget to connect the interface to power, nothing will happen, no message will give an alert. In case of LLWin it wil be done under the hood. Here some solutions for safe operating.

  1. If ft.OpenInterface("COM1") = ftiFehler Then
    Msgbox "Interfaceproblem", vbOKOnly
    Exit Sub
    End If

    OpenInterface returns a value (the returncode) which tells the open to be OK. The returncode of OpenInterface is checked for ftiFehler (commonError) in that case a message is shown, the sub exits. 
  2. cmdAction.Enabled = False
    cmdEnde.Caption = "HALT"
    If OpenInterface has success, the control loop will run. Therefore the START button is disabled to prevend a new START. The Caption of the ENDE button is changed to HALT. HALT ends only the control loop, not the hole program. This task was done in the past only with the ESC-Key.
  3. If cmdEnde.Caption = "HALT" Then
    ft.NotHalt = True
    Else
    Unload Me
    End If
    The ENDE button now has a second task : ending the control loop. This task is done if its caption is HALT. In that case ft.NotHalt is set to true to signal an end request. Thats all at this place. The Finish statement at the end of the control loop ask in addition to the ESC-Key ft.NotHalt to be true and ends the loop as well.
  4. ft.ClearMotors
    ft.CloseInterface
    cmdEnde.Caption = "ENDE"
    cmdAction.Enabled = True
    cmdEnde.SetFocus
    After the end of the control loop all is cleared. ClearMotors clears all M-Outputs. Motor and lamp are switche off explicitely on this place and not some time later with CloseInterface. The ENDE button gets back its caption 'ENDE', the START button now is enabled.
  5. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If cmdEnde.Caption = "HALT" Then Cancel = 1
    End Sub
    The cross in the corner right above of a window frame which closes the program now is controlled to. If you try ending the program with the 'cross' while the control loop is running it is blocked in QueryUnload (return code Cancel = 1).

When manipulating the form events you can find it nice to have OpenInterface in the Form_Load event and CloseInterface in the Form_Unload event.

And if you are confused by the 'reversed' temperatures (we display no temperature, but NTC values) : Temperatur = 600 - ft.GetAnalog(aFühler) is a beginning ...

What works, if nothing seems to be at work, with the click on the START button. There is no heating, no cooling, nothing works. It will start with heating, if the NTC is cool enough (take a piece of ice or change the value Heiß (hot). Whats about an additional Case Val(txtHeiß) To Val(txtKalt)?

The (non discussed) project Tempar4 only is for my pleasure don't look to it.