miercuri, 20 iulie 2011

Digital Clock, Date and Thermometer using PIC16F628/PIC16F84/PIC16F690 and DS18S20 or DS18B20

This is a small adjustable clock/date with thermometer function based on PIC16F628 or PIC16F84 microchip and DS18S20 or DS18B20 temperature sensor. The hardware part is very simple because it only uses a pic microcontroller, the DS18S20/DS18B20 sensor, 4x7 segments (common anode, something like KW4-301xxx Series, or common cathode something like CC56-21SURKWA), four transistors, some rezistors!

When you first power the device the clock is mentained for 8 seconds. Then the date for 2 seconds and temperature will be displayed for 3 seconds. The clock has four buttons, with one button you enter in set mode, with another button you increase values, the third button will be used to decrease values and you can put or not, the reset. If you don't want a reset button just connect the pin to +5V.



You can change:

  • ho -> hour, from 0 to 23
  • nn -> minutes, from 0 to 59 (I could not display m so I used n twice for it)
  • dd -> date day, from 1 to days/month -> calculated based on month and year
  • dn -> date month (JA FE |¯|A AP |¯|Y JU JL AU SE oc no dE -or- 01 02 03 04 05 06 07 08 09 10 11 12, depending on dt setting)
  • dy -> date year, from 0 meaning 2000 to 99 meaning 2099 (not displayed in time/date mode but needed to calculate days per month)
  • dt -> date type can be 1 or 2, if date type equals 1 then letters are used for month, else numbers are used
  • tt -> time in seconds for showing time/clock, from 2 to 99, you cannot set 0 or 1 for this setting
  • td -> time in seconds for showing date, from 0 to 99, if 0 is used then the date is not shown
  • tE -> time in seconds for showing temperature, from 0 to 99, if 0 is used then the temperature is not shown
  • Sh -> calibrate the clock by adjusting second high (see below)
  • Sl -> calibrate the clock by adjusting second low (see below)
When setting up the day for month take in consideration the month and year and days/that month in that year. You cannot set 31 day for february for example. The two middle points are not blinking when date/temperature are shown and also when set mode is on. If both td and tE are set to 0 then the time will be the only one displayed. In the case DS18S/B20 is missing you can set tE to 0.

[Settings]

Default settings are saved in chip internal memory. When you change hour/minutes/.. all of them will be saved. If power is off you will not have to change them again when powering the device back on, probably only the time/date values. The clock does not have a battery and will not work silently but at least your settings will be saved (h/m/dd/dm/dY/dt/tt/td/te/Sh/Sl).

[Clock calibration 1]

The clock can be calibrated through software. This is usefull if the clock lost or gain seconds during a period of time. This can happen for various reasons. The idea is to make the second last longer or less. One second lasts 1000000 microseconds. This is a big number for my display where I can write only 4 numbers, but.. if we represent this number in hexadecimal will have this value: 0F4240. Calibrations means adjusting around 1000000 so I dropped 0F, you cannot set that, but you can adjust 42(Sh) and 40(Sl) from 00 to FF. This gives you a large posibility to adjust your second. Adjusting examples:
-> lost 30 seconds / 24 hours => 30/86400=0.000347 1000000-(1000000*0.000347)=999653(decimal)=F40E5(hexadecimal)
=> Set 40 for Sh and E5 for Sl.
-> lost 2 seconds / 1 hour => 2/3600=0.000555 1000000-(1000000*0.000555)=999445(decimal)=F4015(hexadecimal)
=> Set 40 for Sh and 15 for Sl.
-> gain 15 seconds / 60 days => 15/5184000=0.000002
1000000+(1000000*0.000555)=1000002(decimal)=F4242(hexadecimal)
=> Set 42 for Sh and 42 for Sl.
A longer the period of time being tested will have a better acuracy for the clock.

[Clock calibration 2]

Other way to calibrate the clock is adjusting Sh and mostly Sl like below. First you need to know two values: one that makes the clock run faster and one that makes the clock run slower. Let's say our two values are: 999840(clock runs faster=FAST) and 999884(clock runs slower=SLOW). Repeat changing the second length to (FAST+SLOW)/2 until FAST=SLOW(+/-1). This should make your clock very accurate.

To download the schematic, BOM, PCB and code for microcontroller click here


    Choose :
  • OR
  • To comment
Niciun comentariu:
Write comentarii