You are on page 1of 2

1HZ CLOCK GENERATOR USING PIC12F675

Based on the idea fromhttp://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. The concept is using 32.768kHz crystal as a clock for the PIC. Therefor, the internalinstruction clock is 32768/4 = 8192 Hz. By using the 16 bit Timer1 to count the instructionclock cycles, the interrupt will occur every 8 second. This period can be reduced by settinginitial 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.

Basado en la idea dehttp://www.josepino.com/pic_projects/?timebase he creado un reloj de 1 Hz del generador. Yo uso PIC12F675 ya que est disponible localmente. Su precio es de apenas alrededor de 1 dlar EE.UU.. El concepto de est utilizando cristal de 32,768 kHz como un reloj para el PIC. Por lo cual, al interior de la instruccinel reloj es 32768/4 = 8192 Hz. Al utilizar el Timer1 de 16 bits para contar los de instruccin ciclos de reloj, la interrupcin se produce cada segundo 8. Este perodo puede reducirse mediante la creacin valor inicial del Timer1 (TMR1H: TMR1L).Tengo que hacer Timer1 a contar hasta 8192 para la generacin de desbordamiento interrumpen cada 1 segundo. Para hacer Timer1 contar hasta 8192, el valor inicial del TMR1 debe ser 65536 a 8192 = 57344 o 0xe000. Esto significa TMR1H = 0xE0 y 0x00 = TMR1L. En este caso, tengo que configurar slo el TMR1H = 0xE0 y dejar TMR1L funciona continuamente. Al cambiar el valor inicial de Timer1, que puede generar casi ninguna frecuencia. Una aplicacin para este proyecto es un 1Hz precisa parpadeo del LED de seal :) ja, ja. S que no es til, pero creo que es divertido de ver (Estoy loco?). Otra aplicacin es una base precisa tiempo de 1 Hz de un reloj. El cdigo fuente est escrito en MikroC.

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 () { TRISIO = 0; //Make all pins as output ports GPIO = 0; //Use Timer1 module INTCON.GIE = 1; INTCON.PEIE = 1; T1CON = 0x01; //Overflow every 8192 TMR1H = 0xE0; TMR1L = 0x00; // Enable TMR1 interrupt PIE1.TMR1IE = 1; }

You might also like