Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:39 10 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBasic/MM2: Clocktrim made easy

Author Message
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 06:53am 18 Sep 2015
Copy link to clipboard 
Print this post

There is already a thread for CLOCKTRIM but I think this is much easier.

Most of us own a DS3231 RTC modul which also outputs a very precise 32khz (32768hz) squarewave signal (32kHz TCXO).

With clocktrim value=0 I get the (wrong) 32742hz displayed (this means the MM is too fast!). After setting clocktrim value=-2 my MM2 works nearly perfect (Freq=32772).


' Clocktrim level for Micromite2/MMBasic
' determines the value for Option ClockTrim n
' using the DS3231 32768hz signal (32kHz TCXO).
' Released by twofingers@TBS 18.09.2015
' Provided AS IS. No warranty.
'
' You need only to connect a wire from
' DS3231/32kHz Pin to a MM2 (COUNT) pin (e.g. 16)

CLS
Option EXPLICIT
Dim integer freq,ctrim

SetPin 16,fin
Pause 2000
freq=Pin(16)

ctrim=Cint(freq-32768)/15
'Print freq, ctrim
If Abs(ctrim) < 10 Then
Option ClockTrim ctrim
Print "ClockTrim is set to "ctrim
Else
Print "Error! Please check 32khz signal. Freq="freq
EndIf


Download:2015-09-18_165241_Clocktrim.zip

Frequencies for different ClockTrim (-)values measured with MM2/MX170/28Pin at room temperature (22°C).
Each clocktrim value represents ~15hz (or 0,046% of 32768).
0 32742
1 32757 -15
2 32772 -15
3 32787 -15
4 32802 -15
5 32818 -16
6 32833 -15
7 32849 -16
8 32864 -15
9 32879 -15
10 32895 -16
11 32910 -15
12 32925 -15
13 32940 -15
14 32956 -16
15 32971 -15
16 32986 -15
17 33007 -15
18 33022 -15
19 33037 -15
20 33053 -16
21 33068 -15
22 33084 -16
23 33099 -15
24 33114 -15
25 33131 -17
26 33146 -15
27 33162 -16
28 33178 -16
29 33193 -15
30 33208 -15
-460 -15,33333333


Michael
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10067
Posted: 08:44am 18 Sep 2015
Copy link to clipboard 
Print this post

  Quote  There is already a thread for CLOCKTRIM but I think this is much easier.

Certainly is - great bit of lateral thinking

One minor issue, you should remove CLS as we don't all have a display connected.

OPTION CLOCKTRIM isn't remembered so needs to be executed each time. However, with the new features in 4.7 it can now be included it in MM.STARTUP
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 09:12am 18 Sep 2015
Copy link to clipboard 
Print this post

Thanks you for the kind words!

  Quote  One minor issue, you should remove CLS as we don't all have a display connected.


Yes! I used a BP170 with 2.4" TFT.

  Quote  OPTION CLOCKTRIM isn't remembered so needs to be executed each time. However, with the new features in 4.7 it can now be included it in MM.STARTUP


I thought it would be enough - in the most cases - if the Clocktrim value is at the beginning of the code. Moving it to the MM.STARTUP will be problematic because it takes 2sec (PAUSE 2000)! Who wants to wait for so long?
causality ≠ correlation ≠ coincidence
 
centrex

Guru

Joined: 13/11/2011
Location: Australia
Posts: 320
Posted: 06:41pm 18 Sep 2015
Copy link to clipboard 
Print this post

I have three 3231 modules all look the same but only one of them returns a trim figure the other two get the error message check the frequency.
They look identical and the 32 Khz pin on the 3231 is connected to the output pin.
Puzzled.
Cliff
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1526
Posted: 11:05pm 18 Sep 2015
Copy link to clipboard 
Print this post

  centrex said   They look identical and the 32 Khz pin on the 3231 is connected to the output pin.


to the output pin?

I have no idea. Can you check the signal on PIN1 (DS3231 chip)?
AFAIK the 32khz signal should be on (if powered by VCC):
  Quote  Control Register (0Eh)
Bit 7: Enable Oscillator (EOSC). When set to logic 0, the oscillator is started. When set to logic 1, the oscillator is stopped when the DS3231 switches to VBAT. This bit is clear (logic 0) when power is first applied. When the DS3231 is powered by VCC, the oscillator is always on regardless of the status of the EOSC bit. When EOSC is disabled, all register data is static. (MAXIM DS3231 manual p.13)


This is my DS3231:



Here is a updated version of the ClockTrim Demo:

DOWNLOAD:
2015-09-19_085543_Clocktrim1.zip

causality ≠ correlation ≠ coincidence
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2946
Posted: 11:54pm 18 Sep 2015
Copy link to clipboard 
Print this post

Hi Michael, All,

I have tried it on my SMD BackPack 170 which uses a DS3232 8pin RTC chip and it seems to work as well.

FYI here is where to link the 32kHz signal to Pin(16)



Regards,

Mick

Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025