Skip to main content

Temperature Data Logger part 2

1.2 Steps Involved In Project Implementation
  1. Study of the IC-DS1820, 1-WIRE Protocol.
  1. Implementing single DS1820 with PIC.
  2. Implement two DS1820 ICs with PIC microcontroller.
  1. Adding three, four and five DS1820 IC’s on 1-wire with PIC-18F4550.
  2. Implementing Search Rom command, adding the complete 3-DS1820 1-wire code with the complete code of the Data-Logger.

2 Solar-Panel
Solar panel power output is directly affected by the temperature of the solar panel.
Solar panels are made up of solar cells which convert incident light into electricity. The power output by solar panels is measured in watts or kilowatts. It is important to monitor and estimate the amount of power being provided to the power grid.

2.1 Hardware Requirements
The list of Hardware devices are given below:
1. PIC IC 18f4550,
2. IC DS1820,
3. IC MAX232,
8. PIC Development Board,
9. PIC KIT-2 Programmer,
10. CRO,
11. Step down Transformer240/9-0-9V,
12. Solar Panels,
13. Serial to USB Converter/Cable,
14. Crystal Oscillator 12 MHz,
15. Resistors/Capacitors,
16. Digital Multimeter,
17. Connecting Wires and
18. Computer (Desktop or Laptop).

2.2 Software Requirements.
The coding of the complete program in microcontroller for temperature measurement is done using Embedded C. The tools used for compiling, assembling and programming the PIC IC are MPLAB IDE v8.50, C18 Compiler and PIC Kit2 Programmer.
MPLAB IDE is a cross compiler built for 32-Bit and 64 Bit Windows OS support, minimum PC requirements for installing are:
· 512 MB recommended
·         400 MB of hard disk space
·         Internet Explorer 5.0 or greater for installation and on-line Help.
This IDE has support for assembly language programming and C language (C compilers, assemblers, linkers, etc.) from many different vendors.
The C18 compiler is MPLAB® C Compiler for PIC18 MCUs v3.35, after installing this compiler the path of the C18 compiler has to be linked in the MPLAB IDE and under configure proper PIC IC has to be selected. The PIC Kit 2 programmer version 2.61 is used for In Circuit Serial programming. It is a simply plugged using USB cable to the PC. It is also used as a debugging tool. The hex file generated after the successful compilation and build project is loaded imported to the PIC Kit programmer and the PIC IC is then written and verified. For receiving serial data from the PIC a serial to USB driver is used, this converter requires driver software - Silicon Labs CP210x installed in the PC. The hardware connections including DS1820 IC and Voltage supply, and serial to USB driver connections are made on the PIC development board. And PIC is programmed and switched to view the DS1820 temperature reading on the Hyperterminal.










3. SYSTEM Design
PIC 18F4550
PIC 18F4550 is one of the advanced microcontrollers of PIC family from Microchip. The most important features it provides are Enhanced Flash, 13 channel A/D converter and USB.
The main features of PIC-18F4550 include
- 40 Pins
- 32K Flash Memory,
- 2048 Bytes SRAM and 256 EEPROM as Data memory,
- 13-Channel 10bit Analog to Digital Converter,
-The communication protocols it supports are SPP for USB, SPI(Serial Pheriperal Interface), Master I2C and EUSART.
- It has 2 Comparators and
- single-8bit, three-16bit Timers.

3.1 Temperature Measurement with DS1820
The Temperature Measurement is performed by Dallas IC DS1820. It’s a Digital Thermometer which provides 9–bit temperature readings which indicate the temperature of the device it is connected to. The primary reason to select this IC as a temperature sensor for the 5-Channel Data Logger is because it gave temperature readings in digital format.
Another major reason for using this IC is DS1820 works on 1-wire protocol to communicate with the master (microcontroller) which means a single microcontroller port pin is sufficient to connect with all the 5 DS-1820 IC’s for the 5 channel Data-Logger. DS1820 outputs a purely digital signal (Binary Coded. 9–bit temperature readings. The table below shows the pin-specification of the DS1820.
PINS
SYMBOL
DESCRIPTION
1
GND
Ground.
2
DQ
Data Input/Output pin. For 1–Wire operation: Open drain.
3
Vdd
Optional Vdd pin.

Table 3.1: DS1820 Pin Description

Thus multiple IC devices can be connected to the bus as each device has a unique 64- bit ROM number which act as identifier, the 64-bit ROM is used to address each sensor. The 1-Wire connection with the PIC is as shown in fig 3.2. As the DS1820 is synchronized to a low pulse, the communication from both the ends is initiated by pulling low the Data Line.
Fig 3.2: Multiple DS1820 interface on a single bus
A pull-up resistor connects the data line of the 1-Wire network to the 5V supply of the PIC (this acts as a “resistive” or “weak” pull-up). So the data line is constantly being pulled towards the logic 1 state by this weak pull-up resistor.

3.2 DS1820 Components
The main components are:
i) 64–bit ROM, ii) Temperature sensor, iii) 64-bit Scratch-Pad
i) 64–BIT ROM
Each DS1820 contains a unique ROM code that is 64–bits long. The first eight bits are a 1–Wire family code (DS1820 code - 10h). The next 48 bits are a unique serial number. The last eight bits are a CRC (Cyclic Redundancy Check) of the first 56 bits.

The 64–bit ROM and ROM Function Control section allow the DS1820 to operate as a 1–Wire device. The functions required to control other sections of the DS1820 are not accessible until a single ROM function command has been given. The 1–Wire PIC must first provide at-least one of the five ROM function commands, following which other functions/commands specific to the DS1820 is accessible.
ii) Temperature Conversion
Block diagram of the temperature measurement circuitry is shown in fig 4.7
There are two temperature co-efficient oscillators which affect the counter value.
- High temperature co-efficient oscillator and Low temperature co-efficient Oscillator as shown in fig 4.6
- There is a Slope Accumulator Circuitry.
- A Counter and a Temperature Resistor.
- The counter is preset with a base count that corresponds to -55ºC

Fig 3.3 Temperature Co-efficient Oscillator Cycles

- The DS1820 measures temperature by counting the number of clock cycles that the low temperature coefficient oscillator goes through during a gate period determined by high temperature coefficient oscillator.
- If the counter reaches zero before the gate period is over, the temperature register, which is preset to the -55ºC value, is incremented, indicating that the temperature is higher than -55ºC.
Fig 3.4: Internal Block Diagram for Temperature Measurement
- At the same time, the counter is then preset with a value determined by the slope accumulator circuitry.

- This is to compensate for the parabolic behavior of the oscillators over temperature.
- The counter is then clocked again until it reaches zero. If the gate period is still not complete, then this process repeats.
The DS1820 can measure temperature over the range of –55°C to +125°C in 0.5°C increments. For example
MSB LSB
11111111 1 1 0 0 1 1 1 0 = –25°C
The most significant (sign) bit is duplicated into all of the bits in the upper MSB of the two–byte temperature register in memory. This “sign–extension” yields the 16–bit temperature readings as shown in Table. 4.2




TEMPERATURE
DIGITAL OUTPUT
DIGITAL OUTPUT
+125°C
00000000 11111010
00FAh
+25°C
00000000 00110010
0032h
1/2°C
00000000 00000001
0001h
+0°C
00000000 00000000
0000h
–1/2°C
11111111 11111111
FFFFh
–55°C
11111111 10010010
FF92h

Table 3.2 Temperature and DS1820 output data.

iii) 64+8 - Bit Scratch-Pad
The read/write memory consists of a scratchpad RAM and nonvolatile, electrically erasable RAM, which stores the high and low temperature thresholds TH and TL. The scratchpad is organized as eight bytes of memory. The first two bytes contain the measured temperature information. The third and fourth bytes are volatile copies of TH and TL and are refreshed with every power– on reset. The next two bytes are not used; the seventh and eighth bytes are count registers. There is a ninth byte which may be read with a Read Scratchpad command. This byte contains a cyclic redundancy check (CRC) value of the previous 8 bytes.
4.3.2 Transaction Sequence and Timing Diagrams
The steps to communicate with DS1820 IC are as follows -
Initialization Reset Pulse: The initialization sequence required to begin any communication with the DS1820 is shown in Figure 4.8. A reset pulse followed by a presence pulse indicates the DS1820 is ready to send or receive data. All the DS1820 commands are of length 1 byte and all the transaction that takes between the DS1820 and the master (PIC) is done with LSB (least significant bit) first.
Indications
Master Active Low DS1820 Active Low
PIC and DS1820 Low Resistor Pull-Up
Fig 3.5 Reset pulse for DS1820
Rom Commands:
  1. Read ROM [33h]: This command allows the bus master to read the DS1820’s unique 64 bit ROM code which includes 8–bit family code, unique 48–bit serial number, and 8–bit CRC. This command can only be used if there is a single DS1820 on the bus.
  2. Match ROM [55h]: The match ROM command, followed by a 64–bit ROM sequence, allows the bus master to address a specific DS1820.
  3. Skip ROM [CCh]: This command can save time in a single drop bus system by allowing the bus master to access the memory functions without providing the 64–bit ROM code.
  4. Search ROM [F0h]: The bus master might not know the number of devices on the 1–Wire bus or their 64–bit ROM codes when connected initially. The search ROM command allows the bus master to identify the 64 bit ROM codes of all slave devices on bus.
  5. Alarm Search [ECh]: This command is identical to the Search ROM command. However, the DS1820 will respond to this command only if an alarm condition has been encountered at the last temperature measurement.

Memory/Control Commands:
  1. Write Scratchpad [4Eh]: This command writes to the scratchpad of the DS1820, starting at address 2. The two bytes written will be saved in scratchpad memory, at address locations 2 and 3. Writing may be terminated at any point by issuing a reset.
  2. Read Scratchpad [BEh]: This command reads the contents of the scratchpad.
Reading will commence at byte 0, and will continue through the scratchpad until the 9th (byte–8, CRC) byte is read.
  1. Copy Scratchpad [48h]: This command copies the scratchpad into the E2 memory of the DS1820, storing the temperature trigger bytes in nonvolatile memory.
  2. Convert T [44h]: This command begins a temperature conversion. No further data is required. DS1820 will output “0” on the bus as long as it is busy making a temperature conversion; it will return a “1” when the conversion is done.
  3. Recall E2 [B8h]: This command recalls the temperature trigger values stored in E2 to the scratchpad. This recall operation happens automatically upon power–up to the DS1820 as well.
  4. Read Power Supply [B4h]: With every read data time slot issued after this command has been sent to the DS1820, the device will signal its power mode: “0”=parasite power, “1”=external power supply provided.

4.3.3 Search Rom Algorithm
With SEARCH ROM (F0h) command, PIC can individually identify all the 1-Wire devices connected on the 1 wire bus and their 64-bit addresses at once. The ROM search process is the repetition of a simple 3–step routine: read a bit, read the complement of the bit, then write the desired value of that bit. The bus master performs this simple, 3–step routine on each bit of the ROM. After one complete pass, the bus master knows the contents of the ROM in one device. The remaining number of devices and their ROM codes may be identified by additional passes. The following example of the ROM search process assumes four different devices are connected to the same 1–Wire bus. The ROM data of the four devices is as shown:
ROM1 00110101...
ROM2 10101010...
ROM3 11110101...
ROM4 00010001...
The search process is as follows:
1. The PIC begins the initialization sequence by issuing a reset pulse. The slave devices respond by issuing simultaneous presence pulses.
2. The PIC will then issue the Search ROM command on the 1–Wire bus.
3. The PIC reads a bit from the 1–Wire bus. Each device will respond by placing the value of the first bit of their respective ROM data onto the 1–Wire bus. ROM1 and ROM4 will place a 0 onto the 1–Wire bus, i.e., pull it low. ROM2 and ROM3 will place a 1 onto the 1–Wire bus. The result is the logical AND of all devices on the line, therefore the PIC reads a 0. The PIC reads another bit, all of the devices on the 1–Wire bus respond to this second read by placing the complement of the first bit of their respective ROM data onto the 1–Wire bus. ROM1 and ROM4 will place a 1 onto the 1–Wire. ROM2 and ROM3 will place a 0 onto the 1–Wire, thus it will be pulled low. The PIC again observes a 0 for the complement of the first ROM data bit. It has determined that there are some devices on the 1–Wire bus that have a 0 in the first position and others that have a ‘1’.
00 There are still devices attached which have conflicting bits in this position.
01 All devices still coupled have a 0–bit in this bit position.
10 All devices still coupled have a 1–bit in this bit position.
11 There are no devices attached to the 1–Wire bus.

4. The PIC writes a 0. This deselects ROM2 and ROM3 for the remainder of this search pass, leaving only ROM1 and ROM4 connected to the 1–Wire bus.
5. The PIC performs two more reads and receives a 0–bit followed by a 1–bit; it indicates that all devices still coupled to the bus have 0’s as their second ROM data bit.
6. The PIC then writes a 0 to keep both ROM1 and ROM4 coupled.
7. The PIC executes two reads and receives two 0–bits. This indicates that both 1–bits and 0–bits exist as the third bit of the ROM data of the attached devices.
8. The PIC writes a 0–bit. This deselects ROM1 leaving ROM4 as the only device still connected.
9. The PIC reads the remainder of the ROM bits for ROM4 and continues to access the part if desired. This completes the first pass and uniquely identifies one part on the 1–Wire bus.
10. The PIC starts a new ROM search sequence by repeating steps 1 through 7.
11. The PIC writes a 1–bit. This decouples ROM4, leaving only ROM1 still coupled.
12. The PIC reads the remainder of the ROM bits for ROM1 and communicates to the underlying logic if desired. This completes the second ROM search pass, in which another of the ROMs was found.
13. The PIC starts a new ROM search by repeating steps 1 through 3.
14. The PIC writes a 1–bit. This deselects ROM1 and ROM4 for the remainder of this search pass, leaving only ROM2 and ROM3 coupled to the system.
15. The PIC executes two read time slots and receives two zeros.
16. The PIC writes a 0–bit. This decouples ROM3, and leaving only ROM2.
17. The PIC reads the remainder of the ROM bits for ROM2 and communicates to the underlying logic if desired. This completes the third ROM search pass, in which another of the ROMs was found.
18. The PIC starts a new ROM search by repeating steps 13 through 15.
19. The PIC writes a 1–bit. This decouples ROM2, leaving only ROM3.
20. The PIC reads the remainder of the ROM bits for ROM3 and communicates to the underlying logic if desired. This completes the fourth ROM search pass, in which another of the ROMs was found.


Comments

Popular posts from this blog

CAN INTERVIEW QUESTIONS

Qualifiers and Modifier in C

RTOS Real time operating system interview questions

CAN INTERVIEW QUESTIONS 2

What is UDS protocol

Memory mapping in c

TOP IOT PLATFORMS