Autor Tema: Segundo cristal en el pic  (Leído 2207 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado RaDoN

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1498
Segundo cristal en el pic
« en: 31 de Agosto de 2005, 06:57:00 »
El datasheet cita lo siguiente:

Cita:

12.6 Using Timer1 as a Real-Time
Clock
Adding an external LP oscillator to Timer1 (such as the
one described in Section 12.3 “Timer1 Oscillator”
above) gives users the option to include RTC functionality
to their applications. This is accomplished with an
inexpensive watch crystal to provide an accurate time
base and several lines of application code to calculate
the time. When operating in Sleep mode and using a
battery or supercapacitor as a power source, it can
completely eliminate the need for a separate RTC
device and battery backup.
The application code routine, RTCisr, shown in
Example 12-1, demonstrates a simple method to
increment a counter at one-second intervals using an
Interrupt Service Routine. Incrementing the TMR1
register pair to overflow triggers the interrupt and calls
the routine, which increments the seconds counter by
one; additional counters for minutes and hours are
incremented as the previous counter overflow.
Since the register pair is 16 bits wide, counting up to
overflow the register directly from a 32.768 kHz clock
would take 2 seconds. To force the overflow at the
required one-second intervals, it is necessary to preload
it. The simplest method is to set the MSb of
TMR1H with a BSF instruction. Note that the TMR1L
register is never preloaded or altered; doing so may
introduce cumulative error over many cycles.
For this method to be accurate, Timer1 must operate in
Asynchronous mode and the Timer1 overflow interrupt
must be enabled (PIE1<0> = 1) as shown in the
routine, RTCinit. The Timer1 oscillator must also be
enabled and running at all times.



Y da un esquemita simple del segundo cristal en el pic, la duda es, según creo haber leido, todo el pic ira a la velocidad marcada por el segundo cristal (en el caso que ocupa 32khz), la pregunta es ... ¿podría correr el PIC normalmente, digamos 20mhz, y el timer con el cristal externo hacerlo a la de este, 32khz?

Si alguien tiene alguna experiencia con los segundos cristales, me gustaria conocerla. Thanks!!! Sonrisa Gigante
Si juegas contra el mejor, pierdes como los demás.

Desconectado fenix_jn

  • PIC18
  • ****
  • Mensajes: 418
RE: Segundo cristal en el pic
« Respuesta #1 en: 31 de Agosto de 2005, 09:31:00 »
Tenngo entendido q si, puesto q el timer esta usando una entrada externa para incrementarse, recuerda q los timers son "independientes" del programa y el cristal de 20 Mhz es usado exclusivamente para el PC del propio PIC (y todas sus operaciones internas).

Piensa en el cristal externo del TMR1 como un 555, hace la misma funcion: generar una señal de reloj para q el timer se incremente.

Desconectado piriots

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 609
RE: Segundo cristal en el pic
« Respuesta #2 en: 31 de Agosto de 2005, 10:25:00 »
Estoy totalmente de acuerdo con tigo fenix_in, yo hice algunas pruebas con un 16F84 y un generador de onda cuadrada pero solo como ejercicio teorico, no le di ninguna aplicacion, usando un cristal de 32Khz no deberia ser dificil hacer un RTC. Buscando un poco en los apuntes de 1º encontre este ejemplo tan simple.

Codigo:

// el programa muestra el contage del TMR0

#include <16f84.h>
void main()
{
GIE=0;
TRISA=0b11111;
TRISB=0;
T0CS=1; // cuenta pulsos que entran por RA4
T0SE=1;   // cuenta en flanco descendente
PSA=0;   // asignamos la cuenta al timer0
PS2=1;
PS1=1;
PS0=1;   // damos el valor 256 al prescaler
TMR0=0;
while(1)
   {
   PORTB=TMR0;
   }
}


Salu2

Desconectado RaDoN

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1498
RE: Segundo cristal en el pic
« Respuesta #3 en: 31 de Agosto de 2005, 11:07:00 »
OK, dudas aclaradas, es algo que nunca use Sonrisa Gigante

Thanks!
Si juegas contra el mejor, pierdes como los demás.


 

anything