![]() |
Forum Index : Microcontroller and PC projects : MMBasic/MM2: Clocktrim made easy
Author | Message | ||||
twofingers Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1526 |
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 KingdomPosts: 10067 |
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: GermanyPosts: 1526 |
Thanks you for the kind words! ![]() Yes! I used a BP170 with 2.4" TFT. 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: AustraliaPosts: 320 |
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: GermanyPosts: 1526 |
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): 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: AustraliaPosts: 2946 |
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) <<< |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |