Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

a problem with DS1390 (RTC)

Status
Not open for further replies.

mf1364

Full Member level 3
Joined
Dec 4, 2007
Messages
185
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,700
Hi
I am using DS1390 for making a digital clock, at quick glance it looks good but during a month I understand that my circuit calculate time faster than real ! I put here my codes could you please somebody check them
Code:
#define RTC_chip_select portc.f0
char* text;
char txt[6];
unsigned char    Minute,Second,Hour;
void lcd(){
byteToStr(Bcd2Dec(Second), txt);
Lcd_Out(3, 12, txt);
byteToStr(Bcd2Dec(Minute), txt);
Lcd_Out(3, 9, txt);
text=":";
Lcd_Out(3, 12, text);
byteToStr(Bcd2Dec(Hour), txt);
Lcd_Out(3, 6, txt);
Lcd_Out(3, 9, text);
}
//////////////////////////////////////// Set Hour
void Inc_Hour(){
delay_ms(200);
Hour = Bcd2Dec(Hour);
Hour++;
if( Hour> 24)Hour =0;
Hour=Dec2Bcd(Hour);
RTC_chip_select=0;
spi_write(0x83);
spi_write(Hour);
RTC_chip_select=1;
}
//////////////////////////////////////////Set Hour
///////////////////////////////////////// Set Minute
void Inc_Minute(){
delay_ms(200);
Minute = Bcd2Dec(Minute);
Minute++;
if( Minute> 59)Minute=0;
Minute=Dec2Bcd(Minute);
RTC_chip_select=0;
spi_write(0x82);
spi_write(Minute);
RTC_chip_select=1;
}
////////////////////////////////////////Set Minute
///////////////////////////////////////////Set Second
void Inc_Second(){
delay_ms(200);
Second = Bcd2Dec(Second);
Second++;
if( Second> 59)Second=0;
Second=Dec2Bcd(Second);
RTC_chip_select=0;
spi_write(0x81);
spi_write(Second);
RTC_chip_select=1;
}
/////////////////////////////////////////////Set Second
///////////////////////////////////////keypad Function
void Keypad(){
unsigned char kp;
kp = Keypad_Read();
if(kp=!0) {
kp = Keypad_Read();
if(kp==1)Inc_Hour();
if(kp==2)Inc_Minute();
if(kp==3)Inc_Second();
}}
/////////////////////////////////////// keypad Function
//////////////////////////////////////RTC_Refresh Function
void RTC_Refresh(){
RTC_chip_select=0;                  // enable RTC - CS low
spi_write(0x01);                   // seconds register read address
Second = spi_read(255);       // read seconds register
Minute =spi_read(255);        // read minutes
Hour =spi_read(255);          // read  hours
RTC_chip_select=1;                 // disable RTC - CS high
}
//////////////////////////////////////RTC_Refresh Function
/////////////////////////////////////RTC_Register Function
void RTC_Register(){
///////////////////////////////control register
RTC_chip_select=0;
spi_write(0x8d);                // control register write address
spi_write(0xBD);                //10111101//
RTC_chip_select=1;
///////////////////////////////control register
///////////////////////////////////trickle charger
RTC_chip_select=0;
spi_write(0x8f);
spi_write(0xAB);        // one diode and one 4k resistor
RTC_chip_select=1;
//////////////////////////////////trickle charger
}
//////////////////////////////////////RTC_Register Function
////////////////////////////////////////////Pins Function
void Pin(){
trisc.f0=0;    // chip select
portc.f0=1;   // chip select
trisc.f1=1;    // int
portc.f1=1;    // int
trisc.f2=0;    // led
portc.f2=0;    // led
}
/////////////////////////////////////////////// Pins Function
//////////////////////////////////////////// main Function
void main() {
ADCON1=0b00000111;
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CURSOR_OFF);
Keypad_Init(&PORTA);
Spi_Init_Advanced(MASTER_OSC_DIV64,DATA_SAMPLE_End,CLK_IDLE_HIGH , LOW_2_HIGH) ;
Pin();
delay_ms(2000);
RTC_Register();
while(1){
Keypad();
RTC_Refresh();
lcd();
}
}
//////////////////////////////////////////// main Function
 

I am using DS1390 for making a digital clock, at quick glance it looks good but during a month I understand that my circuit calculate time faster than real ! I put here my codes could you please somebody check them

If there is a steady increasing time differential between the DS1390 and an known accurate time source, like a Tier 1 NTP Time Source, the issue is most likely the crystal used in your circuit rather than your code.

What time source are you using to determine there is an increasing time differential, in other words the DS1390 is running fast?

What are the specifications of the crystal being utilized in the circuit, Frequency Tolerance, Frequency Stability, Load Capacitance, Equivalent Series Resistance (ESR) ratings?

If you do not know the specs of the crystal you are now utilizing, I suggest you purchase a crystal which meets the specifications stated in the DS1390 Datasheet.

Reference: , Section: Oscillator Circuit & Clock Accuracy, Page: 13:
Oscillator Circuit

All five devices use an external 32.768kHz crystal. The
oscillator circuit does not require any external resistors
or capacitors to operate. Table 2 specifies several crystal
parameters for the external crystal. If a crystal is
used with the specified characteristics, the startup time
is usually less than one second.

The crystal, traces, and crystal input pins should be isolated
from RF generating signals. Refer to Application Note 58:
Crystal Considerations for Maxim Real-Time Clocks for additional
specifications.


ESR of 55 kΩ
Capacitive Load of 6 pF

Both the Capacitive Load and ESR are particular important to ensuring accurate RTC performance, frequency tolerances and stability of 10ppm or less are preferred.

The crystal should be attached to the DS1390 as close as possible with proper RF and EMI precautions taken, like the effective use of a ground plane.

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 is added by crystal frequency drift
caused by temperature shifts. External circuit noise
coupled into the oscillator circuit can result in the clock
running fast. Figure 7 shows a typical PC board layout
for isolation of the crystal and oscillator from noise.
Refer to Application Note 58: Crystal Considerations
with Maxim Real-Time Clocks for detailed information.

BigDog
 
Thanks for your guidance, I don't know the spec of my crystal also I didn't route the PCB according the datasheet so I think if I correct my PCB, my problem will be solved. in some boards I saw that the body of crystal has connected to GND, but I didn't see any statement related to this matter in the datasheet, so what is your Idea ? connect the crystal to the GND ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top