User Tools

Site Tools


Clock frequency trimming on Micromite II uses precision 32.768KHz output from DS3231 Real Time Clock

The DS3231 RTC has a very precise 32.768KHz output usually on pin 1 (ymmv). By taking this known frequency and measuring it using the COUNT function in MMBasic, the internal clock frequency (which determines the gate period for the count) can be adjusted until the measured frequency is as near as possible to the know frequency from the RTC.

The clever code below measures the frequency and automatically calculates the CLOCKTRIM argument.

Originally posted here:

Credit: twofingers

' 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 1 to a MM2 (COUNT) pin (e.g. 16) 

Dim integer freq,ctrim 

SetPin 16,fin 
Pause 2000 

'Print freq, ctrim 
If Abs(ctrim) < 10 Then 
   Option ClockTrim ctrim 
   Print "ClockTrim is set to "ctrim 
   Print "Error! Please check 32khz signal. Freq="freq 
mmbasic/clock_frequency_trimming_on_micromite_ii_uses_precision_32_768khz_output_from_ds3231_real_time_clock.txt · Last modified: 2024/01/19 09:30 by