B. Base Station
The Base Station (Figure 7
), is also built around the PIC16F873 microprocessor. For this application, I
used the second onboard oscillator to generate a real time clock and configured
the MSSP as a UART for asynchronous communication with the host PC.
RS232 buffering and level translation is accomplished through the MAX232. A standard DB25 connector is used to connect to the PC. J3 provides connectivity to the RF Receiver board which was assembled with the components specified in Table 1 . No voltage conversion is required between the DataIn pin of the RF Receiver and the microprocessor since the minimum Input High voltage for the PIC is 2.0 volts.
Power is provided via a 9VDC wall mount power supply driving a 78L05 regulator for 5 volts and an LT1121 for 3.3V. A single green LED is used to provide a power indicator. When the microprocessor detects the reception of a valid data packet, additional current is injected into the LED causing it to pulse.
C. Microprocessor Code
1. Remote Station
The code for the remote station is very
simple and can be explained easily with psuedocode:
Loop | ||
Sleep for 1 minute | ||
Turn on Pressure Sensor | ||
Perform A/D conversion on Temp Sensor | ||
Average four readings | ||
Add Hamming codes to data | ||
Measure pulse width of humidity sensor circuit | ||
Measure period of 555 oscillator / 16 | ||
Compress data to fit into 10 bits | ||
Add Hamming codes to data | ||
Perform A/D conversion on battery | ||
Average four readings | ||
Add Hamming codes to data | ||
Delay additional 20msec for Pressure Sensor Stabilization | ||
Perform A/D conversion on Pressure Sensor | ||
Average four readings | ||
Add Hamming codes to data | ||
Turn Off Pressure sensor | ||
Transmit Data | ||
Turn on transmitter and wait two bit times for settling | ||
Send Preamble of eight 1's and eight 0's | ||
Send 14 bits of temperature data | ||
Send 14 bits of pressure data | ||
Send 14 bits of humidity data | ||
Send 14 bits of battery data | ||
Turn off transmitter | ||
Repeat Loop |
See the Appendix for an explanation of Hamming Codes.
2. Base Station
The firmware in the base station performs
the following functions
- Detect and decode data from the RF Receiver
- Perform error correction on the received data
- Encode the received data into ASCII format
- Transmit the ASCII data to the RS232 port
- Perform hourly data logging on RCVD data for a total of 24 hours of data
- Detect and respond to RS232 requests for latest and historical data
The base station firmware relies on interrupts to detect and collect incoming data as well as to maintain the one hour clock for data logging. Once these events occur, flags are set that inform the main loop that either new data is available or that it is time to store a reading in memory.
The main loop monitors the flags set by the interrupt service routine. If the Received Data flag is set, the RS232 transmitter routine is called. If the log data flag is set, the last received data block is buffered. In addition, the main loop monitors the RS232 receiver. If the character “L” is received, the last reading is transmitted to the serial port. If the character “H” is received, the last 24 hours of logged data are sent to the serial port.
The serial data is transmitted at 9600 baud using an 8N1 format. The ASCII encoded measurement data stream looks like:
T:ttt, P:ppp, H:hhh, B:bbb
In the above, T is temperature, P is pressure, H is humidity, and B is battery voltage. “ttt”, “ppp”, “hhh”, and “bbb” are the 10 bit readings in hexadecimal format. This data has been error corrected but not calibrated. It is the function of the application software to convert the 10 bit hex values and perform the calibration corrections.
To convert the temperature and pressure, the measured voltage is the hex code multiplied by .004 or
Vtemp = ttt * 0.004
Vpres = ppp * 0.004
The conversion of battery voltage is similar:
Vbat = 2 * bbb * .004
= bbb * .008
The frequency of the humidity sensor circuit can be derived from:
f = 1/T =(16 * 106) / (hhh+2000)
Recall from earlier in this document that relative humidity is derived from the circuit frequency via:
R.H. = -6.4790E-06 * f2 + 1.0047E-02 * f + 2.7567E+02
advertisement
advertisement