1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Industrial Control Student Guide Version 1.1 phần 8 ppsx

24 357 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 24
Dung lượng 571,99 KB

Nội dung

Experiment #7: Real-time Control and Data Logging Note that the program will reset the time to 05:53 every time the BASIC Stamp is reset This can occur from program loading, manual Stamp reset, power supply cycling, and sometimes the COM port or computer cycling The start time is appropriate for what we are discussing in this section, but in later sections you may want to set the values of the start-time to actual values '***** Initialize Settings ******* Time = $0553 Seconds = $00 CTimeLow CON $1800 CTimeHigh CON $0600 LowTempSP CON 900 HighTempSP CON 1000 '********************************* GOSUB SetTime ' Define initial time ' Define time to go low temp ' Define time to go high temp ' Define low temp ' Define high temp ' Set RTC (Remark out if time ok) Note: If power is removed from the DS1302 Real Time Clock it will power-up with unpredictable values in the time registers with Gosub SetTime remarked out The times for changing temperature and their new values are also set here GOSUB SetTime sets the real time clock to the specified time Once the proper time is set, this line may be remarked out and downloaded again to prevent the time from being reset to 05:53 if the BASIC Stamp is reset The program uses two sets of variables for time, one to set/hold the current time, and another to hold the time we wish to change the thermostat Note that the word variable of Time and CTime are further broken down into Hours and Minutes: Time Hours Minutes VAR VAR VAR WORD TIME.HIGHBYTE TIME.LOWBYTE ' Word to hold full time ' High byte is hours ' Low byte is hours The variable Hours is assigned to be the high byte of the word variable Time, or those two BCD positions representing the hour The same is true for minutes and the lower positions This is a very powerful tool when parts of a single variable need to be addressed individually Program 7.1 starts time minutes before switching to the working-hours temperature This should provide time for temperature to stabilize at the lower temperature Figure 7.4 is a plot of the run Industrial Control Version 1.1 • Page 197 Experiment #7: Real-time Control and Data Logging Figure 7.4: Time-Controlled 'Building Heating’ The StampPlot Lite user status box displays the current time and the time that the next change is set to occur The time in the status box may appear to be changing at irregular intervals, but that is a result of timing of the BS2 in displaying the data and not the time kept by the RTC The message area displays both the time a change occurred and the new setpoint The plot illustrates On/Off control at the 90 F setpoint, and the switch to the 100 F setpoint at 06:00 Using the RTC, adding more output devices, and expanding the control section of the code, we could add numerous time-based events to occur over the course of a day Download and run program 7.1 Monitor with StampPlot Lite through at least the 06:00 change You will need to wait another 12 hours to see if it switches back to the low setpoint at 18:00 Have time to wait? Page 198 • Industrial Control Version 1.1 Experiment #7: Real-time Control and Data Logging Questions and Challenges: 1) The time data stored in the DS1302 uses the number system 2) Add a temperature setting of 95 F to be enabled between 4:00PM (16:00) and 6:00 PM (18:00) Modify the starting time and initial temperature to test both times 3) Use the LED on P8 to simulate a house lamp Add code to energize it at 8:00 PM (20:00) and de-energize it at 11:00 PM (23:00) Modify the starting time of RTC to test both times Exercise #2: Interval Timing Instead of having events occur at defined times of the day, often a process may need to perform actions at certain intervals of time The annealing process is one such process In this example a metal is heated at a given temperature for a set amount of time, raised to another temperature for a set amount of time, and then cooled to yet another temperature This tempers the metal and gives it certain desirable characteristics, such as hardness and tensile strength Since we are dealing with intervals of time instead of absolute times, we will need to perform calculations to find the target time that marks the end of an interval The time interval must be added to the start time of the temperature phase This sounds simple, but it isn’t If you remember, our time keeping is performed in BCD, a subset of hexadecimal When adding values together for time, the BASIC Stamp is working in hexadecimal Take the example of 38 seconds + seconds We know this should yield a result of 43 seconds, but since we are really adding $38 + $05 (hexadecimal), our result is $3D (counting 5: $39, $3A, $3B, $3C, $3D) If we compare that value to a time from the RTC, it will never occur! We need to decimal adjust the result This is done by checking whether the digit exceeds the legal BCD range ( >9) and adding if it does Test this with the above result: $3D + $06 = $43 (counting 6: $3E, $3F, $40, $41, $42, $43) Success! We now have the result we needed for BCD values Some other issues we need to contend with is that either the one's or ten's place may need to be adjusted Depending on the result we may need to carry over into our minutes or hours Seconds and minutes need to roll over at 60, while hours needs to roll over at 24 Industrial Control Version 1.1 • Page 199 Experiment #7: Real-time Control and Data Logging This is the general sequence, or algorithm, our program will use: • Check whether the one's place in seconds is legal BCD (

Ngày đăng: 08/08/2014, 01:21