Recent Posts

Blogroll

                                          My PIC12F683 Development Board
Office Map Circuit diagram for each experiment may not be available separately because they are conducted with PIC12F683 development board that I made. So, the readers should first see the schematic of my development board.

Friday, August 27, 2010

A Versatile Temperature Data Logger using PIC12F683 and DS1820

Introduction
There are varieties of digital temperature logger projects available online based on different microcontrollers. The one I am going to talk about is based on a Microchip's 8-pin microcontroller, PIC12F683. It reads temperature values from a DS1820 digital sensor and stores in its internal EEPROM. PIC12F683 has 256 bytes of internal EEPROM and we are going to store the temperature values in 8-bit format. This means only the eight most significant bits of temperature data from DS1820 will be read and as such the temperature resolution will be of 1 degree C.

My temperature logger has following features:
  • Reads temperature from a DS1820 sensor and stores in the internal EEPROM locations.
  • Can store up to 254 temperature values. EEPROM location 0 is used to store the sampling interval, and location 1 is used to store the number of records.
  • Three sampling interval options: 1 sec, 1 min, and 10 min. This can be selected during powering up.
  • Start and Stop buttons for control operations.
  • The recorded temperature values can be sent to PC through a serial port. A separate Send button is available to initiate data transfer.
  • A LED to indicate various ongoing operations.
  • Reset button to clear all previous records.  

Circuit Design
PIC12F683 has 6 I/O pins, out of which one (GP3, pin 4) is I/P only pin. Here is how we are going to assign the port pins.

The six I/O pins of PIC12F683 are assigned as follows:
1. GP0 (Pin 7, I/P): This pin will be used to read the temperature value from DS1820 sensor.
2. GP1 (Pin 6, O/P): This will be used for serial data transfer to a PC.
3. GP2 (Pin 5, O/P): LED output pin.
4. GP3 (Pin 4, I/P): Send (tactile switch)
5. GP4 (Pin 3, I/P): Stop (tactile switch)
6. GP5 (Pin 2, I/P): Start (tactile switch)

A simple transistor based level shifting will be used to convert the TTL voltage from PIC12F683 to appropriate RS232 level for serial data transfer to PC. The required negative voltage is derived from PC RS232 port pin 3 (Tx), which remains idle as no data transfer occurs from PC to PIC. I soldered all the components on a general-purpose prototyping board. Besides, my finished product runs on 3-AAA batteries with a diode in series for reverse polarity protection. I also have a power switch on the board. The PIC uses internal oscillator at 4MHz, and MCLR is disabled.

List of Components

  • PIC12F683 microcontroller

  • DS1820 temperature sensor

  • BC557 NPN transistor

  • Resistors: 10K (4), 4.7K (2), 470 Ohm (1)

  • Capacitor: 10uF, 50V (1)

  • LED (1)

  • Tact switches (3)
Software
The firmware is written in C and compiled with mikroC compiler from MikroElektronika. I used the free version of it because our HEX output is going to be less than 2K. The download link for mikroC is http://www.mikroe.com/eng/downloads/get/29/mikroc_pro_pic_2010_v380_setup.zip

The 3 user input switches work on interrupt-on-change mode. That means any time the user presses any button, an interrupt is generated except at times when the microcontroller is reading temperature values from DS1820 (which is instantaneous) and when it is transferring data to a PC through serial port. The interrupts are disabled at those instants. The data transfer takes place at 9600 baud rate. You can write your own software to receive data on PC side, but I have used the Hyperterminal application for this purpose. My Hyperterminal settings are
bps : 9600, Data Bits: 8, Parity : None, Stop Bits : 1, Flow Control : Hardware
Configuration: Internal clock @ 4 MHz, MCLR Disabled, WDT OFF



As I mentioned earlier, the sampling time of the data logger is selectable to 1 sec (this is for test purpose), 1 min, or 10 min. With 10 min sampling time, 254 EEPROM locations would provide temperature logging for 42 hours. Each of the three buttons (Start, Stop, and Send) provide more than one function. For example, if you keep pressing the "Send" button for more than 2 sec, you are going to reset the system, which means all the past recorded values will be erased and the default sampling interval will be set to 1 sec. In order to program the sampling interval, first turn the power OFF. Now suppose if we want 1 min sampling time, we will hold pressing the Stop button and turn the power ON. At start, PIC12F683 checks any key pressed, and determine what the sampling interval is going to be. Once it finds any button pressed, the LED will glow to indicate it is the time to release the key. Similarly, for 10 min sampling interval, use the Send key, and for 1 sec, use the Start key. 

Program Sequence
The firmware inside the PIC does the following sequence of operations.
  1. Power ON.
  2. Blinks the LED for 3 times.
  3. Check any key pressed. If yes, identify the key and store the appropriate sampling interval to EEPROM location 0. After it identifies the pressed key, the LED will glow up, and you need to release the key. Once the key is released, the selected sampling interval is stored in the EEPROM. Every time when a EEPROM location is written, the LED blinks for 3 times. 
  4. Read EEPROM location 0, and get Sampling Time. Now the program is inside the main loop. The three switches (Start, Stop, and Send) connected to GPIO 5, 4, and 3 work in Interrupt-on-Change mode. That means, when any of these buttons is pressed, an interrupt will be generated, and served accordingly. Start will start the logging of temperature values. Stop will interrupt the logging process, and Send will transfer data to serial port. If the Send is pressed for more than 2 sec, the EEPROM memory will be cleared.
Pictures
Finished Board

Serial connection to PC

Data Logger is clear (Default sampling time = 1 sec after reset)

LED blinks during data transfer


Various sampling time select and recorded values

I have posted this project on Electronics-Lab website. The complete project including firmware is downloadable from there. Here is the link.

1 comments:

Unknown said...

how the hyperterminal receive the data from PIC.........can u explain the process of transferring data from PIC to PC through RS232 using HyperTerminal software....reply...

Post a Comment

Online Embedded Systems Lab

This online laboratory teaches you the fundamentals of microcontroller-based embedded system development through a series of laboratory exercises. Most of the time, students and hobbyists could not afford expensive development kits and software to learn these things. These tutorials are prepared such that you will be building microcontroller projects at a minimum cost. Check this out