ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 14.06.2025

Просмотров: 1796

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

Experiment #7: Real-time Control and Data Logging

FOR x

= 4 to MemAddr-1

' Loop through memory locations

READ x,DataIn

' Read data stored in memory

GOSUB Calc_Temp

' Calculate temp based on data

LMinutes = LMinutes + Interval

' Add interval to get stored time

GOSUB AdjustTime

' Decimal adjust time

' Display message data

DEBUG DEC X-4,",",HEX2 LHours,":",HEX2 LMinutes,",",DEC Temp,CR

DEBUG DEC Temp,CR

' Plot temperature

HIGH LED

' Pause 0.1 second for spacing between data

PAUSE 100

LOW

LED

NEXT

DEBUG

"!PLOT OFF",CR

' Disable plotting

LTime

= Time

' Set Log time to current time

LMinutes = LMinutes + Interval

' Add interval to set for next data logging

GOSUB

AdjustTime

' After dump, hold button to reset logging

HIGH 8

' Or logging will continue from current point

' LED ON

DEBUG

"Hold button now to reset log",CR

PAUSE

2000

' If button not pressed, skip restart

IF PB

= 1 THEN SkipReset

GOSUB

RecoveryData

' Restart - save new recovery data

DEBUG

"Release button now",CR

SkipReset:

' LED Off

LOW 8

= 0 THEN SkipReset

If PB

' Wait for button release

Return

We'll discuss operation and major blocks in our code. At the top of the code is the initialization information:

'*** Set Init.

Time and Logging Interval **************

Time

=

$2246

' Initialization Time

Interval

CON

$05

' Do not

use digits >

6

' Sample

interval (in

BCD minutes) for logging

Samples

CON

500

' Number

of samples to acquire

Stop_Reset

CON

0

' When full, 0=reset,

1 = stop logging

'******************************************************

This data defines the time to set the RTC, how long the interval between logging should be, and how many samples should be logged. Stop_Reset is defines whether to stop logging (1) or reset (0) and start over destroying the old data when the maximum samples are collected.

The pushbutton has several purposes:

Industrial Control Version 1.1 •Page 211


Experiment #7: Real-time Control and Data Logging

1.On-Power up or Reset of the BS2, a message will appear informing you to hold down the pushbutton to initialize the clock and logging (the LED will light for this also). If the button is held down, the value of time in the initialization section will be used to set the RTC and logging will be reset to the start. Recovery data will be written to EEPROM for the next reset.

RecoveryData:

' Stores data for recovery from restart

MemAddr = 4

' Set starting location

WRITE 0,MemAddr.HIGHBYTE

' Write to EEPROM

WRITE 1,MemAddr.LOWBYTE

' Save start time in EEPROM

WRITE 2,Hours

WRITE 3,Minutes

Return

Note that a memory address is

a word-sized value and must be saved as high and

low byte.

2.During logging, if the pushbutton is pressed, the data will be ‘dumped’ or downloaded. We will be using StampPlot Lite to capture and plot the data as it is dumped. The data is NOT destroyed and the logger will continue to log new data.

3.At the end of a data dump, if the pushbutton is held down, the data logger will reset the log to the start destroying old data and resetting the start time of logging.

If the BASIC Stamp 2 is reset and the button is NOT held down, the program will read recovery data of current memory location and start time from the EEPROM. The RTC time will NOT be reset. It should be maintaining proper time through the reset UNLESS power was lost. Figure 7.7 is the flowchart of the initialization of the program.

Page 212 •Industrial Control Version 1.1

Experiment #7: Real-time Control and Data Logging

Figure 7.7: Logging Initialization Routine

Industrial Control Version 1.1 •Page 213

Experiment #7: Real-time Control and Data Logging

Figure 7.8: Control and Saving Routines

Time Control routine (Figure 7.8) is used to determine if it is time to save new data to memory. This is contingent on the memory location for samples being less than the number of samples specified.

TimeControl: ' Check if time for reading IF (Time = LTime) AND (MemAddr-4 < Samples) THEN SaveData

RETURN

The Save Data routine is called from Time Control when it is time to write a new sample to memory. The current DataIn (value read from the ADC) is stored in the current memory address, and the memory address is incremented for the next cycle. The next interval time is calculated (and later BCD adjusted). If the

Page 214 •Industrial Control Version 1.1

Experiment #7: Real-time Control and Data Logging

maximum number of samples is reached, depending on the Stop_Reset value, data logging will either ceased (see Time Control) or logging will start over.

Note that the raw DataIn value from the ADC is stored and not the temperature-calculated value. This allows the data to be stored in one byte instead of two as a word. The stored value will be converted into temperature when it is ‘dumped’ to the PC.

SaveData:

' Write ADC reading to memory

WRITE MemAddr, DataIn

' Store data into EEPROM

HIGH 8:PAUSE 250:LOW 8

' Blink LED

MemAddr = MemAddr + 1

' Increment memory location for reading

WRITE 0,MemAddr.HIGHBYTE

' Update recovery data

WRITE 1,MemAddr.LOWBYTE

LMinutes = LMinutes + Interval

' Update for next interval

IF MemAddr-4 < Samples THEN AdjustTime

' If samples not full, continue

IF Stop_Reset = 1 THEN Dont_Reset

' If samples full, restart or end logging

GOSUB RecoveryData

Dont_Reset:

AdjustTime:

Figure 7.9 illustrates the flow of the DumpData routine. When the pushbutton is pressed, Dump Data configures StampPlot for plotting, and creates a loop reading through the logged values, converting them to temperatures, and sending the values for plotting and the message window. Note that the log time is set to the start time, and the timing interval is added to the log time each loop iteration to determine the original time the data was logged.

Once the loop is complete, the log time is set back to the current time and the user is requested to hold down the pushbutton to reset the logging to start (the LED will light for indication also).

Industrial Control Version 1.1 •Page 215


Experiment #7: Real-time Control and Data Logging

Figure 7.9: Data Dump Routine Flowchart

Once DumpData is complete, the control time will be updated to the time of the next sample, and logging will continue from the point it left off, allowing downloading without affecting the stored data. Figure 7.10a is a screenshot of our collected data dumped to StampPlot Lite.

Page 216 •Industrial Control Version 1.1

Experiment #7: Real-time Control and Data Logging

Figure 7.10a: Sample Data Dump of Logged Data

The format of the message data is suitable for importing into a spreadsheet for graphing, as seen in Figure 7.10b. A portion of the saved message file is as follows:

Point,Time,Temperature

0,22:51,787

1,22:56,787

2,23:01,787

3,23:06,787

4,23:11,783

5,23:16,783

Industrial Control Version 1.1 •Page 217

Experiment #7: Real-time Control and Data Logging

Figure 7.10b: Imported Message Data to Excel

Logged Temperature Data

900

(tenths)

875

850

825

Temperature

800

775

750

725

700

22:51

00:01

01:11

02:21

03:31

04:41

05:51

07:01

08:11

09:21

10:31

11:41

12:51

14:01

15:11

16:21

17:31

18:41

19:51

21:01

22:11

23:21

00:31

Time

We set the incubator outside of a window and recorded outdoor temperatures.. Outdoor temperature can be tricky due to effects of wind cooling, sunlight heating, and thermal layers in the canister trapping heat. We had quite a few spikes in readings. Can you do better?

Our plot shows temperatures from 22:51 to 22:51 the next night. Note the rise and falls in temperature during the day. The expected high for the day was 88F, and we came pretty close!

Of course, we are not restricted s temperature range 70F-120F. Refer back to Experiment #4. Software range values are determined by the span and offset voltage settings to the ADC0831.

TempSpan

CON

5000

'

Full Scale input span

(5000 = 50 degrees

span)

Offset

CON

700

'

Minimum temp. Offset.

(700 = 70 degrees)

Page 218 •Industrial Control Version 1.1


Experiment #7: Real-time Control and Data Logging

Questions and Challenges:

1.Perform Logging of a System: Determine a temperature that you want to log over a long period of time. This may be outdoors, the room temperature (does the heating/cooling change during evening hours?), or maybe some other slow changing system (a water tank in the sun?).

1)Determine the range of expected values for temperature. Set the span and offset variables and potentiometers appropriately.

2)Determine the length of time you need to collect the data (one day? the weekend?). Based on a maximum of 50 samples, calculate the interval time needed for logging.

3)Ready to program? If you are going to move your BOE, make sure it is running on a battery that will last throughout the logging!

4)We also want to check the accuracy of the RTC in this experiment, so when the program is ready to download:

a)Open the Windows clock and pick an upcoming time.

b)Set the start time to this upcoming time (remember to use 24-hour time) Time = $1530

c)5 seconds before the initializing time, download the file to the BS2 and hold the circuit pushbutton down until the LED goes off or debug window instructs you to release it.

d)Use the Debug Window or StampPlot to note the BS2 and the PC Times.

BS2: _________ PC: __________ Difference: ________

e)Let your data record! After the 1st sample is done, you may test the data dump by pressing the push-button.

f)After you are finished recording data, run and connect StampPlot Lite, press the push-button to dump the data.

g)Use the Debug Window or StampPlot to note the BS2 and the PC Time.

BS2:_________ PC: __________ Difference: ________

h) Extrapolate the time-error for 24 hours: _________

Did the data conform to your expectations?

Industrial Control Version 1.1 •Page 219

Experiment #7: Real-time Control and Data Logging

2.Discuss the 'system' you monitored and conclusions of your results.

3.How much time error was calculated over a 24-hour period? How could this error be compensated for in software?

4.Why is it important to limit the amount of data that can be stored in the BS2?

Page 220 •Industrial Control Version 1.1

Appendix A: StampPlot Lite

Appendix A:

StampPlot Lite

StampPlot Lite is an application developed by SelmaWare Solutions for the Industrial Control series. The application allows plotting and capture of analog, digital and general data.

Downloading and Installing StampPlot Lite

StampPlot Lite may be downloaded from the Stamps in Class web site at http://www.stampsinclass.com. The program is installed by double-clicking on the setup.exe icon and accepting the default directories.

To download StampPlot Lite, click on the “Downloads” button on our web site and scroll down to the “Industrial Control” section.

Industrial Control Version 1.1 •Page 221