Loading...
Showing posts with label Clock. Show all posts
Showing posts with label Clock. Show all posts

Saturday, November 4, 2017

DS3231 RTC Clock mikro C Demo Code - 16F648A


LCD Clock
LCD Clock

Introduction:

The DS323x is a low-cost, extremely accurate I²C real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input, and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device as well as reduces the piece-part count in a manufacturing line. The DS323x is available in commercial and industrial temperature ranges, and is offered in a 16-pin, 300-mil SO package.

DS3231 Block Diagram
DS3231 Block Diagram
The RTC maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with an active-low AM/PM indicator. Two programmable time-of-day alarms and a programmable square-wave output are provided. Address and data are transferred serially through an I²C bidirectional bus.

Most RTCs use an external 32kHz timing crystal that is used to keep time with low current draw. And that’s all well and good, but those crystals have slight drift, particularly when the temperature changes (the temperature changes the oscillation frequency very very very slightly but it does add up!) This RTC is in a beefy package because the crystal is inside the chip! And right next to the integrated crystal is a temperature sensor. That sensor compensates for the frequency changes by adding or removing clock ticks so that the timekeeping stays on schedule.

DS3231 module
DS3231 module

This is the finest RTC you can get, and now it in a compact, breadboard-friendly breakout. With a coin cell plugged into the back, you can get years of precision timekeeping, even when main power is lost. Great for data-logging and clocks, or anything where you need to really know the time.

The Circuit:

The circuit is very simple. It used PIC16F648A Pic micro, 16x2 LCD and DS3231 RTC module. The PIC used it's internal oscillator and run at 4MHz. Proteus and Hex file can download from the bottom of the page.

DS323x RTC Clock Circuit
DS323x RTC Clock Circuit


MikroC PRO Source Code:

/**************************************************************************

DS323x RTC Clock Demo
Copyright (C) 2017 Scorpionz

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.

>> Email: scorpionzblog@gmail.com
>> Blog : scopionz.blogspot.com

***************************************************************************/


// Software I2C connections
sbit Soft_I2C_Scl at RB2_bit;
sbit Soft_I2C_Sda at RB1_bit;
sbit Soft_I2C_Scl_Direction at TRISB2_bit;
sbit Soft_I2C_Sda_Direction at TRISB1_bit;
// End Software I2C connections

// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

char seconds, minutes, hours, day, date, month, year, tem_l, tem_h; // Global variables

//--------------------- Reads time and date information from RTC (DS3231)
void Read_Time()
{
Soft_I2C_Start(); // Issue start signal
Soft_I2C_Write(0xD0); // Address DS3231, see DS3231 datasheet
Soft_I2C_Write(0); // Start from address 0
Soft_I2C_Start(); // Issue repeated start signal
Soft_I2C_Write(0xD1); // Address DS3231 for reading R/W=1

seconds = Bcd2Dec(Soft_I2C_Read(1)); // Read seconds byte
minutes = Bcd2Dec(Soft_I2C_Read(1)); // Read minutes byte
hours = Bcd2Dec(Soft_I2C_Read(1)); // Read hours byte
day = Bcd2Dec(Soft_I2C_Read(1)); // Read day byte
date = Bcd2Dec(Soft_I2C_Read(1)); // Read date byte
month = Bcd2Dec(Soft_I2C_Read(1)); // Read month byte
year = Bcd2Dec(Soft_I2C_Read(1)); // Read year byte

Bcd2Dec(Soft_I2C_Read(1)); // Alarm
Bcd2Dec(Soft_I2C_Read(1));
Bcd2Dec(Soft_I2C_Read(1));
Bcd2Dec(Soft_I2C_Read(1));
Bcd2Dec(Soft_I2C_Read(1));
Bcd2Dec(Soft_I2C_Read(1));
Bcd2Dec(Soft_I2C_Read(1));

Bcd2Dec(Soft_I2C_Read(1)); // Data
Bcd2Dec(Soft_I2C_Read(1));

Bcd2Dec(Soft_I2C_Read(1));

tem_h = Bcd2Dec(Soft_I2C_Read(1)); // Temp
tem_l = Bcd2Dec(Soft_I2C_Read(0));

Soft_I2C_Stop(); // Issue stop signal
}

void write_data(char address, char w_data)
{
Soft_I2C_Start(); // issue I2C start signal
Soft_I2C_Write(0xD0); // send byte via I2C (device address + W)
Soft_I2C_Write(address); // send byte (address of DS3231 location)
Soft_I2C_Write(w_data); // send data (data to be written)
Soft_I2C_Stop(); // issue I2C stop signal
delay_ms(50);
}

//-------------------- Output values to LCD
void Display_Time()
{
Lcd_Chr(2, 7, (hours / 10) + 48);
Lcd_Chr(2, 8, (hours % 10) + 48);
Lcd_Chr(2,10, (minutes / 10) + 48);
Lcd_Chr(2,11, (minutes % 10) + 48);
Lcd_Chr(2,13, (seconds / 10) + 48);
Lcd_Chr(2,14, (seconds % 10) + 48);

Lcd_Chr(2,16, (day % 10) + 48); // day
}

void Display_Date()
{
Lcd_Out(1,1,"Date: "); // Prepare and output static text on LCD
Lcd_Chr(1,9,'-');
Lcd_Chr(1,12,'-');
Lcd_Out(1,13,"20"); // start from year 2000

Lcd_Chr(1, 7, (date / 10) + 48);
Lcd_Chr(1, 8, (date % 10) + 48);
Lcd_Chr(1,10, (month / 10) + 48);
Lcd_Chr(1,11, (month % 10) + 48);
Lcd_Chr(1,15, (year / 10) + 48);
Lcd_Chr(1,16, (year % 10) + 48);
}
void Display_Temp()
{
Lcd_Out(1, 1,"Temp: +");
Lcd_Out(1,13,"ßC ");
Lcd_Chr(1,10,'.');

tem_l=tem_l*25;

Lcd_Chr(1, 8, ((tem_h & 127) / 10) + 48);
Lcd_Chr(1, 9, ((tem_h & 127) % 10) + 48);
Lcd_Chr(1, 11, (tem_l / 10) + 48);
Lcd_Chr(1, 12, (tem_l % 10) + 48);

if(tem_h & 128) Lcd_Chr(1, 7, '-');
}

//------------------ Performs project
void Init_Main()
{
PCON.OSCF = 1; //4MHz
CMCON |= 0x07; // Disable Comparators CMCON |= 7;
OPTION_REG = 0;

Soft_I2C_Init(); // Initialize Soft I2C communication
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off

Lcd_Out(1,3,".:Scorpionz:.");
Delay_ms(500);
Lcd_Out(2,1,"Ds3231 RTC Clock");
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,1,"Time: ");
Lcd_Chr(2,9,':');
Lcd_Chr(2,12,':');

write_data(14,0x40); //SQWE output at 1 Hz
}

//----------------- Main procedure
void main() {
Delay_ms(500);

Init_Main(); // Perform initialization

while (1) { // Endless loop
Read_Time(); // Read time from RTC(DS3231)
Display_Time(); // Prepare and display on LCD
Display_Date(); Delay_ms(450);
Display_Temp();
Delay_ms(450);
}
}

Saturday, January 17, 2015

8x32 LED Matrix Real Time Clock Circuit with Alarm - 18F2550

Most of electronic enthusiasts are very much interest about the LED matrix displays. So if you are one of them this is for you. If you are not familiar with LED matrices at all, please read these two experimental tutorials Basics of LED matrix display and scrolling text message on an LED matrix .

8x32 LED Matrix Clock
LED Matrix Clock

LED matrix displays are very popular in these days and most of people are love it but wonder how it can construct. So that I decide to provide this post for you. This project is about constructing a mono-color LED matrix display based real time clock. It can display time, date, and room temperature alarm with chime function. You can control this clock using four switches (Mode, Enter, Up, Down) and can changed the speed of scrolling by RV2.

8x32 LED Matrix Clock circuit
Matrix Clock

The main IC of this project is PIC16F2550 micro controller which controls all the sections, and display the LED matrix with the help of 74HC595 shift registers and DS1307 RTC IC. As amplifier I chose TDA7052 because of low cost and almost no component. But you can choose any amplifier for it. To react function keys you need to press and hold keys and remember to put 100-330 resistors between shift registers and displays if those are too bright.

This built in some events and according to it clock change its welcome massage and alarm tone.

The events are;
  • New Year – Jan 1  
  • Vesak  - May 
  • Christmas - Dec 25
  • Valentine – Feb 14 and
  • Birthday - User Define

You can add custom date for birthday by changing the values of Eeprom (1) for day and Eeprom (2) for month. Also used hex value for this.
Ex: for Jun 25 -> Eeprom (1) = 19 and Eeprom (2) = 06

LED Matrix Clock Preview

Tested and Working!

Thursday, November 13, 2014

DS1302 Real Time LCD Clock Circuit - 16F88

DS1302 Real Time Clock circuit
Clock Schematic

This clock use DS1302 as timekeeping chip and this was my first time I used this IC for my project. It used three wires for communication. It communicates with a microprocessor via a simple serial interface. Three wires are required to communicate with the clock/RAM: CE, I/O (data line), and SCLK (serial clock). The real-time clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The DS1302 will run with a voltage from 2.0V to 5.5V.

Here I used PIC16F88 micro-controller and 16x2 LCD. No switches were added to edit time and date. To add switches you have to modify the code and it is not difficult. The DS1302 uses an external 32.768kHz crystal. The oscillator circuit does not require any external resistors or capacitors to operate. The accuracy of the clock is dependent upon the accuracy of the crystal and the accuracy of the match between the capacitive load of the oscillator circuit and the capacitive load for which the crystal was trimmed. Please refer datasheet for more information.

DS1302 Features

  • Real-Time Clock Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the Week, and Year with Leap-Year Compensation Valid Up to 2100
  • 31 x 8 Battery-Backed General-Purpose RAM
  • Serial I/O for Minimum Pin Count
  • 2.0V to 5.5V Full Operation
  • Uses Less than 300nA at 2.0V
  • Single-Byte or Multiple-Byte (Burst Mode) Data Transfer for Read or Write of Clock or RAM Data
  • Simple 3-Wire Interface
  • DS1202 Compatible

MikroC used as programming language but you can easily convert it to MikroC Pro. Micro-controller is running by its internal clock at 8MHz.The project files can be download from below with Source files, Proteus and Hex file.

Tuesday, November 11, 2014

Seven Segment Simple Digital Clock Circuit - 16F628

Simple Clock circuit
Clock Schematic

This is a very simple clock circuit. The only IC used in this circuit was 16F628A pic micro-controller. This IC is very cheap and you can get it from any electronic spare parts shop. Four common cathode seven segment displays used to display time. We cannot get much accurate time using this. However, we can able to get reasonable accurate if we calibrate this circuit correctly. You can calibrate this clock by changing value of ‘Drift’. The ‘Drift’ variable is use to set calibration and it value should be in 0 to 255. In my code, value of ‘Drift’ is 198 and that is not the perfect value for it. You can get 0.5Hz frequency from RB7 if your ‘Drift’ value is correct.

Totally four buttons are used in this circuit and RESET button is optional. Min and Hour buttons used to update time and Mode button change the display mode. Two display modes are available. At the beginning, it will show hour and minutes on display. You can view seconds by pressing Mode button. Please replace NOT gate with NPN transistors such as BC547 and put 1k-10k resistors for base before connect with micro-controller.

MikroC used as programming language but you can easily convert it to MikroC pro or any other language. Because the code very simple. Micro-controller is running by its internal clock at 4MHz.The project files can be downloading from below with Source files, Proteus and Hex file.

Saturday, November 8, 2014

DS1307 Real Time Seven Segment Alarm Clock Circuit - 16F88

Updates
  • 31/01/2016 - Added: Hourly chime restriction function
  • 27/10/2019 - Fixed: Hourly chime delay error (v3)
  • 27/10/2019 - Fixed: Auto mode data showing time increased (v3)

DS1307 Alarm Clock
Alarm Clock

This is the newest clock I made using DS1307 real time clock IC. Not like other clock circuits I posted, this clock circuit built in all necessary function such as hourly chime, alarm, time drift correction, etc. In addition, it also include temperature sensor as optional function.

This clock has eight display modes (including standby mode).
  • Mode 1 – Display Seconds
  • Mode 2 – Display Time
  • Mode 3 – Display Date
  • Mode 4 – Display Year
  • Mode 5 – Display Alarm
  • Mode 6 – Display Temperature
  • Mode 7 – Show Time, Date and Temperature continuously
  • Mode 8 – Stand By Mode

DS1307 Alarm Clock
DS1307 Alarm Clock

This PIC project uses PIC16F88 micro-controller, DS1307 Real Time Clock, LM35 temperature sensor, and SSD-5461AG common cathode seven segment display. (If you cannot find that display then use four common cathode seven segment displays).

The PIC16F88 used its internal oscillator and it runs at 8MHz. We can reduce cost and complexity of circuit and can save micro-controller’s pin by using internal oscillator.RA0 and RA1 configured as digital and analogue alternatively to drive seven segment and read voltage of LM35.

The DS1307 (RTC) Real Time Clock is an 8-pin device using an I2C interface. It has eight read/write registers that store the information. This IC will do the timekeeping and it not only keeps track of time but also the date and the day of the week. DS1307 RTC is fully Binary Coded Decimal (BCD) clock/calendar. Therefore, the data read from DS1307 should be converted to BCD format. The most important is the Clock Halt Bit (CH), which is, bit 7 of address 0. This is the register that controls 'seconds' and the CH bit has to be preserved otherwise the chip stops the clock. Writing zero to this bit resets the CH bit so that the clock runs. So when the first usage we must set ‘seconds’. Otherwise clock fail to run.

DS1307 Alarm Clock circuit
Alarm Clock's Internal

Time Setting

Using MODE button you can change the display mode and the current status will save to Eeprom.
SET button can be used for edit the time, date, alarm etc. When you pressed the SET button, clock entered to the Edit mode and two displays will turn off. You can be able to edit values on other display by pressing UP and DOWN buttons. To edit turn off displays value pressed SET button again. Press the SET button again to return clock to normal mode. If the clock is in normal mode UP button also can used to change the time format (12hr or 24hr) and DOWN button can used to turn on or off alarm.

When time changed to 12hr mode LED will indicate the AM/PM status. Alarm on will indicated by the decimal point of last seven segment display. If you wish, you can also connect separate LED for it.

Error correction

Surprisingly making an accurate 32kHz oscillator is a difficult. This is because low speed oscillator drivers are designed for low power operation. That means high impedance and therefore low current, which makes the driver extremely sensitive to noise (or any nearby signals, which can capacitive couple to the crystal wire). Because that when using DS1307 we cannot get accurate time. Therefore, I added simple error correction mechanism for this clock

First, set the clock to current time (time of computer or internet) and keep it run up-to 24 hours.
After 24 hours, check the time of clock with time of computer. If time is drift, check how many seconds are drifted..?  (Use clock mode 1 to view seconds)

E.g. 1:  PC time:  16:30:00 Clock time:  16:30:05
+5 seconds drifted. So we have to reduce time.

I used Eeprom (2) to store this values and default value is 30 (0x1E).  See the Eeprom figure.
Now simply overwrite it with 25 (0x19). You must use hex values for it.

E.g. 2:  PC time:  16:30:00 Clock time:  16:29:58
-2 seconds drifted. So we have to increase time.
Overwrite Eeprom (2) value with 32 (0x20).

Hourly Chime Restriction

You can able to stop hourly chime function for specific time period using this setting. Device Eeprom address 6 and 7 use for this. default values are 0x00 and 0x18 (0 and 24)

Eeprom(6) ≤ Chime Restriction < Eeprom(7)

Eg: Stop Chime from 21.00 to 6.00
Eeprom(6) = 0x06 and Eeprom(7) = 0x15
6 ≤ Chime Restriction < 21

Eeprom of 16F88
Eeprom of 16F88

Sunday, March 3, 2013

DS1307 Real Time Seven Segment Clock Circuit - 16F88

DS1307 IC
DS1307 is a low power serial real time clock with full binary coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM (Non Volatile Static Random Access Memory). Data and Address are transferred serially through a bidirectional I2C bus.

The RTC provides year, month, date, hour, minute and second information. The end date of months is automatically adjusted for months fewer than 31 days including leap year compensation up to year 2100. It can operate either in 24-hour format or 12-hour format with AM/PM indicator.

DS1307 comes with built-in power sensing circuit which senses power failures and automatically switches to back up supply. We can provide a 3V CMOS Battery for that. The DS1307 RTC uses an external 32.768 kHz Crystal Oscillator and it does not requires any external resistors or capacitors to operate.

DS1307 Block Diagram
DS1307 Block Diagram

In this project, I used ds1307 as real time clock ic and PIC16f88 as micro-controller. To save micro-controller pins there are four input keys which are all connected to a single analogue input pin. This pin also drives one of the seven segment display LEDs so it has to be switched between input (to read the analogue voltage) and output (to drive the led). Each key pulls the analogue input to a different voltage level which you can easily read using the ADC (RA0).

DS1307 Real Time Clock circuit
Circuit Diagram

Set Time

Mode : Pressing mode button cycles the display showing 3 different data.

Mode 1 : Time only
Mode 2 : Seconds only
Mode 3 : Stand-by


Set : To change the value, set button must be pressed.

Set 1 :  Edit mode, show Minute
Set 2 :  Edit mode, show Hour
Set 3 :  Return to clock mode


Up and Down : After Pressing set button, you can change the values indicated on clock by using this buttons.

UP :  Values ++
In clock mode it will also change the 12/24Hr format.

Down :  Values --
In clock mode it will do nothing.

Clock Accuracy:

The accuracy of the clock is dependent upon the accuracy of the crystal and the accuracy of the match between the capacitive load of the oscillator circuit and the capacitive load for which the crystal was trimmed. Additional error will be added by crystal frequency drift caused by temperature shifts. External circuit noise coupled into the oscillator circuit may result in the clock running fast.

To ensure the crystal oscillates correctly you must ensure that;
  • Crystal uses 12.7pf load capacitance (correct crystal type).
  • The crystal is close to the IC.
  • The tracks are short.
  • The chip supply has lots of decoupling (capacitors from +5V to GND). e.g. A 100n and a 10n
  • There are no signal tracks near to the crystal.
  • For a PCB: It has a guard ring and a ground plane and away from digital signals.

DS1307 Datasheet
PIC16F88 Datasheet

PIC16F88 pin
Pin Connection


I Used mikroC for compile this project.
Also you can get PCF8583 version from here.

Saturday, March 2, 2013

PCF8583 Real Time Seven Segment Clock Circuit - 16F88

Basic Connection of PCF8583
Basic Connection of PCF8583
The PCF8583 is a clock and calendar chip based on a 2048 bit static CMOS RAM organized as 256words by 8 bits. Addresses and data are transferred serially via the two-line bidirectional I2C-bus.

The built-in word address register is incremented automatically after each written or read data byte. Address pin A0 is used for programming the hardware address, allowing the connection of two devices to the bus without additional hardware.

The built-in 32.768 kHz oscillator circuit and the first 8 bytes of the RAM are used for the clock, calendar, and counter functions. The next 8 bytes can be programmed as alarm registers or used as free RAM space. The remaining 240 bytes are free RAM locations.

Block diagram of PCF8583
Block diagram of PCF8583

Features:

  • I2C-bus interface operating supply voltage: 2.5 V to 6 V
  • Clock operating supply voltage 1.0 V to 6.0 V at 0 °C to +70 °C
  • 240 × 8-bit low-voltage RAM
  • Data retention voltage: 1.0 V to 6.0 V
  • Operating current (at fSCL = 0 Hz): max 50 μA
  • Clock function with four year calendar
  • Universal timer with alarm and overflow indication
  • 24 hour or 12 hour format
  • 32.768 kHz or 50 Hz time base
  • Serial input and output bus (I2C-bus)
  • Automatic word address incrementing
  • Programmable alarm, timer, and interrupt function
  • Slave addresses: A1h or A3h for reading, A0h or A2h for writing

PCF8583 Real Time Clock circuit
Circuit Diagram

This clock circuit is same as DS1307 - Real Time Clock. The only different is here I used PCF8583 RTC clock ic and change firmware. Because registers of DS1307 and PCF8583 are different.

To save micro-controller pins there are four input keys which are all connected to a single analogue input pin. This pin also drives one of the seven segment display LEDs so it has to be switched between input (to read the analogue voltage) and output (to drive the led). Each key pulls the analogue input to a different voltage level which you can easily read using the ADC (RA0).


Set Time:

Mode : Pressing mode button cycles the display showing 3 different data.

Mode 1 : Time only
Mode 2 : Seconds only
Mode 3 : Stand-by


Set : To change the value, set button must be pressed.

Set 1 :  Edit mode, show Minute
Set 2 :  Edit mode, show Hour
Set 3 :  Return to clock mode


Up and Down : After Pressing set button, you can change the values indicated on clock by using this buttons.

UP :  Values ++
In clock mode it will also change the 12/24Hr format.

Down :  Values --
In clock mode it will do nothing.

Quartz Frequency Adjustment:

By evaluating the average capacitance necessary for the application layout, a fixed capacitor can be used. The frequency is measured using the 1Hz signal available after power-on at the interrupt output (pin 7). The frequency tolerance depends on the quartz crystal tolerance, the capacitor tolerance and the device-to-device tolerance. Average deviations of 5 minutes per year are possible. See data sheet for more detail.

Use mikroC for compile.

PCF8583 Datasheet

PIC16F88 Datasheet

PIC16F88 pin
PIC16F88 Pin Connection

Saturday, August 18, 2012

PIC16F88 Seven Segment Digital Clock Circuit

In the beginning, I posted a clock that used PIC16F84A micro-controller. You can see it here. PIC16F84A is very old IC and it has very less functions. Therefore, today I post a developed version of that clock. It used PIC16F88 micro-controller. PIC16F88 built in many features such as large memory, internal oscillator, ADC and many more. In addition, we can use this IC for our future projects.

PIC16F88 Digital Clock preview
Preview

PIC16F88 Digital Clock in dot board
Circuit Created On Dot board

You can use big SSD or LEDs to build this but therefore you should add more transistors. Like this.

large display connection
for large display

Here I used 4 switches to control the clock.
  • SW1 – Edit / Enter
  • SW2 – Up Sec / Min
  • SW3 – Down Sec / Min
  • SW4 – 12Hr / 24Hr
  • SW5 – Reset

Click here for 1Hz Oscillator Circuits

1Hz Oscillator Circuits
Clock Circuits

PIC16F88 Datasheet

PIC16F88 Pin
16F88 Pin-out


Saturday, July 28, 2012

24Hr Digital Clock and Alarm Circuit Using Logic ICs - CD4017 CD4026

[Updated]
06/05/2018 - Added Month and Date Reset Feature


This is my first clock project, and used logic IC such as 4017, 4026 to build this clock circuit. Its include Date, Day, and Hourly alarm.See below picture.

Logic clock preview
Preview

It’s very complicated at first sight. But it is not. First of all you can build main circuit and check it work or not.If the circuit work fine, then add other parts step by step to the circuit.

If it’s not work check all component and connections are correct and also check Seven Segment Displays. In my circuit I used LEDs but it is possible to use Seven Segment Displays.
Add &transistors if you use LED or big Seven Segment Displays because this logic ICs can not handle large current. I connect this circuit with 6v backup battery to prevent time lost when the power is fail. In power failure displays are turned off but time is running using battery power.

Logic clock circuit
Full Circuit Diagram

1Hz Signal Generators

To generate 1Hz clock pulse for this circuit here I used circuit of a ordinary clock machine. you can buy a clock machine very cheap price at electronic shops or you can get it from old clock. In below picture you can see most common circuits of clock circuits. By giving power to this circuit we can able to get 1Hz output across the pins that are connected to coil (motor). (But actually we can get only 0.5Hz pulse in one pin. So get 1Hz we need to connect those pins by two diodes. you can see that in the diagram).

1hz signal generator circuit
Clock circuits

4017 decade counter (1-of-10)

CD4017 pin The count advances as the clock input becomes high (on the rising-edge). Each output Q0-Q9 goes high in turn as counting advances. For some functions (such as flash sequences) outputs may be combined using diodes.

 The reset input should be low (0V) for normal operation (counting 0-9). When high it resets the count to zero (Q0 high). This can be done manually with a switch between reset and +Vs and a 10k resistor between reset and 0V. Counting to less than 9 is achieved by connecting the relevant output (Q0-Q9) to reset, for example to count 0,1,2,3 connect Q4 to reset.

 The disable input should be low (0V) for normal operation. When high it disables counting so that clock pulses are ignored and the count is kept constant.

 The ÷10 output is high for counts 0-4 and low for 5-9, so it provides an output at 1/10 of the clock frequency. It can be used to drive the clock input of another 4017 (to count the tens).

4026 decade counter and 7-segment display driver

CD4026 pin The count advances as the clock input becomes high (on the rising-edge). The outputs a-g go high to light the appropriate segments of a common-cathode 7-segment display as the count advances. The maximum output current is about 1mA with a 4.5V supply and 4mA with a 9V supply. This is sufficient to directly drive many 7-segment LED displays. The table below shows the segment sequence in detail.

 The reset input should be low (0V) for normal operation (counting 0-9). When high it resets the count to zero.

 The disable clock input should be low (0V) for normal operation. When high it disables counting so that clock pulses are ignored and the count is kept constant.

 The enable display input should be high (+Vs) for normal operation. When low it makes outputs a-g low, giving a blank display. The enable out follows this input but with a brief delay.

 The ÷10 output (h in table) is high for counts 0-4 and low for 5-9, so it provides an output at 1/10 of the clock frequency. It can be used to drive the clock input of another 4026 to provide multi digit counting.

cd4026 display chart
4026 display chart

CD4073 triple 3-input AND Gate

CD4073 internal
CD4073 pin

The 4073 has three separate 3-input AND gates which you can use independently.

Truth table

The truth table of each individual gate is:
C B A Output
0 0 0
0 0 1 0
0 1 0 0
0 1 1    0
0    0
1 0 0
1 1 0    0
1 1   1 1

where '0' represents a LOW voltage, and '1' represents a HIGH voltage.

Basic operation

You can investigate the behavior of a single 3-input AND gate using this circuit:

3-input AND gate operation
The inputs of the gate must be connected, either to LOW or to HIGH, and must not be left open circuit. This is the function of the input switches with their pull-down resistors. To avoid loading the output of the gate, a transistor switch indicator circuit should be used. It is good practice with CMOS circuits to insert a decoupling capacitor, 47µF or 100µF, across the power supply. (This helps to prevent the transfer of spikes along the power supply rails.)

UM348X

UM348X  pin
The UM348X series is a mask-ROM-programmed multi instruction melody generator, implemented in the CMOS technology. They are designed to play the melody according to the previously programmed information and capable of generating 16 songs with 3 instrument sounds, the piano, the origin and the mandolin.

The devices also included a per-amplifier which provide simple interface to the driver circuit. The UM348X series is intended for applications such as toys, door bells, music boxes, melody clock/timers and telephones


Month and Date Reset

Month and Date Reset Circuit
Month and Reset Circuit
This is a newly added circuit and use 16F628A micro-controller. you have to program it before use. the purposes of this circuit are show month and reset date according to the month. Ex: Jan 31, Feb 28, Etc. PIC use its internal oscillator and circuit is very simple. To save pins, Month shows binary format.
Ex: 1=0001, 2=0010, 3=0011, etc.
For power supply and more details please refer device datasheet. 


Code

/******************************************************************************* Month and Date Reset - 16F628A Copyright (C) 2014 Praneeth Kanishka This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses >> Email: scorpionzblog@gmail.com >> Web : http://scopionz.blogspot.com *******************************************************************************/ int count=1, month=1, date=1; const char day_month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; // Interrupt Service Routine (ISR) void interrupt() { if (INTCON.INTF) // Check for interrupt { PORTA.F2=1; count=count+1; delay_ms(5); PORTA.F2=0; if(count>day_month[month]) { count=1; if(++month>12) month=1; PORTA.F3=1; Delay_ms(5); PORTA.F3=0; PORTA.F2=1; Delay_ms(5); PORTA.F2=0; } PORTB = month<< 0x07="" a0="" clear="" cmcon="" comparators="" delay_ms="" disable="" flag="" if="" intcon.intf="0;" intcon="0b10010000;" interrupt="" interrupts="" main="" month="" nable="" option_reg.intedg="0;" pcon.oscf="1;" porta.f2="0;" porta="0x00;" portb="month<<4;" rb0="" trisa="0x03;" trisb="0x01;" void="" while="" z="">12) month=1; PORTB = month<< count="" delay_ms="" if=""> day_month[month]) { count=1; PORTA.F3=1; Delay_ms(5); PORTA.F3=0; } PORTA.F2=1; Delay_ms(50); PORTA.F2=0; Delay_ms(400); } } }

Friday, July 27, 2012

12 24Hr Big LED Digital Clock Circuit - 16F84

Few years ago I build a 24Hr clock using logic ICs. It’s work nicely but little complex to beginners. So I think build clock using pic IC. Check the below picture. Hope you like it.

16F84A digital clock preview
16F84 digital clock

It’s very easy to build and time accuracy is 99.999%. Because I use a clock circuit to generate the 1Hz pulse. It drive the clock. Use well smoothest power supply to give power to the circuit.

Preview of clock

Use '16F84A_12Hr.Hex' for 12 hour clock and '16F84A_24Hr.Hex' for 24 hour.

What is clock circuit?

I use the clock circuit to drive the clock because it is the easiest way to keep time accurately without using Real time clock IC such as DS1307. You can buy an ordinary clock machine in a shop. It is very cheap. Then open it and get the circuit out. That is the clock circuit! Connect outputs of clock circuit (winding of coil is connected to here) to P5 and P6, (+) to P7 and (-) to P8. That’s all.

1Hz clock generator
clock circuits

Now you can work in time. :D

PIC16F84A Datasheet

16F84A Pin
pin-out

 

on line

Labels

Recent comment

Visitors

Free counters!
Copyright © 2012 - Scorpionz™.,All rights reserved | Powered by Blogger