1Hz Clock Generator using PIC12F675

Based on the idea from http://www.josepino.com/pic_projects/?timebaseI have created a 1Hz Clock Generator. I use PIC12F675 as it’s available locally. Its price is just about US$1.

Clock Generator
The concept is using 32.768kHz crystal as a clock for the PIC. Therefor, the internal instruction clock is 32768/4 = 8192 Hz. By using the 16 bit Timer1 to count the instruction clock cycles, the interrupt will occur every 8 second. This period can be reduced by setting initial value of the Timer1 (TMR1H:TMR1L). I have to make Timer1 to count up to 8192 for generating overflow interrupt every 1 second. To make Timer1 count up to 8192, the initial value of TMR1 must be 65536-8192 = 57344 or 0xE000. This means TMR1H = 0xE0 and TMR1L = 0x00. In this case, I need to set only the TMR1H=0xE0 and let TMR1L runs continuously. By changing the initial value of Timer1, I can generate almost any frequencies.

An application for this project is a precise 1Hz blinking LED signal πŸ™‚ ha ha. I know that it’s not useful but I think it’s fun to look at (am I crazy?). Another application is a precise 1Hz time base for a clock.
Schematic Clock Generator
The source code is written in MikroC.


//Β PIC12F675
//Β 1HzΒ TimeΒ BaseΒ Osc.
//Β Timer1Β Module
//Β 32.768Β KHz
unsignedΒ shortΒ tick;
voidΒ InitΒ ();
voidΒ interruptΒ ()
{
ifΒ (PIR1.TMR1IF)
{
TMR1HΒ =Β 0xE0;
PIR1.TMR1IFΒ =Β 0;
tickΒ =Β 1;
}
}
voidΒ mainΒ ()
{
tickΒ =Β 0;
//InitializeΒ PortsΒ andΒ Timer1Β Module
InitΒ ();
whileΒ (1)
{
ifΒ (tick)
{
tickΒ =Β 0;
GPIOΒ =Β (1Β <<Β 2);
}
ifΒ (TMR1HΒ >Β 0xF0)
{
GPIOΒ =Β 0;
}
}
}
voidΒ InitΒ ()

 

For more detail: 1Hz Clock Generator using PIC12F675


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.