Friday, 22 April 2016

Alarm Clock-Cum-Temperature Indicator

This circuit is a PIC micro-controller based easy-to-construct gadget, which combines a clock with a temperature indicator in the same display. The display uses four 7-segment common-anode LED. It shows the clock, and in every minute for five seconds the display
alternates to show the temperature in oC. An alarm facility with buzzer is provided.

Clock’s precision is due to the 20-MHz high-frequency crystal that is used with PIC16F73 chip. Second display’s decimal point blinks every second. The display for temperature uses three digits from the left and the fourth digit just shows oC. For this, the fourth LED is soldered on the PCB upside-down. This places its decimal-point LED on top-left instead of bottom-right so as to show the symbol of degree (o). Hence, we use four separate common-anode LED units instead of a combo LED display component.

The MCU choice is now for the more convenient PIC chip from the low-cost 16F family. This is a 28-pin chip with ports a, b and c, as well as several internal peripherals like Timer, ADC and UART. Most important advantage of PIC is the ease of downloading a program on to the chip, because it uses flash memory and can be programmed with 5V supply. PICkit2 programmer is used for downloading the hexadecimal code on to the chip.
                                  

Port pins in the PIC chip have greater power capability than those in the 8051 family. So driving LED segments can be made by directly connecting the segments to the port pins, without any buffer IC. Thus, component count is reduced.

There are several analogue-to-digital converter input channels. Speed of conversion is as short as 20 microseconds. So it is easy to connect any analogue signal and digitise the same for displaying with LEDs. Here, the analogue signal is that of temperature.

Texas Instruments chip LM35 is a low-cost temperature sensor and is connected to the analogue input pin of the PIC chip. It can measure Temperatures in the range -50oC to 100oC, but in this unit it is mounted on the PCB only to show room temperature.

Circuit and working 

shows the circuit diagram of the alarm clock-cum-temperature indicator. PIC16F73 IC has its reset on pin 1. A resistor and capacitor junction is tied to this pin to perform reset on applying power. The 5V power supply is obtained from a low-voltage transformer (X1), rectifier (BR1) and voltage regulator IC 7805 (IC1).
                         

Pin 20 is Vcc and pins 19 and 8 are grounded. Pins 9 and 10 are for connecting a crystal for the oscillator. Any crystal frequency is alright, but it is better to use the highest 20MHz crystal for speed. Two capacitors, each of 15pF, are tied to the end of the crystal to ground. This frequency is called high speed, or HS. There is a configuration register inside the chip, which should be programmed for HS, among other choices, such as XT, RC and LP. The configuration byte we use is 52 hex.

Port B is programmed as output pins. Port A pins are programmed as input pins and pin 2 (AN0) is used as analogue input pin from temperature sensor LM35. Port C pins 4 through 7 are used for driving the anodes of the four LEDs.

Pin C.0 is used as input pin for connecting switch S1 to high logic in order to set the time of clock or alarm time. By continuously pressing it, time changes and the switch has to be released immediately after the required time is displayed.

Pin C.3 is used as another input pin. It is used for setting the alarm time. S2, which grounds this pin, will set the alarm time to be the time currently on display. Thereafter, S1 is to be pressed to adjust to the current clock time. 

Pins C.2 and C.1 are used for seconds blinking (not used here) and for clock alarm output. A piezo buzzer of a musical type is connected to it.

Port B pins are used for sinking the currents from the segments of the four LED displays. Segments of all LEDs are connected together and a multiplexed drive lights one LED after another with a delay of 1ms. Multiplexing is done by port C pins 4 through 7, which go low one after another in sequence. This low-going signal pulls the bases of transistors T1 through T4 in sequence, causing current to flow from the collector pins to anode pins of the LEDs. Emitters of the transistors are all tied to 5V line. Transistors are therefore of pnp type. We can use 2N2907 for bright displays; BC557 can also be used.

While signal from the temperature sensor is given to AN0 pin (2), pin 5 is connected to a supply voltage of 2.55V. This is necessary because ADC of the chip converts to values from 0 to 255. Reference voltage is derived from a zener of 3.3V (which has the least temperature variation among all zener values) and a preset. This pin 5 is programmed to be the reference voltage pin for the ADC. This is done by ADCON1 register bits of the chip. By writing 01 to this register, choice of reference voltage for the ADC to work is from pin 5.

Since LM35 gives a linear 10mV output for each degree of temperature, it will output a value of, say, 250mV for 25oC. This will be read by the ADC as 25 because it is one-tenth of the reference voltage. For a temperature of 100oC, it will give 100 x 10 = 1000mV or 1V. This will be shown as 100 on the ADC. Value of ADC register ADRES is used to show the temperature on the display.

In order to convert the ADC value to decimal, divide the value by ten to get the high digit; balance or remainder will be low digit. First three LEDs show the 3-digit temperature value and the fourth digit is programmed to show oC. Therefore the fourth LED is turned top-down in the PCB while soldering.

It may be noted from the circuit diagram that order of the segments of the LED displays is not in sequence while wiring port B pins. So port B pins 0 through 7 are not wired in sequence to segments a, b, c, d, e, f, g and DP. Rather, order is changed in order to ensure that PCB tracks are easily routed. Order used is b-a-f-g-c-d-e-DP.

It is to be understood that, according to this connection, look-up table for the segment code for each and every digit displayed is to be prepared. For example, to show number 3, segments a, b, c, d and g have to be made low to sink the current and make these glow. As per the above-mentioned order, this gives the code as 0-0-1-0-0-0-1-1. This byte is 23, which is the look-up table entry for number 3.

component list

                                            

Software
Code for the clock as well as the temperature indicator was developed using Oshon PIC simulator _IDE software. It provides high-level BASIC for code development and has all peripherals available for simulation of a program under development on the computer screen.Complete program is in .ASM format and the program code in hEX is in a hex file. Using PICkit2 programmer it can be entered into a fresh PIC chip. Note that the configuration byte is 52 hex. You use 42 hex if you want to protect the code from being copied.


Download PCB and component layout




After powering on the circuit, a default value will be displayed. Press S1 to set the desired time. After setting the time, press S2 to set alarm time. Now, present time will be shown on the display. The buzzer (PZ1) will sound at the time set for the alarm.


No comments:

Post a Comment