Quantcast
Channel: Clock - Timer Projects - PIC Microcontroller
Viewing all 218 articles
Browse latest View live

00 to 99 minute timer using PIC16F628A microcontroller

$
0
0

Last week I was browsing my old backup hard drive and I found a source code for a very simple PIC based digital timer that I made a couple of years ago. The actual hardware of the project isn’t with me anymore. I might have lost it when I moved from my old apartment into my new home. However, I thought this might be a good practice project for beginners and so I am sharing it here. I am not going to build it from scratch again; I will rather demonstrate it using my DIY PIC16F628A breadboard module and I/O board. The complete circuit diagram along with the firmware developed using mikroC Pro for PIC compiler is provided in the article.

99 Min Timer

Circuit diagram

As I mentioned earlier, the microcontroller used in this project is PIC16F628A running at 4.0 MHz clock using an external crystal. An HD44780 based 16×2 character LCD is the main display unit of the project where you can watch and set the timer duration using tact switch inputs. There are three tact switches connected to RB0 (Start/Stop), RB1 (Unit), and RB2 (Ten) pins. You can select the timer interval from 0-99 min using Unit and Ten minute switches. The Start/Stop switch is for toggling the timer ON and OFF. When the timer gets ON, a logic high signal appears on the RA3 pin, which can be used to switch on a Relay. The circuit diagram of this project is described below.

I am using my self-made breadboard module for PIC16F628A and experimenter’s I/O board here to demonstrate this project. Since there is no relay switch in the I/O board, I am connecting the timer output (pin RA3) to an LED. When the timer starts, the LED is turned ON. As the timer duration is elapsed, the LED is turned OFF.

 

For more detail: 00 to 99 minute timer using PIC16F628A microcontroller

Current Project / Post can also be found using:

  • timer projects using pic

The post 00 to 99 minute timer using PIC16F628A microcontroller appeared first on PIC Microcontroller.


Oscilloscope clock

$
0
0
An eight pin Microchip PIC microcontroller is programmed to operate from a 32768 Hz watch crystal and output waveforms which, when displayed on an oscilloscope, show the time in HH:MM:SS format. The screen capture shows winscope showing 12:46: …

Step 1: Design the character set

On an oscilloscope screen, vertical axis (up and down) corresponds to the magnitude of the voltage and horizontal axis (across) corresponds to time.

Letters and numbers are made visible by assigning a voltage to each dot, vertically, and using time to scan across it. If a dot is to be made visible, a particular voltage is output during its time slot. If the dot is invisible, a blanking voltage is output during that time instead. Oscilloscope clock

Since we are using a programmable microcontroller, the characters to be displayed will be held as dot patterns in its program memory. We thus have the freedom to design the character set for the clock. I have used a 7×5 matrix font, and used graph paper to design the characters.

It is simple. Just grab a pen and mark inside the squares of the 7×5 area, and try to make the result look like letters and numbers.

Get lots of paper, so that you can throw away your mistakes and start all over again.

Or, you can download the data sheet of some LCD controller ic and it will have all those character maps listed inside. Copy away, and no one will ever suspect that this work is not your own.

Step 2: Digitise each character

Now you have to convert each character into numbers to be incorporated into the microcontroller program. Each byte holds eight bits, so five bytes will hold one 7×5 matrix character as ones and zeroes.

A blank square is zero. A filled square is a one. One bit in each byte will remain unused.

The microchip assembler directive “dt” will cause the value following it to be converted into a “retlw” intruction.

The number in the form ” b’nnnnnnn’ ” will be interpreted as a binary number.

In this case, I have decided to make the top of the character be represented by the most significant bit of the byte.

This process will have to be repeated for each character that you wish to display.

Step 3: The program

I have made it in two parts: the character generator part is in a separate include file, “chargen.inc”, and the main program is the file “clock510.asm”. When you assemble it with MPLAB, you get the file “clock510.hex” which has to be programmed into a Microchip PIC12F510, PIC12F509 or PIC12F508. The same hex file will work for all three processors. The circuit is shown in ASCII form in the program itself.Oscilloscope clock schematic

Step 4: The circuit

The circuit is very simple. The eight pin microcontroller was mounted on a piece of scrap copper clad board after cutting out eight islands for the eight leads. An electrolytic capacitor was connected across the supply leads. A crystal taken from an old watch was fitted across leads 2 & 3. Two 15 pf capacitors are also to be fitted, but mine seems to work without it. Your Mileage May Vary. The MCLR/Vpp lead was pulled up to Vdd with a 10K resistor.

The remaining three leads connect to three resistors forming a crude weighted resistor DAC.

GPIO0 has a 47 K resistor.
GPIO1 has a 22 K resistor. This should be half the previous value, about 23.5 K, but this value is close enough.
GPIO2 has a 12 K resistor, close to the ideal value of 11K.

The other ends of the resistors are connected together, and I used a series resistor of 1 Megohm and connected it to the Line in jack of the sound card in my computer using shielded cable.

The thin wires in the picture are actually enamelled copper, and so will not short to one another if they touch. They go to

 

For more detail: Oscilloscope clock

Current Project / Post can also be found using:

  • pic based nixie clocks
  • 16f628 timer example
  • pic a lcd a dcf 777
  • pic microcontroller tutorial clock

The post Oscilloscope clock appeared first on PIC Microcontroller.

Multimeter Clock

$
0
0

The Multimeter Clock consists of three multimeters, the first meter displays hours, the second displays minutes and the last displays seconds. A 16F628A PIC microcontroller keeps track of time and outputs a calculated current to each meter to display the current time.

Get your own Multimeter Clock Kit here.
See Multimeter Clock project page here.

Step 1: How it Works

The user enters the time by pressing three time adjust buttons. The first button increments the hours, the second button increments the minutes and the third button resets the seconds. Once the time has been entered the microcontroller will keep track of time from there. An interrupt fires every 10th of a second to increment a 10th second counter. Another routine checks to see if we have at least one full second of time, if we do the current time is incremented by a second.

The microcontroller has a separate output for each of the three meters. The meters are all in 0.5 DCmA mode, the negative lead of each meter is grounded and the positive leads are connected to a microcontroller output via a current limiting resistor. The resistor in this case is a 4.7K however this can be adjusted depending on the meter current scale available. Keep in mind that the PIC can deliver a maximum of 25mA to each meter so a meter with a lowest setting above 25mA would not work without additional circuitry.Multimeter Clock

Step 2: Building the Clock Circuit

The clock kit shown below can be purchased here.

Since the clock controller is built onto a perf board you have lots of flexibility on layout. Construct the circuit according to the schematic diagram. The PIC Microcontroller will need to be programmed with the Multimeter Clock firmware using a PIC chip programmer. When powered up the blue LED will give you a visual indication that things are working, during the power up phase the LED will light steady and as soon as the clock is running it will flash on for one second and off for one second.

The firmware was written in PICBasic Pro so you will need that language if you wish to make changes to the existing functionality. There is still about 20% of the 2K PIC code space still available so there is lots of space for some hacking.

The meter faces of the multimeters will need to be updated to show time scales. I used a program called MeterBasic by Tonne Software. To make a new meter face all you need to do is enter the measurements of the meter face, the name for the meter and scale information. In the end you have a perfect matching scale for your meter. You can download the Hour, Minute and Second faces that I created for this clock here.

Here are the parts you will need.

1 X Pre-programmed 16F628 chip.
1 X 18 pin Chip Socket
1 X 2X3 inch perfboard Circuit Board
1 X 2 position Terminal Block
5X 1N4401 Diode
1 X 100uF 12V Filter Capacitor
1 X 47uF 5V Filter Capacitor
1 X .01uF 5V Decouple Capacitor
2 X 22 pF Crystal Oscillator Capacitor
1 X LM7805 5V Regulator
1 X 20 mHz Crystal Oscillator
4 X 4.7K Ohm Resistor
1 X 1K Ohm Resistors
3 X Tactile Button
2 X 0.1 inch pin header (2 position)
2 X 0.1 inch shorting jumper
1 X Blue LED
1 X 9 to 12 Volts DC Power Supply
3 X Analog type Multimeters, preferably with a 0.5mA setting

Step 3: Clock Schematic

Here is the schematic for the Multimeter ClockMultimeter Clock schematic

Step 4: Building the Clock Housing

To see more information about the V90 CNC machine that was used to build the housing have a look here.

The case was created using multiple layers of 1/2 inch MDF. There’s a front piece that has the actual Simpson 260 multimeter details v-carved into it. This is followed by 4 center spacer pieces and finally a back piece that has the hanging teardrop cutout.

The front piece was primed and painted with Krylon black paint before getting the details routed into it. All the other pieces were just routed in the CNC machine from raw MDF. I could have saved lots of wood if I built the sections from two pieces since the large center space in my design is wasted space but I decided to do it this way so that there will be no joints in the spacer pieces.

The black painted surface of the meter face was covered with contact paper then the details which will eventually be white were v-carved through the contact paper into the MDF. This provides a way of easily painting the fine white details using a spray gun.

 

For more detail: Multimeter Clock 

Current Project / Post can also be found using:

  • pic16f84a 0-99 up counting projects free download

The post Multimeter Clock appeared first on PIC Microcontroller.

Real Time Clock (RTC) Interfacing PIC18F

$
0
0

Introduction to RTC:

Real time clock also referred as RTC is an important device or integrated circuit which will keep the track of current time. RTC is mainly used in computers, mainframes servers and embedded applications (mobile phone, tablets, organizers, PDA etc).

The main function of the RTC is to keep the track of time of the device even though it is in off or turned off state. The best example is your computer, even though if you shut down your computer for really long time you can see the exact time on your desktop.

Battery is used as external power source and connected to the RTC, to keep the track of the system time even if your computer or embedded system is turned off.  If we use lithium battery as external power source RTC will work minimum 3 years even if your system is turned off.Real Time Clock (RTC) Interfacing PIC18F

Pin Configuration of PCF8563:

PCF8563 is a RTC and Calendar developed by NXP Semiconductor.PCF8563 uses bidirectional I2C (inter integrated circuit) for interfacing with other peripheral. The bus speed is 400 kbps and incremented automatically after each written or read data byte.

There are 8 pins which are on the IC as seen in the below figure

  • OSC1 and OSC0: These two pins connected by the 32.768 kHz crystal oscillator and which provide the source clock for the circuit.
  • INT: This pin mainly used to provide an external interrupt to the RTC. For example: in alarm application after the alarm occur it should set back to original state, to set back it to original state the user must give an interrupt to the RTC.
  • Vss: Ground
  • Vdd: Vdd is the pin where we have to give the supply voltage to the RTC. Battery is connected to the Vdd for uninterrupted power supply, even if the main supply voltage is turned off. The operating voltages are 1V- 5V.
  • CLKOUT: for all the application we cannot use 32.768 kHz clock for other application we may need small clock like 32 Hz, 1 Hz for microcontroller clock , input to the charge pump etc.
  • SCL and SDA: SCL is serial clock; SDA serial data pins which are mainly used to interface with the other peripherals through I2c (inter integrated circuit). Through these pins only data is exchanged between the other peripherals and RTC. Clock is given to the SCL and Data is given to the SDA.

Functional Features of PCF8563:

  • Provides year, month, day, weekday, hours, minutes, and seconds based on a 32.768 kHz quartz crystal.
  • Battery backup input pin and switch-over circuit.
  • Freely programmable timer and alarm with interrupt capability.
  •  Selectable integrated oscillator load capacitors for CL = 7 pF or CL = 12.5 pF.
  •  Internal Power-On Reset (POR).
  •  Open-drain interrupt or clock output pins.
  •  Programmable offset register for frequency adjustment.

PIC Microcontroller:

Peripheral Interface controller is developed by general instruments in the year 1975. Hardware architecture and reduced instruction set are used in it. Peripherals like ADC, PWM, OP-AMPS, TIMERS, CAPTURE/COMPARE and DAC etc are inbuilt in PIC microcontroller. Communication protocols like I2C, SPI (serial peripheral Interface) USART (Universal Synchronous Asynchronous Receiver Transmitter), CAN (Control Area Network), ETHERNET are used to communicate with the other external peripheral which are connecter to the PIC micro controller.

PIC is available in different architectural like 8 bit, 16 bit, 32 bit. According to the application we can use the architecture.

PIC 18F45K80 is a PIC 16 bit microcontroller developed by microchip and it belong to PIC 18F66K80 family. PIC 18F45k80 has 40 pin in PDIP (Plastic Dual Inline Package) and 44 pin in TQFP (Thin Quad Flat Package).

PIC 18F45K80 Features:

  • Program memory of 32 Kbytes and data memory of 3648 bytes
  • 40-44 pins and 35 I/O pins
  • Operating Voltage Range: 1.8V to 5.5V
  • On-Chip 3.3V Regulator
  • Operating Speed up to 64 MHz
  •  Up to 64 Kbytes On-Chip Flash Program Memory
  • Five CCP/ECCP modules
  • Five 8/16-Bit Timer/Counter modules  and Two Analog Comparators
  • Configurable Reference Clock Output
  • Charge Time Measurement Unit (CTMU) and  One Master Synchronous Serial Port (I2c and SPI)
  • Two Enhanced Addressable USART modules 12-Bit A/D Converter with up to 11 Channels Data Signal Modulator module.

PIN Diagram of PIC Microcontroller:

Related Post: PIC Microcontroller Architecture

Interfacing PIC with RTC:

Connect the RTC SDL and SCL pins to the PIC controller pins through the pull up resistor (Pull up resistor is nothing but giving the voltage to the resistors (5k – 10k) to the SDL and SCL wires, here we should give VCC voltage which is 5v).  Using the serial interface we can see the output in the terminal.Real Time Clock (RTC) Interfacing PIC18F schematiche

Circuit Diagram:

So by seeing the circuit we can easily understand how the connections are given. But care should be taken with the resistance value. The total project can be divided into three steps

  • Interfacing PIC18F to RTC.
  • Interfacing UART to PIC18F for serial communication purpose to see the RTC output in HyperTerminal of PC.
  • Interfacing RTC output to the Serial communication.

NOTE: same circuit and code can be used for PIC 16F and PIC18F series. In the code you have to change the pin configurations only in the initialization functions.

 

 

For more detail: Real Time Clock (RTC) Interfacing PIC18F

The post Real Time Clock (RTC) Interfacing PIC18F appeared first on PIC Microcontroller.

HC08 Fan Timer using pic microcontroller

$
0
0

Build a timer with Motorola Nitron MCU and using ICC08 to develop c program. Loader schematic also included. New s-record for 8-pin 68HC908QT2!
My son got his fan in the bedroom. The fan has mechanical timer for 0-180mins. One day it broken. So I got the idea to use Nitron chip to replace the mechanical timer. Someone may ask me why so complicated timer made by microcontroller chip? Actually we can build a timer with 555 and a 14-stage cmos counter! The 555 runs astable with time constant controlled by RC and for long period timing we can divide the output frequency of 555 by a cmos counter. That was my homebuilt timer 20 Yrs ago. Such circuit needs a number of passive components. We will see the hardware for timer with Motorola Nitron chip, it is only 16-pin MCU and one decoupling cap. All passive components and timing function are replaced with c coding

HC08 Fan Timer Hardware Schematic

The loader circuit is shown in the block. The hardware settings (external clock with high voltage) forces Nitron chip to run in monitor mode. The IRQ(PTA2) ties to pin 2 of MAX232 to provide HV signal. The external oscillator is required for 9600 BAUD send/receive monitor command via PTA0. It made with CMOS inverter 74HC04 and xtal 9.8304MHz. PTA1 and PTA4 also are required. The free software loader, PROG08SZ V1.7 can get from http://www.pemicro.com/.

The HC08 Fan timer circuit is shown below the loader. The Nitron chip is MC68HC908QY4, 16pin PDIP. When using the ICC08 program, you can choose the programming algorithm with QY4, say. R6 is 10k POT B type tied to the AD0, analog input channel0. It used to set time from 0Hr to 5Hrs. The output relay driving circuit is PTA3. A small NPN transistor drives a 12V electromechanical relay. D2 provides a path for back EMF current flowing when Q2 is turned off. C3 is multilayer 0.1uF decoupling cap. The Nitron chip has internal clock, power reset, low voltage detection, watchdog. You may learn more features from Niron Data sheet.

Zero Power Standby

Figure 2 shows a sample schematic featuring zero power standby. By using a push button S1 to make K1’s contact closed when S1 was pressed. The K1’s contact will close and latch with period setting by R6. When time-out the K1’s contact will open thus turns itself power off. To restart timer, just press S1 again.

Software

As shown in the schematic, we see that the timer circuit has only one 16-pin MCU, so all timing functions are done by program.

HC08 Fan Timer

/*  timer.c firmware for cheap timer using Nitron chip
  MC908QY4CP 16-pin MCU
  compiled with icc08  Time setting is made by 10k POT, the analog input 0-5V.
  Time(mins) = (ADC reading *300)/255  Copyright (c) 2004 Wichit Sirichote, kswichit@kmitl.ac.th

*/
#include <io908QY4.H>

#define minute 7200// 120 ticks = 1 sec, so 7200 ticks = 1 minute

char count;char n,timer1;unsigned int timer2,timer3;unsigned char sec;unsigned int min, PV, save_time,set_time;char x1,x2,x3;char minute_pass;void disable_timer(){   if(set_time <5) PTA &= ~0x8; // off timer}void minute_clock(){   timer2++;   if (timer2 > minute)   {timer2 = 0;    minute_pass = 1;  }}void run_timer(){  if (timer3 > 10)  { PTA |= 0x8;// output high relay if (minute_pass == 1)    {  minute_pass = 0;
         timer3–;   }   }    else    { PTA &= ~0x8; // off relay    }

 

For more detail: HC08 Fan Timer

Current Project / Post can also be found using:

  • digital timer project
  • pic16f84 clock code

The post HC08 Fan Timer using pic microcontroller appeared first on PIC Microcontroller.

PCF8573P I2C Real Time Clock

$
0
0

In this post I’m going to show you how to interface an I2C Real Time Clock – RTC with PIC microcontroller. Only a basic hardware configuration and a communication protocol are presented here. I’m planning to extend it to a more advanced design in a near future. PCF8573P I2C Real Time ClockAlthough PCF8573 was used a similar IC’s like PCF8583 will also fit with minimal changes to PIC software. The PCF8573 is a real time clock/calendar IC. Its addresses and data are transferred serially via the two-line bidirectional I2C bus. I2C communication was used in a number of projects like a Function Generator. Here a modified assembly code will read a minutes count from PCF8573 and show its binary value on LED bar graph connected to PORTB of PIC16F876A.

To set up a basic circuit only an oscillator and a small capacitor are required. See design schematic. PCF8573 I2C address 0xD0 is send by PIC. If ACK is received the minutes data is read by sending 0xD1 address and transferred to PORTB. (LSB is R/W bit). More detailed explanation can be found in attached assembly code at the bottom of the page, also look at full Data Sheet for comprehensive functional description of RTC, its timing specification and operation modes.PCF8573P I2C Real Time Clock schematich In a screenshot above you can see SCL – Clock and SDA – Data lines while I2C was active. Oscilloscope screen capture was taken with RIGOL DS2072 using its I2C Decoder and trigger mode.

Assembly code is available here. You may also be interested in SPI code example here or  UART implementation.

 

 

For more detail: PCF8573P I2C Real Time Clock

Current Project / Post can also be found using:

  • timer circuit using in microcontroller
  • digital clock circuit using pic16f84a program
  • home based rtc projects
  • led clock microcontroller programming

The post PCF8573P I2C Real Time Clock appeared first on PIC Microcontroller.

GPS-based universal clock generator using PIC16F628

$
0
0

GPS satellites and GPS Ground Segment need extremely accurate timing to allow GPS users to know their own position on the Earth. Rubidium and Cesium clock generators are extensively used and maintained to synchronize and generate the signals that our inexpensive navigator gets from the GPS satellites orbiting at 20000 Km. Many commercial systems use the same GPS signals to extract time marks or high-frequency clock references with atomic-like accuracy, and with the appropriate hardware this opportunity is available also for amateurs and hobbysts. With the project described in these pages, the microwave frequency counters and signal generators we have in our home-labs will have an absolute accuracy in the range of 10ppb (parts-per-billion) without relying on external calibration facilities.

universal clock generator

OPERATION PRINCIPLES

Almost all commercially available GPS OEM modules provide a 1pps output, synchronized with GPS time. This pulse could be used as a reference to generate accurate high-frequency clocks, but special design has to address the short-term jitter affecting the 1pps signal. As a general guideline, an oven-stabilized crystal oscillator who guarantees the short-term stability is synchronized with the GPS 1pps for the long-term accuracy.

An alternate, and simpler, solution uses the higher frequency synchronization signal (10KHz) that the Rockwell’s Jupiter GPS is able to provide. Ideally, a simple PLL frequency multiplier with a loop bandwidth in the range of 50~100mHz is all you need to complete the equipment. We have bought a couple of these modules on E-bay and we started some experiments with them.

PROJECT DESCRIPTION

The projects is straightforward and basically simple. As anticipated in the previous section, it is a PLL multiplier with few auxiliary blocks to get more flexibility and to monitor the GPS status without the need of a PC.

The /2000 divider of the PLL has 8 taps at most used frequencies from 10KHz to 20MHz: an output selector controlled by the uP forwards the selected one to the main output of the equipment. One or more auxiliary outputs at fixed frequency can also be implemented to drive more instruments that need different master-clock frequencies. The PLL loop bandwidth is intentionally limited to 1/10~1/20Hz to cut-off short-term frequency jitter of the 10KHz GPS reference. As a consequence, a VCXO (Voltage Controlled Crystal Oscillator) has been chosen to avoid all instabilities and drifts outside the loop bandwidth. No temperature stabilization has been adopted: the only precautions taken have been to supply the VCXO with a dedicated 5V regulator and to keep it in a closed box protected from sudden temperature variations. A varicap in series with a 20MHz crystal gives a ±300Hz correction range, therefore excess drifts at extreme cold or warm ambient temperatures could not be corrected by GPS synchronization. A larger correction range could be reached, in theory, but at the price of oscillator Q reduction and, as a consequence, a greater phase noise that could prevent the use of this clock generator for LO generation in narrow-band microwave transverters. A LOCK signal turns-on an indicator LED and informs the uP that the phase loop is locked.

 

For more detail: GPS-based universal clock generator using PIC16F628

Current Project / Post can also be found using:

  • pic16f877 digital clock downloads

The post GPS-based universal clock generator using PIC16F628 appeared first on PIC Microcontroller.

Making a binary clock using a PIC Microcontroller

$
0
0

You can use a PIC microcontroller and an LED matrix to create a binary clock (or if you prefer you can wire up individual LEDs).

This project uses an LED matrix block as it saves lots of wiring.  So what is it ?

Its an led clock that displays the time information as binary numbers…

Making a binary clock using a PIC Microcontroller
…and it is a good way of learning how to read binary (well up to 9 any way!).

You can represent the numbers 0-9 using 4 binary digits so only four leds are needed for each time digit. There’s a binary-decimal conversion table here.

To display hours, minutes and seconds (2 digits each) you need 6 binary digits in total (depending on whether you use a 24 hour clock the top digit needs only 1 or 2 LEDs).

How to read a binary clock

the time is displayed in 24 hour mode so:

  • The 1st two digits represent 0-23 hours,
  • The next two digits represent 0-59 minutes,
  • The next two digits represent 0-59 seconds.
Binary Clock digit defiinition
Hours
MSD 0-2
Hours
LSD 0-3
Minutes MSD 0-5
Minutes LSD 0-9
Seconds MSD 0-5
Secondss LSD 0-9
Making a binary clock using a PIC Microcontroller(MSD,LSD Most Significant Digit, Least Significant Digit)

Note: You could use a 5×7 led matrix as only the right hand 4 leds (also only 6 rows)are used in this project.

The black rectangle, in the diagram above, shows which leds you need to look at – the rest are not used in this project.  You read the clock starting from the top and read horizontal row of four LEDs as a binary number. Each LED that is on represents a one and each LED that is off represents a zero. You then use the conversion table to translate it into decimal until you become so good at it that you won’t need the table!

 

For more detail: Making a binary clock using a PIC Microcontroller

The post Making a binary clock using a PIC Microcontroller appeared first on PIC Microcontroller.


Relay Timer with PIC16F628

$
0
0
Here is 0 to 99 minutes relay timer using PIC16F628 microcontroller and 16 character LCD display. The microcontroller is PIC16F628A running at 4.0 MHz clock using an external crystal. An HD44780 based 16×2 character LCD is the main display unit of the project where you can watch and set the timer duration using tact switch inputs.Relay Timer with PIC16F628 There are three tact switches connected to RB0 (Start/Stop), RB1 (Unit), and RB2 (Ten) pins. You can select the timer interval from 0-99 min using Unit and Ten minute switches. The Start/Stop switch is for toggling the timer ON and OFF. When the timer gets ON, a logic high signal appears on the RA3 pin, which can be used to switch on a Relay. The circuit diagram of this project is described below.
Relay Timer with PIC16F628

Build Accurate LC Meter and start making your own coils and inductors. This LC Meter allows to measure incredibly small inductances making it perfect tool for making all types of RF coils. Relay Timer with PIC16F628 schematichLC Meter can measure inductances starting from 10nH – 1000nH, 1uH – 1000uH, 1mH – 100mH and capacitances from 0.1pF up to 900nF. The circuit includes an auto ranging and reset function to make sure the readings are as accurate as possible .

For more detail: Relay Timer with PIC16F628

Current Project / Post can also be found using:

  • realtime clock using pic18 abstract
  • microchip pic hd44780 assembly
  • pic 18f1220 assembler projects

The post Relay Timer with PIC16F628 appeared first on PIC Microcontroller.

Digital DCF77 clock with LCD and gong using PIC16F628A

$
0
0

Always the right time and date with DCF77

This project make use of a PIC16F628(A) and a DCF77 receiver from Conrad (Orderno. 64 11 38)

Optional there is a possibility to connect an electronic gong on it.
Click for information about DCF77 on the link underneath:

The working from the DCF77 time signal

Connect the output from the DCF77 module with PORTB.0 (pin 6).
The pull-up resistor on the DCF77 output isn’t necessary because PORTB.0 internal pull-up is enabled.

Digital DCF77 clock

Every second is on PORTA.1 (pin 18) a pulse from 0.5 second.
This signal isn’t necessary for anything, but maybe you want to connect a LED on it, so that these wil blink every second, or a piezo buzzer, so that the clock ticks as an analog clock.

PORTA.0 (pin 17) is the daylight-saving time (DST) pin and is high when it is summer.
For the LCD’s 2×20 and 2×24 is it possible to print a W or S on the LCD in winter/summertime.

When connect PORTA.6 (pin 15) to +5V, the clock stays in 24 hours notation and if is choosen for 12 hours notation (AM/PM) then connect this pin with GND.

Use a HD44780 (or compatible) device for the LC-Display.
Download the .HEX file which belongs to the used LCD size.



When switching the power on, the PIC waits till it get a signal from the DCF77 module (receiver).


When searching does take more than 45 seconds, the message “No signal” follows.
The PIC stays searching until it have a decent timesignal reception.


When there is a signal found, it search to the begin from a new minute, this will take maximum 1 minute.
The timebar gives the left time.
If the whole timebar is full, then there is no startsecond found and the message “No signal” appears.


When the startsecond is found, the bits are gonna filled with time and date.
This takes exactly one minute.
If the whole timebar is full, the actual time and date is complete.


From now the day, time and date can be read.


If PORTA.6 (pin 15) is connected to GND the clock stays in 12 hours (AM/PM) notation.
The W stays for Wintertime (S for Summertime, DST).
There is a .HEX file with W / S and a .HEX file without this indication.


When the reception becomes worse or disappears, then also follows the message “No signal”.
The PIC still keeps trying to find the actual time back when the reception is good (again).


The basis
If only the time and date must be read from LCD without any fuss then build the circuit from scheme 1.
Adjust the contrast from the LCD with P1.

 

For more detail: Digital DCF77 clock with LCD and gong using PIC16F628A

Current Project / Post can also be found using:

  • DIY Connecting PIC18F2550 to Serial LCD Displays
  • pic 18f452 c rogram lcd
  • Real time clock in pic18f452 projects using mp lab

The post Digital DCF77 clock with LCD and gong using PIC16F628A appeared first on PIC Microcontroller.

Countdown Timer using PIC16F690 microcontroller

$
0
0

This is a simple countdown-timer-on-a-chip project – you program the PIC, attach some buttons and a pair of 2-segment LEDs, and you are done.

countdown timer

I used this timer for one of my projects, but I tried to make that timer as generic as possible, so it can have other applications. On this site I describe only the timer itself – code, pinout, and operation. If you want to see something built with the timer, check my Air Sampler project.

Give it a try:

Specification


  • Two digit LED display with maximum count time of 99 units (units are configurable and can be seconds, minutes, or hours).
  • Start/Stop/Increment/Decrement buttons working in press and press-and-hold mode.
  • Optional Increment-by-ten/Decrement-by-ten buttons.
  • Pause and resume.
  • Add or subtract time while timer is running.
  • One output to control an external device or signal time state.
  • One unused pin – you can customize the code to make use of it as an either input or output.
  • Works with a cheap 3.579545 MHz (NTSC) crystal, easily adjustable to other frequencies.

You can give it a try right now – the widget on the right is a fully-operational simulation of the timer, configured to count seconds. Adjust the time using the +1, -1, +10, and -10 buttons. Start the timer with the SET button. Pause, stop, or clear timer by pressing RST. Pressing and holding a button works as you would expect from any timer. The green LED will show you when the timer is working – in real life, instead of the LED you will most likely have some device controlled by the timer.

If you have questions or comments, or if you have found an error on this site, please let me know. My e-mail is at the bottom of the page.

 

For more detail: Countdown Timer using PIC16F690 microcontroller

Current Project / Post can also be found using:

  • countdown timer ic chip 10 hour

The post Countdown Timer using PIC16F690 microcontroller appeared first on PIC Microcontroller.

PIC based WWVB clock

$
0
0

Introduction

There are many DIY versions of WWVB clock designs available on the web. Commercial “atomic” clocks are inexpensive and widely available, but I wanted to try my hand at designing one to gain insight into WWVB reception and to learn a little about programming a PIC microcontroller. My version is not the simplest available, but it works well and I think it offers a few unique features.PIC based WWVB clock

WWVB Clock Features

  • Receives time broadcast from WWVB, Fort Collins, CO
  • Auto synchronizes internal time with WWVB time
  • Maintains local time when WWVB signal is lost
  • This version is for Pacific Standard Time, and auto detects/corrects for Daylignt Savings Time
  • 6-digit display of hours, minutes, seconds using 1″ seven-segment LED displays
  • WWVB sync indicator
  • Time display is in 12-hour format
  • PIC 16F628 microcontroller
  • Software written in C
  • All tools (schematic editor, C compiler, PCB layout software, PIC programmer are free and available for download on the web.

A complete description and specification for the WWVB broadcasts is available (free), document # 432, attf.nist.gov/general/pdf/1383.pdf The WWVB signal is broadcast as a 60 kHz carrier that is AM modulated with a time code frame that is updated once per minute. The data rate is one bit per second. Along with time code information, the data frame also contains synchronization bits, calendar data, UT1 correction, leap year, and leap second data. The clock design presented here only decodes the time data and daylight savings correction data. The software could easily be modified to include decoding of the other information bits, if desired. The the low frequency WWVB signal strength is weak and reception can be problematic. Signal acquisition time is variable, depending on location and atmospheric conditions. Reception is usually best at night between 8pm – 4am. To use the clock, just apply power and wait for reception of the WWVB signal. When the clock receives a complete error-free frame of data, it will automatically reset the display to show the correct time. After the initial time correction, the clock will maintain time even if WWVB reception is lost.

Hardware Description

As shown in the schematic (pdf format), the heart of the clock is a PIC 16F628 microcontroller running at 4 MHz. Decoded time data is sequentially output from the microcontroller (RA0 – RA3) to the 7-segment decoder/drivers on a 4-bit data bus. The data is output sequentially as seconds, 10s of seconds, minutes, 10s of minutes, hours, and 10s of hours. The microcontroller outputs (RB1, RB2, RB3) route a 10 uSec stroble pulse from RB4 out to each of the 7-segment decoder/drivers at the proper time to latch the data bus values. Seconds and 10s of seconds display values are updated once per second. Minutes, 10s of minutes, hours, and 10s of hours are updated once per minute. The display consists of 1″ red-orange LED 7-segment displays. The decimal points on the displays are used to form colons to separate the seconds, minutes, and hours. The 10s of seconds and 10s of minutes displays are mounted upside down to form the upper colon dots. The WWVB receiver is a C-MAX model CMMR-6 and is available from Digi-Key (www.digikey.com) as part # 561-1014-ND complete with loopstick antenna. Data output from the receiver is sampled by the microcontroller on RB0.PIC based WWVB clock schematich

Construction

I have built two of these clocks, one using point-to-point wiring and one using a pcb. Both versions perform well. Just keep the receiver away from noise sources and the wire / trace lengths short to minimize inductance. I found that the receiver is also sensitive to magnetic fields produced by power supplies. I used a 9V, 200 mA “wall-wart” instead of an internal power supply to eliminate this problem.

My pcb was designed using Free PCB software www.freepcb.com. The artwork contains both the main board and the display board on a single layout to save the cost of two separate boards. I purchased the pcb from www.4pcb.com by sending them the gerber files and using their “bare-bones” process. The “bare-bones” process does not include solder mask nor silk-screen. Just cut off the display board from the main board and mount it at a right angle to the main board and wire them together using the pads provided.

For more detail: PIC based WWVB clock

The post PIC based WWVB clock appeared first on PIC Microcontroller.

Real Time Clock Circuit using Mircocontroller

$
0
0

Here I am going to teach you a simple circuit of 24 hour digital clock display that can also be used in 12 hour format by simply loading the corresponding clock program. You can download the hex files for both 12 hour format and 24 hour time system from the link given in this article. Coming to the technical part, main component of the circuit is a PIC16f84A microchip; it generates the one second clock to run the device and also controls the seven segment display. Three push buttons are also provided to set the time; one for reset by which you can reset the complete circuit as it is connected to the reset pin of PIC microcontroller. Other two push buttons are for setting hour and minute. By Pressing these button continuously you can increment hour and minutes.

Real Time Clock Circuit using Mircocontroller

The main feature of this real time clock circuit is that it only draws less than 100mA, so it can be run with rechargeable batteries. By increasing the value of resistors connected to the seven segment display you can decrease the current gain. 24(international time clock) to 12 hour time clock conversion can be done simply by burning the PIC microchip with the corresponding hex file.

Download Hex file of real time embedded C

The hex file for both 12 hour and 24 hour time clock are available at our Download Center.
(In case you are facing any problem in downloading the files, use the comment box at the bottom
Download link Updated: 14/June/2013)

Circuit diagram of Pacific Time clock

Click on the circuit for enlarged view

Real Time Clock Circuit using Mircocontroller Schemetic

Components Required

  1. PIC 16F84A
  2. Transistor BC548 (4-Nos)
  3. Resistor (180R-9Nos,10K,1K-4Nos)
  4. LED
  5. Capacitor(22pf2Nos)
  6. Push button (3-Nos)
  7. Crystal 4MHz
  8. Common cathode seven segment display (4-Nos)

 

For more deteail: Real Time Clock Circuit using Mircocontroller

Current Project / Post can also be found using:

  • 16f84 clock & date project
  • connecting pic with timer

The post Real Time Clock Circuit using Mircocontroller appeared first on PIC Microcontroller.

Minidot 2 – The holoclock using PIC16F88 microcontroller

$
0
0

Minidot 2 – The holoclock

Well maybe holoclock is a little bit inaccurate….it does use holographic dispersion film on the front to give a bit of depth.

Basicaly this instructable is an update to my previous Minidot located here:
http://www.instructables.com/id/EEGLXQCSKIEP2876EE/
and re-using a lot of code and circuitry from my Microdot located here:
http://www.instructables.com/id/EWM2OIT78OERWHR38Z/

EagleCAD files and Sourceboost code is included in the zip files attached.

The holoclock
Why? The previous Minidot was overly complex, from the Microdot I learned how to do an RTC on a PIC using only a 32.768 crystal and didn’t need to use a special RTC chip. Also I wanted to get rid of the display chips from the previous Minidot. So now there is only a power regulator chip and a PIC16F88….just two chips.
The other reasons for an update were my Minidot was getting a bit un-reliable because of the seperate switch board and I wanted a soft fade between dot patterns as well as some sort of ambient light sensor to dim the display at night. The other Minidot was fixed brightness, and illuminated a room at night.

The device was constructed with the aid of the EagleCad software package and Sourceboost compiler. You’ll need to have some experience with electronics and programming PIC controllers to start this project. Please note this isn’t an instructable on either electronics or PIC programming, so please keep questions relevant to the Miniclock design. Refer to the instructables above or many other instructables on this site for advice on using EagleCad or programming PICs.

So here it is…..Minidot 2, The Holoclock……or Minidot The Next Generation………….

 

The circuit

This circuit is very simliar to the Microdot. Note the charlieplex array is virtually identical…only a few pins have been moved.

A 20Mhz crystal has been added to the Microdot circuit to clock the PIC much faster, this allows the array to be scanned faster and enables the implementation of a dimming algorithm. The dimming algorithm was very important to getting a cross pattern fade and ambient light function to work. This would have been impossible with the Microdot, because of the slower clock speed as some scan cycles needed to be spent on dimming. See next section for a description of the Dimming functionality.
Schematic The holoclock
The other things to note are the use of a MCP1252 charge pump regulator to supply 5V, my favourite chip at the moment. If you modified the circuit you could use a plain old 7805……I just have a number of these handy chips hanging around.

I’ve now moved the switches to the front, saves fiddling round the back of the clock after power dropouts to reset the time and now everything is only one PCB….no cabling issues.

Also of note is the inclusion of an LDR. This is used in a voltage divider which is sensed by the A/D pin on the PIC. When the PIC senses the ambient light level is low (ie night time) the dimming algorithm keeps the charlieplex array dark for more cycles than when the light level is high. I couldn’t find an LDR symbol in the Eaglecad library, so I just used an LED symbol…..don’t be fooled it’s an LDR. See actual picture of the PCB below.

One thing to note when using multi-coloured LEDs in a charliplex array. You need to make sure the forward voltage of the LEDs are more or less the same. If not, then stray current paths may occur and multiple LEDs will light. Thus using 5mm or higher power LEDs for this configuration will not work as there is usually quite a difference between the green/blue LEDs and the red/yellow LEDs. In this case I used 1206 SMD leds and high efficiency green/blue LEDs in particular. The forward voltages were not an issue here though. If you wanted to use a mix of green/blue and red/yellow higher power LEDs in a charlieplex array you’d need to seperate out the different colours into two charliplex arrays.

There are numerous explanations of charlieplexing that can be googled……I’ll not go into details here. I’ll leave it to you to do some research.
(Press the little ‘i’ icon in the corner of the pic below to see a larger version)

The dimming algorithm – charliplexed pulse width modulation

As mentioned earlier, I wanted to have the different dot patterns for the time fade smoothly rather than jerking from one pattern to another.

See the video for a demonstration. In the middleis the new Minidot clock, on the right is the older Minidot. Notice how much nicer the new one is.

The post Minidot 2 – The holoclock using PIC16F88 microcontroller appeared first on PIC Microcontroller.

Time Display unit for a GPS module using pic microcontroller

$
0
0

I decided to build a device to permanently display accurate time received from a cheap GPS module installed in my workshop. Having obtained a PIC18F1320 microcontroller for experimentation, I wanted to learn about the new features of the PIC18F range using only minimal hardware to control the display. I am currently using it with the on-chip 8Mhz oscillator only and driving a six digit led display, multiplexed with further saving of chip pins by a technique pioneered by Charlie Allen of Maxim-Dallas for their MAX6951 LED display drivers called “Charlieplexing” (see their application note AN1880). I would have liked to have used a MAX6951 chip for better display brightness, but they appear to be only available in “Quarter Size Outline Packages” (QSOP) – the leads are very close together,not easy to experiment with. Another alternative would be to use a MAX7219 display driver, this chip has a serial interface and an option to adjust the display brightness – something I may try later.

Time Display unit for a GPS moduleFeatures
Simple design, few components, no surface-mount types.
UTC time configurable to different time zones with DST option
Low power consumption
Uses modern Microchip PIC 18F1320 microcontroller
Selectable 12 or 24 hour time display modes
Leading zero blanking option
AM/PM indication in 12 hour mode
GGA and RMC sentence status indication

Circuit Description
The microcontroller receives serial data from a GPS module at the standard rate of 4800 Baud.
It parses the NMEA 0183 Standard data sentences, looking for only two types of sentence – RMC and GGA. (These sentences must be sent by the GPS module every second for it to work.)
The RMC sentences include date and time information and GGA has Time and number of satellites received (no date information).
The serial time data sentences are only usually accurate to within a second, so a separate 1pps pulse from the GPS module is used to sync the seconds transitions.
(Note. Some GPS modules do not have a 1pps pulse output, these will not work with the current project firmware ).
(It has been tested ok with a Holux GM-82 module with TTL logic serial outputs.)

The controller drives the three (high efficiency) dual LED digit common cathode type display segments through series 510ohm resistors to help limit the current to remain within the 25mA per pin drive limit, together with the multiplexing action which effectively reduces the average current.
A disadvantage of this method is with the multiplexing and drive current limitations, the display is not very bright, requiring the use of high efficiency LEDs to achieve an acceptable brightness.

It is possible to increase brightness by the use of separate driver transistors for the display cathodes – but my initial tests found this produced some switching radio interference. (the MAXIM chips overcome that problem by using slew-limiting on their switching transistors).
Because the display cathodes share the same microcontroller outputs as the segments, the multiplexing action also switches outputs into high impedance (input mode) in addition to to high and low logic levels depending on which segments/cathodes are being driven.
Using the on-chip oscillator frees-up the two pins normally used for connecting a crystal to be used as ports instead.
Another extra (input only) port could have been gained by not using the MCLR pin – I decided not to do this as it can apparently cause problems when used with some types of PIC programmers (according to some web forum posts).

There are two tactile pushbuttons for configuration – a “SET” button to enter config mode and an “UP” button to increment the config values also show the date and number of satellites received.

The transistor (T1) Diode (D1)and resistor (R6) are provided to allow the unit to work with GPS modules that output the serial data using RS232 voltage levels. My GPS module outputs data at TTL logic levels (0-5v) so I have not used those components on my board yet (I will test it later by connecting to a PC emulating a GPS module).
The power requirements are very simple, It consumes less than 50mA with a 9V DC input (the 7805CT 5v regulator could be replaced with a smaller 78L05 type to save space).
The 470uF capacitor (C3) is only required if your DC power supply is not already smoothed.

Operation
When power is first applied, the display shows start-up information, including the project name and firmware version.
On receipt of 1pps pulses it will then show zeros while it waits for the GPS module to get valid satellite time. (this can take about a minute).
As soon as it has obtained valid data, it shows the time.
The red LED flashes to indicate the second pulses received from the GPS module.
Satellite time is UTC (GMT) time so there are options to change this:
Pressing the SET button will enter set-up mode and show an option to change to DST (Summer time) one hour advance.
The next press of the SET button allows the Time Zone offset (up to +/-15 hours) to be changed.
The next option toggles 12/24 hour time display mode.
The fourth option toggles leading zero blanking.
Changed settings are saved in eeprom and retained when switched off.
There are no other config options yet – I may add more later…

The DP led next to the second digit indicates an RMC sentence is detected ok.
The DP led next to the fourth digit indicates an GGA sentence is detected ok.
The DP led next to the last digit indicates time is PM (in 12 hour mode)
Time Display unit for a GPS moduleFirmware info
The firmware for this project is written in assembler language. The 18F1320 controller has 8Kb of memory, allowing up to 4096 instructions.
The current firmware occupies only about 25% of the available memory.
I found a few advantages to using 18F controllers, such as easier control of memory – no need to keep changing memory banks for accessing registers etc. and the additional commands make it easier to perform some tasks.
The downside is that some things are a bit more complicated – small tables are now not so simple because every entry uses two bytes of memory (It does provide some powerful commands for working with tables though).
The extra complexity added to some features such as interrupts and timers etc. can cause a few slight problems,requiring careful studying of the data sheets.

In addition to reading the 18F1320 datasheet, a more detailed coverage of 18F features can be found in the 976 page PICmicro® 18C MCU Family Reference Manual (39500a.pdf) which is available from the microchip website.

Another useful document is Application Note AN716 which explains the differences encountered when migrating from 16F to 18F devices.

I have a few ideas to expand the software features for this project and/or use them in future projects – when I have time..

For more detail: Time Display unit for a GPS module

Current Project / Post can also be found using:

  • PIC16F84A program for clock

The post Time Display unit for a GPS module using pic microcontroller appeared first on PIC Microcontroller.


How to use Timers in PIC18F4550 Microcontroller

$
0
0

Timers as the name suggests pertain to time-related operations. They are mostly used for exact delay generation. Timers are also used in various other operations like PWM signal generation, auto-triggering of several other peripherals etc. The working and configuration of PIC18F4550 Timers have been explained in this article.

Timers are the most essential peripheral for a microcontroller and every controller provides a provision for using them. Beginners are advised to go through the tutorial on Timers before going any further.
For basic Timer operations, refer the Tutorial on Timers. PIC18F4550 is equipped with four Timers namely, Timer0, Timer1, Timer2 and Timer3. Before going for the details of Timer configurations, it is important to learn how time delay is calculated by the timer since exact delay generation is the most common application of Timers.
Timers in PIC18F4550
Time Delay calculation with Timer:
Example: Given that a time delay of 1 sec is to be generated and a 12MHz crystal oscillator is connected with PIC. Please note that this example considers external clock source for the controller, however, PIC18F4550 has provision for both external as well as internal clock source.
Timer is related to the internal frequency which is always Fosc/4.
Clock source frequency (Crystal)
Fosc = 12 MHz = 12000000 Hz
Therefore, Timer frequency :
FTimer = Fosc / 4 = 12000000 / 4 = 3000000 Hz = 3 MHz
If Prescaler = 1:256, then
FTimer= 3000000 / 256 = 11718.75 Hz
So, the time interval :
TTimer = 1 / FTimer = 1 / 11718.75 = 85 us (microseconds)
This means that when Timer runs, it will take 85 ?secs to increment its value at every count.
To calculate the value to be filled in Timer rolling over register to generate 1 sec delay :
No. of count for 1 sec Delay = 1sec / 85 us = 11718.75 = 2DC6H
 
So the value to be filled in Timer’s 16 bit register                  =          FFFF – 2DC6
=         D239
These values are filled in the Timer register and it rolls over up to FFFF. The values are reloaded again to start timer for same delay. Before filling this value timer registers should be configured as we shall see.
Each of the four Timers of PIC18F4550 has certain special features some of which are explained below. The detailed list of these features can be obtained from PIC18F4550 datasheet.
Timer0:
·         Timer0 can work as Timer/Counter in both 8-bit and 16-bit modes
·         Dedicated 8-bit, software programmable prescaler
·         Selectable clock source (internal or external)
·         Interrupt on overflow
Timer1:
·         Timer1 can work as 16-bit timer or counter
·         Readable and writable 8-bit registers (TMR1H and TMR1L)
·         Selectable clock source (internal or external)
·         Alternate clock source can be provided at Timer1 oscillator pins (T1OSO & T1OSI)
·         Interrupt on overflow
·         Timer1 can be multiplexed with other peripherals like ADC etc. and generates special event triggering for CCP (Capture, Compare and PWM) events.

The post How to use Timers in PIC18F4550 Microcontroller appeared first on PIC Microcontroller.

New Earth Time digital clock in recycled retro-modern case using PIC16F627A

$
0
0

New Earth Time (NET) digital clock in recycled retro-modern case

Ever get confused by GMT, or just wish you had a cooler way to keep track of time?  Build a New Earth Time clock!  Using a PIC microcontroller, some code, and a couple discrete parts, you too can have a unique timekeeping device to keep on your desk.

New Earth Time (NET) is an idea for a global time standard.  Like Greenwich Mean Time (GMT), it is the same “New Earth Time” everywhere on the globe at any instant.  Unlike GMT, NET counts time in Degrees and Minutes so as to not be confused with your local time (which is still counted the same way you’re used to).  You can read all about how New Earth Time works at their website, newearthtime.net .

It seems like a cool idea to me, and what better way to support the idea than to build a clock and start using New Earth Time!

Step 1

Parts

digital Electronic clock

You can see my prototype NET clock in the picture to get an idea of what’s involved.

Electronics:
1x – PIC16F627A Microcontroller
1x – 32.768kHz Crystal (Mouser 815-AB26T-32.768KHZ or equivalent)
2x – 22pF Ceramic Capacitor (or 1x 22pF and 1x 0-56pF Variable capacitor for tuning)
4x – 10k Resistor
7x – 100 Ohm Resistor
1x – 4.7k Resistor
5x – 1k Resistor
5x – 2n3904 Transistor
5x – Common Cathode 7-segment Display (Mouser 512-MAN6980 or equivalent)
2x – SPST Momentary pushbutton switch
1x – Round LED, modified as described in Step 2 (Making the degrees LED)

5V Power source (Wall adapter, or 9V battery regulated down with an LM7805 Regulator)

Other:
Case (My case came from an old electric blanket thermostat.  I love the cool retro-modern look about it)
Breadboard or Perfboard to construct the circuitry
Hookup Wire
A little bit of Heatshrink (the size of your LED) and a Sharpie Marker.

Tools:
PIC Programmer

Step 2

Making the Degrees LED

Because NET counts in Degrees, it is only appropriate to add a Degrees symbol after the Degrees display.

To make your own Degrees indicator, press a piece of un-shrunk heatshrink tubing onto the LED, so that the end of the tubing is about even with the top of the LED lens.  Don’t shrink the tubing!  Leave it just like it is.

Next, take a sharpie marker and color in the center of the LED lens. It usually works best to do this with the LED on, so you can see where you need more ink. It may take several coats of ink to get it dark enough that it blocks light. I find that a “dabbing” motion of the sharpie deposits the ink better that a “dragging” or writing motion.

When you’re done, you’ll have an LED that only lets light out from the edges – just like a Degrees symbol!

Step 3

Electronic Schematic

schematics digital Electronic clock

The schematic diagram (see picture) and electronic assembly are fairly straightforward since most of the “magic” happens in the microcontroller code.

Just like any digital clock, the microcontroller uses time-division multiplexing to control five 7-segment displays from only 12 I/O pins.  You can look up this scheme on the internet, but the basic idea is that only one display is on at any given time but our eye perceives all displays to be on simultaneously due to persistence of vision.  The displays are driven by 2N3904 transistors, since the PIC I/O ports can’t sink enough current for 7 LEDs.

In addition to the displays, there are two buttons multiplexed into the display outputs for the clock setting functions.  One button sets NET Degrees, the other sets NET Minutes.

The 32.768kHz crystal is the main timekeeping device for the clock.  You want to make sure you get a high-accuracy crystal, but even then you may need to adjust the value of C1 and C2 to keep time accurately.

I have included a small 5V regulator circuit in the lower corner.  If you have a 5V source already, this isn’t needed.

For more detail: New Earth Time digital clock in recycled retro-modern case using PIC16F627A

Current Project / Post can also be found using:

  • how many onbard timers are in th e pic16f690
  • microcontroller based timer circuit
  • pic microcontroller clock project

The post New Earth Time digital clock in recycled retro-modern case using PIC16F627A appeared first on PIC Microcontroller.

DIGITAL CLOCK CIRCUITS

$
0
0

A Digital Clock can be made easily by using PIC Microcontroller, DS1307 and a 16*2 LCD. I have already posted about Interfacing DS1307 RTC with PIC Microcontroller. The DS1307 RTC can work either in 24-hour mode or 12-hour mode with AM/PM indicator. It automatically adjusts for months fewer than 31 days including leap year compensation up to year 2100.  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. Communication between PIC Microcontroller and DS1307 takes place through I²C Bus.DIGITAL CLOCK CIRCUITS
Suggested Readings:

Circuit Diagram:

 Note: VDD , VSS of the Pic Microcontroller and VCC , GND of DS1307 are not shown in the circuit diagram. VDD, VCC should be connected to +5V and VSS, GND to OV as marked in the circuit diagram.

To simulate this project in Proteus you may need to connect I2C Debugger. SCL and SDA of I2C Debugger should be connected in parallel to SCL and SDA of DS1307. I2C Debugger can be found where CRO can be found in Proteus.
You can download the MikroC Source Code and Proteus Files etc at the end of this article. Here I explains the Source Code and different functions used in it.
The Three points to be noted while editing or creating program for this project:

  • DS1307 RTC is fully Binary Coded Decimal (BCD) clock/calender. So the data read from DS1307 should be converted to required format according to our needs and data to be written to DS1307 should be in BCD format.
  • Library for Interfacing LCD With PIC Microcontroller of MikroC needs Character or String Data. So data to be displayed in the LCD Screen should be converted to Character.
  • Addition and Subtraction cannot be directly applied on BCD. Here I am first convert BCD to Binary. Then addition and subtraction can be simply applied on Binary. Then the Binary is converted back to BCD.DIGITAL CLOCK CIRCUITS schematic

Functions that are used for reading and writing data from DS1307 are explained in the article Interfacing DS1307 with PIC Microcontroller please refer it. BCD2UpperCh() and BCD2LowerCh() are the two functions used to convert BCD to Character. Hour, Minute, Second, Date, Month and Year data are stored in DS1307 in separate 8-bit registers in BCD format. We read the data of these registers to access time/date. BCD2UpperCh() converts most significant 4 bits to corresponding character and BCD2LowerCh() converts least significant 4 bits to corresponding character.
The BCD2Binary() converts the BCD data read from the RTC to corresponding Binary for addition or subtraction and Binary2BCD converts the Binary back to BCD.
Bit 6 of Hour register is defined as the 24-hour or 12-hour mode selection bit.  When this bit is made high, 12-hour mode is selected and Bit 5 will represent AM/PM (Logic High represents PM).

 

 

For more detail: DIGITAL CLOCK CIRCUITS

The post DIGITAL CLOCK CIRCUITS appeared first on PIC Microcontroller.

A Real Time Clock IC (DS1307) project using the PIC micro.

$
0
0

Making A Real Time Clock (RTC) is simple if you use a helper chip such as a DS1307 because you do not need to keep track of the length of each month or account for leap years. It is all done for you, plus you get the benefit of a battery back up system that means it won’t lose the data or time when you turn off main power.

This PIC project uses an I2C (or IIC) Real Time Clock IC (DS1307) and a four digit seven segment display to create a standard desk clock.
Note: If you typed DS1703 Real Time Clock to find this page you probably mis-spelled the chip type.

Anyway you can find a DS1307 (RTC) Real Time Clock IC project and information on this page.

Note: This RTC project has been updated with easier to use software i.e. the software loaded into the PIC (Note the compiler is free for <2k and currently the code uses about 1550 bytes). There are also two additional modes one for information and one for debugging:A Real Time Clock IC (DS1307) project using the PIC micro schematic

The first new mode is found when pressing key 3 which will display an indication of what the current display is showing (sometimes it is hard to figure that out by just looking at numbers!). The second is when pressing key 4 which will cycle through all the RA0-RA7 output pins and show the LEDs lit on the 7-segment display. This means it is easier to figure out if the RA0-RA7 connections are correct when you wire it up (Note RA5 is not used as it can only be an input – see detail below). The project has also been updated to use the latest MikroC compiler 6.0.1

Specification

Accuracy Watch crystal spec typically 20ppm
Compiler Mikroelectronika MikroC Compiler Free!
Target 16F88 (re-targettable to other PICs that have Analogue input AN0).
Software level Medium.
Software notes Switching between i/p & o/p to read analogue/drive display. Using I2C routines.
Hardware level Easy.
Hardware notes Special care must be taken in placing the DS1307 and the crystal.
Project version 1.02

Real Time Clock IC : DS1307

Although the PIC16F88 has a built in oscillator for a 32kHz watch crystal a DS1307 is easier to use on a bread board. This is because you can control the layout of the circuit more easily.

The RTC also makes the software easier as it takes care of all calendar functions; accounting for leap years etc.

The DS1307 (RTC) Real Time Clock IC (an I2C RTC) is an 8 pin device using an I2C interface (although the data sheet does not mention I2C to avoid royalty payments!). It has 8 read/write registers that store the following information:

Address Register function
0 Seconds 0-59
1 Minutes 0-59
2 Hours 0-24,1-12
3 Day 1-7
4 Date 1-31
5 Month 1-12
6 Year 0-99
7 Control

Note: Addresses 0x08 to 0xf3 are user RAM and if you use a backup battery these are then non volatile ram i.e. they will save their contents after the power is off – so you have an extra 56 bytes of ram to play with! less the one used for storing the year high digits at 0x20– you could change this to not use the RAM but it is also used as an initialisation check – see the code.

Note: Address 3f is used in this project as a check to see if the clock needs initialising and to store the upper year digit (for easier coding).

The last address 0x08 is the CONTROL address and it determines what is generated at the SQW/OUT pin. You can control the level directly via I2C or set it to 1Hz, 4096Hz, 8192Hz, or 32768kHz. In this software it is set to 1Hz and used to drive an LED that can be used as a back light for the 4×7-segment module (if you shine a light through the module you’ll see the two central holes (like a colon character) that are between the left and right sets of two 7-segments. This is usually used to flash seconds so placing the LED behind this will achieve that operation.

In the same way as the I2C pins you need to add a pull-up to V+ at the SQW/OUT pin to see any output signal as it is an open drain output! or as in this circuit, an LED and 470R resistor are connected in series and to the +5V power. The other end goes to the SWQ/OUT pin of the DS1307.

Real Time Clock IC : Embedded control bits

There are two specific ‘gotcha’ type controls embedded in the addresses which make using the chip slightly more complicated.

Real Time Clock IC DS1307 : Clock halt / Minutes and Seconds register

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.

Note: You have to reset the CH bit to zero to let the chip operate!

Warning: The default state of the DS1307 is undefined
so you must clear the CH bit to start the oscillator.

In general you should leave this bit at zero and only set it if you have to. This bit is contained within register zero which is also the “minutes” and “seconds” register. In general keep this bit at zero unless you are updating the seconds part of the register (you don’t want the seconds changing while you are editing them).

Real Time Clock IC DS1307 : 24/12 Hour control

The second is the 24/12 hour control which is bit 6 of address 2. It is set high for 12 hour mode and low for 24 hour mode. In this project it is set low for 24 hour mode.

The problem with these two bits is that you have to preserve them when accessing the registers to write data and ignore them when reading out values for display. Its not a big problem and you can see how it’s done when you look at the code (see function edit_DS1307() and the 1st 2 case statements for address 0 (CH) and 2 (12H/24H) ).

Real Time Clock IC : 32kHz oscillator

Surprisingly making an accurate 32kHz oscillator is a difficult task (much more than a high speed oscillator e.g. a MHz crystal oscillator). 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 capacitively couple to the crystal wire).

Using the DS1307 lets you put the crystal in the least noisy part of the board. In addition it sets the crystal load capacitance which is critical in making the crystal oscillate at exactly 32kHz – controlling its initial error i.e. for the specified ppm error value the load capacitance must be exact.

Note: A common way of calibrating a crystal (not in this project) is crystal pulling or changing the capacitance at one crystal pin relative to the other – so load capacitance is crucial.

The DS1307 loads the crystal with 12.7pF so you need to buy a crystal that is defined to use this load capacitance. Circuit layout also affects the capacitance at the crystal pins so you must keep the crystal as close as possible to the chip and the tracks from crystal to chip must be short.

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.

If you are doing a board layout there is good advice in the PIC 16F88 datasheet (Timer 1 section) on crystal pcb guard rings. Dallas recommends Application note 58 which I have not read yet.

Real Time Clock IC : Power failure.

The DS1307 detects a power failure if its input voltage (Vcc) falls below (VBat) and automatically switches to the Vbat supply input (you should use a lithium 3V battery here as the backup battery). It also inhibits I2C control signals until Vcc is 1.25 x Vbat so you won’t be able to put bad data into the chip as the power is failing!

Input keys

To save microcontroller 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).

Note: This works because the analogue input is switched to receive analogue for only (150us approx) there is a 100us delay to let the inputs settle (just a guess and could be made lower – but it is not critical in this application). Then the input signal is read. Because of persistence of vision (on which the entire display methodology depends) your eye can not see this missing light pulse so it looks like the display is completely steady!

Each key pulls the analogue input to a different voltage level which you can easily read using the ADC (RA0).

7 Segment Display

The display is made up of four 7 segments built into a convenient block where all 8 led drive lines  are connected together. You could wire up individual 7-segments to achieve the same result but doing it on a soldered breadboard is a pain. The block just saves you effort (and errors in wiring).  So this results in 8 data lines and 4 digit select lines.

Initially I used RA0 to RA7 as the data line drivers and RB2,5,6,7. Then I realised that RA5 is only allowed to be an input because it is also multiplexed with the reset pin MCLR. Since it had been wired up this way the simplest solution was to eliminate RA5 but how do you do that without changing all the drive data definitions?

When eliminating RA5 I moved RA6 and RA7 down to bits b5 and b6 so this leaves the LED drive for the decimal point unconnected but that is OK since we are not using that part of the 7-segment display.

So the solution is to use a helper function that maps the bits 6,7 to bits 5,6 just before outputting the data to the 7-segment LED bus and the function has an obvious name:

move_b6_b7_to_b5_b6(Byte num)

Note: The other solution is to use RB0-RB7 to drive the LED data bus and RA0-RA4 for the column strobes and you can do this if you want to.
TIP: The MikroC IDE has a useful tool for generating the hex codes for segment drives in Menu–>Tools–>Seven Segment Editor.

Digit Select lines

The digit select lines are each driven by a transistor switch that allows more current if needed ( note I have not measured the exact current drawn as it depends on the refresh rate of the display).

Display Refresh and current limit resistors

Yes there are none! i.e. between the RA bus and the LED drives there are no limit resistors.

Why?

In all other circuits you can see them. I chose not to use them since the display is only ever driven in refresh mode. If it were driven directly then the LEDs would blow up.

If you are uncomfortable with this then add 8 off of 330R or 470R resistors to limit the maximum current to each LED (e.g. if the are driven permanently during testing) from each drive RA bus to the 4×7-segment display.

The reason that it works is to do with heat generated – as the current flows in the LED the junction heats up and if you drive too much current then it melts the internal wires – which is where the max. current limit comes from.

A Real Time Clock IC (DS1307) project using the PIC micro

When driving the display in refresh mode the display is held on for a very short time compared to the time it is held off and this defines an average current that is within the current limit of each LED.

Hey.. don’t knock it… it works fine…promise.

Note: The idea comes from chip design where the current drawn by the device depends on the switching speed of the system since for FETs maximum current is drawn when both upper and lower FETs in a switch are on i.e. during the transition from current level to next i.e. when switching.

Using the Real time Clock IC project

When the system powers up the ram location 0x3f is checked for value 0x20. If this exists then it means that the backup battery has saved contents of the RAM and all the registers have therefore been initialised. So the software skips the initialisation sequence.

Note: I am assuming you are going to be sensible and set the year high digits to 20 as V1.02 allows you to edit this value – just make sure it is 20 if you power down and up otherwise it will set up default values i.e. it will reset the other registers to specific initialisation values.

 

For more detail: A Real Time Clock IC (DS1307) project using the PIC micro.

The post A Real Time Clock IC (DS1307) project using the PIC micro. appeared first on PIC Microcontroller.

PIC based WWVB clock

$
0
0

Introduction

There are many DIY versions of WWVB clock designs available on the web. Commercial “atomic” clocks are inexpensive and widely available, but I wanted to try my hand at designing one to gain insight into WWVB reception and to learn a little about programming a PIC microcontroller. My version is not the simplest available, but it works well and I think it offers a few unique features.PIC based WWVB clock

WWVB Clock Features

  • Receives time broadcast from WWVB, Fort Collins, CO
  • Auto synchronizes internal time with WWVB time
  • Maintains local time when WWVB signal is lost
  • This version is for Pacific Standard Time, and auto detects/corrects for Daylignt Savings Time
  • 6-digit display of hours, minutes, seconds using 1″ seven-segment LED displays
  • WWVB sync indicator
  • Time display is in 12-hour format
  • PIC 16F628 microcontroller
  • Software written in C
  • All tools (schematic editor, C compiler, PCB layout software, PIC programmer are free and available for download on the web.

A complete description and specification for the WWVB broadcasts is available (free), document # 432, attf.nist.gov/general/pdf/1383.pdf The WWVB signal is broadcast as a 60 kHz carrier that is AM modulated with a time code frame that is updated once per minute. The data rate is one bit per second. Along with time code information, the data frame also contains synchronization bits, calendar data, UT1 correction, leap year, and leap second data. The clock design presented here only decodes the time data and daylight savings correction data. The software could easily be modified to include decoding of the other information bits, if desired. The the low frequency WWVB signal strength is weak and reception can be problematic. Signal acquisition time is variable, depending on location and atmospheric conditions. Reception is usually best at night between 8pm – 4am. To use the clock, just apply power and wait for reception of the WWVB signal. When the clock receives a complete error-free frame of data, it will automatically reset the display to show the correct time. After the initial time correction, the clock will maintain time even if WWVB reception is lost.

Hardware Description

As shown in the schematic (pdf format), the heart of the clock is a PIC 16F628 microcontroller running at 4 MHz. Decoded time data is sequentially output from the microcontroller (RA0 – RA3) to the 7-segment decoder/drivers on a 4-bit data bus. The data is output sequentially as seconds, 10s of seconds, minutes, 10s of minutes, hours, and 10s of hours. The microcontroller outputs (RB1, RB2, RB3) route a 10 uSec stroble pulse from RB4 out to each of the 7-segment decoder/drivers at the proper time to latch the data bus values. Seconds and 10s of seconds display values are updated once per second. Minutes, 10s of minutes, hours, and 10s of hours are updated once per minute. The display consists of 1″ red-orange LED 7-segment displays. The decimal points on the displays are used to form colons to separate the seconds, minutes, and hours. The 10s of seconds and 10s of minutes displays are mounted upside down to form the upper colon dots. The WWVB receiver is a C-MAX model CMMR-6 and is available from Digi-Key (www.digikey.com) as part # 561-1014-ND complete with loopstick antenna. Data output from the receiver is sampled by the microcontroller on RB0.PIC based WWVB clock schematic.jpg

Construction

I have built two of these clocks, one using point-to-point wiring and one using a pcb. Both versions perform well. Just keep the receiver away from noise sources and the wire / trace lengths short to minimize inductance. I found that the receiver is also sensitive to magnetic fields produced by power supplies. I used a 9V, 200 mA “wall-wart” instead of an internal power supply to eliminate this problem.

My pcb was designed using Free PCB software www.freepcb.com. The artwork contains both the main board and the display board on a single layout to save the cost of two separate boards. I purchased the pcb from www.4pcb.com by sending them the gerber files and using their “bare-bones” process. The “bare-bones” process does not include solder mask nor silk-screen. Just cut off the display board from the main board and mount it at a right angle to the main board and wire them together using the pads provided.

For more detail: PIC based WWVB clock

The post PIC based WWVB clock appeared first on PIC Microcontroller.

Viewing all 218 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>