Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Report Lab-10
Objective:
Do Activity 8-1,8-2 challenge 8-1+ extra
Used Items:
(1) ADC0831
(1) LM34 Temperature Sensor
(3) 220 Resistors
(1) LED
(1) LM358 Op-Amp
(2) 0.68 F Capacitors
(3) 10 k Resistors
(1) 2N3904 Transistor - BJT
(1) BS170 Transistor FET
(1) 220 Resistor
(2) 1 k Resistors
(1) LED
(1) 100 W Resistor (Heater)
(1) 12 V Fan
(1) Polystyrene Test Tube
(1) 9 V battery (not included)
(1) 0.1 microF Capacitor
Activity 8-1
Circuit
Code
'
'
'
'
'
VAR
VAR
Bit
Byte
Samples
VAR
Delay
CON
Photo PIN 8
Byte
100
' -----[ Initialization ]-------------------------------------------------' ***** Reads values from StampPlot on reset
PAUSE 1000
' Allow connection to stabilize
' Read time between evaluations (seconds * 4)
DEBUG CR,"!READ [(drpTime),*,4]",CR
DEBUGIN DEC Samples
PAUSE 50
' Read setpoint
DEBUG CR,"!READ (txtSetP)",CR
DEBUGIN DEC SetPoint
PAUSE 50
' -----[ Main Routine ]---------------------------------------------------DO
' Adjust delay to approximate real time between evaluations
' Take samples and plot
IF Samples > 2 THEN
FOR Counter = 1 TO Samples
GOSUB ReadPhoto
GOSUB PlotData
IF Samples > 4 THEN PAUSE Delay
NEXT
ELSE
GOSUB ReadPhoto
GOSUB PlotData
ENDIF
' Evaluate and plot
GOSUB CalcError
GOSUB CalcProp
GOSUB MarkProp
' GOSUB CalcInteg
' GOSUB MarkInteg
' GOSUB CalcDeriv
' GOSUB MarkDeriv
GOSUB CalcTotal
GOSUB MarkTotal
LOOP
' -----[ Subroutines ]----------------------------------------------------ReadPhoto:
HIGH Photo
PAUSE 10
RCTIME Photo, 1, PhotoVal
RETURN
CalcError:
Error = PhotoVal - SetPoint
RETURN
CalcProp:
Prop = Error
RETURN
CalcInteg:
' Calculate integral output
IntegSample = Error * Samples
' Sample is error x time (samples) Edt
SignBit = IntegSample.BIT15
' save sign for math
IntegSample = ABS(IntegSample)/4
' approx 1/4 sec per sample ' convert to seconds
IF SignBit = 1 THEN IntegSample = IntegSample * -1
'
'
'
'
CalcDeriv:
DEBUG "!O txtLE=", SDEC LastError,CR
ErrorChange = Error - LastError
SignBit = ErrorChange.BIT15
Deriv = ABS(ErrorChange)/Samples * 4
IF SignBit = 1 THEN Deriv = Deriv * -1
LastError = Error
RETURN
'
'
'
'
'
'
'
CalcTotal:
Total = Prop + Integ + Deriv
SignBit = Total.BIT15
Total = ABS(Total) MAX 25000
IF SignBit = 1 THEN Total = Total * -1
RETURN
'
'
'
'
'
MarkProp:
DEBUG "!DMOD
"!LINE
"!DMOD
RETURN
MarkInteg:
DEBUG "!DMOD
"!FREC
"!RECT
"!DMOD
RETURN
MarkDeriv:
DEBUG "!FCIR
"!DMOD
"^DWTH
"!LINE
"!SETD
"!DMOD
RETURN
MarkTotal:
' Plot outputs and update
DEBUG
"!O txtE=", SDEC Error,CR,
"!O txtActual=", DEC PhotoVal,CR,
"!O txtProp=", SDEC Prop,CR,
"!O txtEdt=", SDEC IntegSample,CR,
"!O txtsumEdT=", SDEC Integ,CR,
"!O txtdE=", SDEC ErrorChange,CR,
"!O txtdEdt=", SDEC Deriv,CR,
"!O txtTotal=", SDEC Total,CR,
"!O plot2.draw=line (DATAVAL1),0,(PTIME),0,(RED)",CR,
"!O Plot2.Draw=LINE (DATAVAL1),(DATAVAL2),(DATAVAL1),",SDEC
Total,",(Black)",CR,
"!O Plot2.Draw=LINE (DATAVAL1),",SDEC Total,",(PTIME),",SDEC
Total,",(Black)",CR,
"!SETD 1,(PTIME)",CR,
"!SETD 2,", SDEC Total,CR,
"!O butLog.Run",CR
RETURN
PlotData:
Figure 8-8
Multiplying the Prop error to 4, and retesting:
Figure 8-9
Testing Derivative Evaluation: E/t
Adding Bias
Challenge 8-1
a)
b)
Activity 8-2
Code:
'
'
'
'
'
'
VAR Byte
VAR Word
LED
ADC_CS
ADC_Clk
ADC_Dout
ADC_Vminus
ADC_Vref
PIN
PIN
PIN
PIN
PIN
PIN
'
'
'
'
'
'
Heater
Fan
PIN 5
PIN 0
DriveTime
PWMVal
x
Offset
Span
VAR
VAR
VAR
VAR
VAR
0
13
14
15
11
10
LED
ADC
ADC
ADC
ADC
ADC
output pin
Chip Select pin
Clock pin
Data output
Offset Value
Span reference
Byte
Byte
Byte
Byte
Byte
'
'
'
'
'
ReadADC
UpdateSP
GetSPDrive
ControlIncubator
' -----[ Subroutines ]----------------------------------------------------' **** Set ADC Span and offset and read ADC value
READADC:
PWM ADC_Vminus,Offset * 255/500,100
PWM ADC_Vref,Span * 255/500,100
LOW ADC_CS
SHIFTIN ADC_Dout,ADC_Clk, MSBPOST,[ADC_DataIn\9]
HIGH ADC_CS
RETURN
'
' **** Drive PWM for amount of drive time in 250mSec intervals
'
Drive only if fan is off
ControlIncubator:
IF FAN = 1 THEN PWMVal = 0
FOR x = 1 TO DriveTime * 4
PWM Heater,PWMVal,250
NEXT
RETURN
' **** Read Configuration information from StampPlot
ReadSP:
PAUSE 50
DEBUG CR,"!Read (txtLower)",CR
' Read Lower Temp
DEBUGIN DEC Offset
PAUSE 50
DEBUG "!Read [(txtUpper),-,(txtLower)]",CR
'Read Span
DEBUGIN DEC Span
PAUSE 50
DEBUG "!Read (txtTime)",CR
' time x 4 for PWM
DEBUGIN DEC DriveTime
PAUSE 50
RETURN
Extra
On-OFF
Getting K:
=>
With Yss= 121.09
A= tf-ti => 122.16 119.55 => 2.61
K=121.09/ 2.61 => K=46.394
Diferencial Gap
Getting K:
=>
With Yss= 101.5
A1= tf-ti => 101.92 100.78 => A1=1.14
K1=101.5/ 1.14 => K1=89.03
Extra 2
Second Order