Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

crystal accuracy is insufficient

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
unforgiven

Bascom Member



Joined: 31 Aug 2007
Posts: 36

russia.gif
PostPosted: Thu Dec 13, 2007 7:36 am    Post subject: crystal accuracy is insufficient Reply with quote

Hello.
I use 32768 hg crystal for am168’s RTC, but accuracy of a course of clock is insufficient. I must correct capacity capacitor?
Back to top
View user's profile
NickUK

Bascom Member



Joined: 15 Nov 2005
Posts: 25
Location: Ashbourne

uk.gif
PostPosted: Fri Dec 14, 2007 5:57 pm    Post subject: Reply with quote

Depending on quality of the crystal and temperature, you will see a drift.

Buy the best ones you can, some are cheap and out-of-spec.

Also it is a good idea to make sure that your circuit contains good grounding and decoupling, as noise will also cause inaccuracy.

You can also design-in a variable cap which you can set with an accurate frequency counter.

BTW These tiny devices do not like being heated up - be careful when soldering.

Hope this helps

Regards

Nick
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 386
Location: Wuppertal, Germany

germany.gif
PostPosted: Sat Dec 15, 2007 12:34 am    Post subject: Reply with quote

A capacitor in parallel to the Xtal will always slow your freq. down.
So, if your clock already retards, no cap will work. This case, make shure the leads are short, as the bring capacitance. The caps used to pull the Xtal are in a range of 5pF to 25pF in most cases. In the Xtals datasheet the "load capacitance" can be found. This is the capacitance of your PCB-layout, to which the Xtal is trimmed during manufaturing. So, if your layout gives 20pF, and your Xtal has 5pF of load cap., your clock will retard a little.
How much does your clock differe from accurate freq.?
Back to top
View user's profile
unforgiven

Bascom Member



Joined: 31 Aug 2007
Posts: 36

russia.gif
PostPosted: Sat Dec 15, 2007 2:29 pm    Post subject: Reply with quote

Course error clock approximately 5 %. Tried to use as with condensers in capacity 12 pf, then without them (as IC connects internal). Tried to change quartz 32768 in case DT-38 on DT-26. Changes has not received.
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 386
Location: Wuppertal, Germany

germany.gif
PostPosted: Sat Dec 15, 2007 3:00 pm    Post subject: Reply with quote

Shocked 5%
wow, thatīs not tolerance, but there is something really wrong with your application. All that capacitior stuff is to trim the clock from e.g. 30min a yeahr (!) to maybe 10 min a yeahr tolerance. A Xtals tolerance is in the range of 50ppm (parts per million). Your deviation is 1000 times higher. There must be something else...
Can you post the code You use?
Back to top
View user's profile
unforgiven

Bascom Member



Joined: 31 Aug 2007
Posts: 36

russia.gif
PostPosted: Sun Dec 16, 2007 3:08 pm    Post subject: Reply with quote

$regfile = "m168def.dat" 'определяют используемый
$crystal = 8000000 'используемых кристаллов
'скоростей двоичной передачи использования
$hwstack = 32 'использования по умолчанию 32
$swstack = 10 'использования по умолчанию 10
$framesize = 40
'использования по умолчанию 40 'сначала соберите и управляйте этой программой с линией ниже отмеченный
C2s Alias Portd.2 : R2s Alias Portd.3 : Reset R2s

Dim Second2 As Eram Byte At 17
Dim Minute2 As Eram Byte At 18
Dim Hour2 As Eram Byte At 19
Dim Dat2 As Eram Byte At 20
Dim Month2 As Eram Byte At 21
Dim Year2 As Eram Word At 22
Dim Leap2 As Eram Byte At 24
Dim Month_inc2 As Eram Byte At 25
Dim Dat_inc2 As Eram Byte At 26
Dim Hour_inc2 As Eram Byte At 27
Dim Month_dec2 As Eram Byte At 28
Dim Dat_dec2 As Eram Byte At 29
Dim Hour_dec2 As Eram Byte At 30

Dim Tact As Byte : Dim Second As Byte : Dim Minute As Byte : Dim Hour As Byte : Dim Dat As Byte : Dim Month As Byte
Dim Year As Word : Dim Leap As Byte : Dim Month_inc As Byte : Dim Dat_inc As Byte : Dim Hour_inc As Byte
Dim Month_dec As Byte : Dim Dat_dec As Byte : Dim Hour_dec As Byte : Dim Maxdat As Byte : Dim Year_l As Byte
Dim Year_d As Byte : Dim Maxdat_l As Byte : Dim Pwm_out As Word : Dim Rs_init As Byte : Dim New_sec As Bit
Dim New_min As Bit : Dim Year_lo As Byte

Dim Rs_tim_cnt As Byte : Dim Buf_full As Bit : Dim Buf_error As Bit :
Dim Buf2_bisy As Bit : Dim Rs_entr As Bit : Dim Rs_pack_num As Byte : Dim Wdr_ovrfl As Bit : Dim Cycle_err As Bit
Dim Rs_pack_b1 As Byte : Dim Rs_pack_b2 As Byte : Dim Rs_pack_b3 As Byte : Dim Rs_pack_b4 As Byte : Dim Rs_pack_b5 As Byte
Dim Rs_pack_b6 As Byte : Dim Rs_pack_b7 As Byte : Dim Rs_pack_b8 As Byte ': Dim Rs_pack_b9 As Byte : Dim Rs_pack_b10 As Byte
'Dim Rs_pack_b11 As Byte : Dim Rs_pack_b12 As Byte : Dim Rs_pack_b13 As Byte : Dim Rs_pack_b14 As Byte : Dim Rs_pack_b15 As Byte
'Dim Rs_pack_b16 As Byte : Dim Rs_pack_b17 As Byte : Dim Rs_pack_b18 As Byte :

Ucsr0a = 2 : Ucsr0b = 24 : Ubrr0l = 8 : Ubrr0h = 0 : Ucsr0c = 38
Reset New_sec : Reset New_min : Reset Buf_full : Reset Buf_error : Reset Rs_entr : Reset Rs_pack_num : Reset Wdr_ovrfl
Reset Cycle_err ': Reset :

'Config Watchdog = 256 : Start Watchdog

Second = Second2 : Minute = Minute2 : Hour = Hour2 : Dat = Dat2 : Month = Month2 : Year = Year2 : Leap = Leap2:
Dat_inc = Dat_inc2 : Hour_inc = Hour_inc2 : Dat_dec = Dat_dec2 : Hour_dec = Hour_dec2
Year = Year Or 2000 : Month = Month Or 1 : Dat = Dat And 31 : Dat = Dat Or 1 : Hour = Hour And 23 : Leap = Leap And 1

Ucsr0a = 2 : Ucsr0b = 24 : Ubrr0l = 8 : Ubrr0h = 0 : Ucsr0c = 38
Config Serialin = Buffered , Size = 10

Enable Interrupts
On Ovf2 Tim2_isr : On Timer2 : Config Timer2 = Timer , Async = On , Prescale = 8 ' 1
Stop Timer2 : Assr = 32 : Timsk2 = 1 : Start Timer2

Print "Year-2000_Month_Day_Hour_Min Sec?(in_binary_mode)" ' Enable Urxc : On Urxc Rec_isr : 'Print "Year-2000?" : Inputbin Year_lo : Print "Month?" : Inputbin Month : Print "Day" : Inputbin Dat : Print "Hour" '
Inputbin Year_lo , Month , Dat , Hour , Minute , Second : Print "Ok" : Year = Year_lo + 2000 : Year2 = Year
Clear Serialin

Do
If Wdr_ovrfl = 1 Then : Set Cycle_err : End If : Set Wdr_ovrfl
'If _rs_head_ptr0 > 1 Then
'If Rs_pack_b8 = 13 Then : Goto 1 : End If : End If
'Inputbin Rs_pack_b1 , Rs_pack_b2 , Rs_pack_b3 , Rs_pack_b4 , Rs_pack_b5 , Rs_pack_b6 , Rs_pack_b7 , Rs_pack_b8
'Inputbin Rs_pack_b9 , Rs_pack_b10 , Rs_pack_b11 , Rs_pack_b12 , Rs_pack_b13 , Rs_pack_b14 , Rs_pack_b15 , Rs_pack_b16
'Goto 3
'1:
'Clear Serialin : Incr Rs_pack_num : Reset Rs_entr : Reset Rs_pack_b1 : Reset Rs_pack_b8 : Print Rs_pack_b1 ; " " ; Rs_pack_b2 ; " " ; Rs_pack_b3 'To Set The Pwm Registers , Just Assign A Value To The Compare A And B Registers

'3:
Stop Timer0 : Ocr0a = Pwm_out : Ocr0b = Pwm_out : Start Timer0
If New_sec = 1 Then '
If New_min = 1 Then
Print Minute ; " \ " ; Hour ; " \ " ; Dat ; "\" ; Month ; "\" ; Year
Reset New_sec : Reset New_min : End If : End If


Reset Watchdog
Reset Wdr_ovrfl
Waitms 100
Loop

Serial0charmatch:
Rs_entr = 1
Return

Tim2_isr:
Incr Tact : Pwm_out = Pwm_out + 1 ' Compare1a = A ' Compare1b = A 'Pwm1a = A 'Pwm1b = A 'Or for better reading :
If Pwm_out > 230 Then : Pwm_out = 10
End If
If Tact > 16 Then
Tact = 0 : Incr Second : Second2 = Second : Set New_sec ': Print "cntr" ; _rs_bufcountr0 ; "Head" ; _rs_head_ptr0,
If Second > 59 Then ' If One Minute
Second = 0 : Incr Minute : Minute2 = Minute : Set New_min
If Minute > 59 Then
Minute = 0 : Incr Hour : Hour2 = Hour
If Month_inc = Month Then
If Dat = Dat_inc Then
If Hour = Hour_inc Then
Incr Hour
End If
End If
End If
If Month_dec = Month Then
If Dat = Dat_dec Then
If Hour = Hour_dec Then
Incr Hour
End If
End If
End If
If Hour > 23 Then
Hour = 0 : Incr Dat : Dat2 = Dat
If Month = 2 Then
Year_d = Year Mod 4
End If
If Year_d = 0 Then : Leap = 1 : Leap2 = Leap : Maxdat = Lookup(month , Dta1) 'if YEAR_LO = 0, (a century has passed) check if YEAR_HI is divisible by 4
End If 'then it is a leap year else if YEAR_LO is divisible by 4 and not zero
If Dat < 27 Then : Goto 2 '
End If : Maxdat_l = Maxdat + Leap
If Dat > Maxdat_l Then : Dat = 1 : Incr Month : Month2 = Month ' then it's a leap year ,if a whole month has passed ' clear DAY , increment MONTH
End If
If Month > 12 Then : Month = 1 : Incr Year : Year2 = Year ' if one year clear MONTH increment YEAR_LO
End If
End If
End If
End If
End If
2:
Return

Dta1:
Data 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sun Dec 16, 2007 3:47 pm    Post subject: Reply with quote

Hi,

Try this code.

Best regards,

Luciano

Code:
' Must use the internal RC oscillator at 8MHz or at 1MHz because
' a 32.768 kHz watch crystal must be connected between the TOSC1 and TOSC2 pins.
'

$regfile = "m168def.dat"
$crystal = 8000000
$baud = 9600

$hwstack = 32
$swstack = 16
$framesize = 40

Dim Seconds_count As Long

' ======================================================
'  Timer2 initialization
'
'  Mode: Normal mode (TOP = FF)
'  Asynchronous clock for Timer2 enabled
'  (A 32.768 kHz watch crystal must be connected between the TOSC1 and TOSC2 pins).
'  Prescaling: clkT2S/128
'
ASSR = &H20                             ' See datasheet for details.
TCCR2A = &H00                           ' See datasheet for details.
TCCR2B = &H05                           ' See datasheet for details.

' ======================================================

On OVF2 OVF2_isr
Enable TIMER2

' Reset the Timer2 count
TCNT2= &H00

Enable Interrupts

Do

  Print "Elapsed seconds:" ; Seconds_count
  Waitms 250

Loop


End

' ======================================================
'Timer2 Overflow Interrupt service routine
OVF2_isr:

  Incr Seconds_count

  If Seconds_count >= 86400 Then       '86400 seconds = 1 day
     Seconds_count = 0
  End If

Return
' ======================================================
 
Back to top
View user's profile
unforgiven

Bascom Member



Joined: 31 Aug 2007
Posts: 36

russia.gif
PostPosted: Tue Dec 18, 2007 3:38 pm    Post subject: Reply with quote

Thanks, these codes work normally. Fault in the Config.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum