Generating an accurate 32768Hz signal with a Teensy 4.0

Kuba0040

Well-known member
Hello,
I need to urgently figure out how to generate, as accurately as possible a 32768Hz 50% duty cycle pulse with a Teensy 4.0. I’ve built a clock for a friend (not using the teensy, it’s an unrelated project) and need to tune its crystal oscillator. I need a as accurate as possible reference signal to compare the crystals output to. I do not have any fancy equipment that could do that. The teensy is my best shot.

I’ve already tried generating the frequency using analogWrite. With that, at a CPU speed of 1.008Ghz and analog write resolution of 2 bits, according to my calculations, the best accuracy could be achieved with a frequency off only by +0.765644Hz.

However, I also know that the Teensy 4.0 has integrated RTC circuitry which uses a 32.768kHz clock for keeping time. Is there anyway I could output this clock signal to a pin of the teensy? This would give me the best accuracy possible.

I apologize for essentially asking the forums to prepare a piece of code for me, however I need to have this clock tuned no later than by the 29th of August. I am under a serious time crunch, also working on other things as I need to ship this clock to another country.

Thank You for understanding and all help.
 
However, I also know that the Teensy 4.0 has integrated RTC circuitry which uses a 32.768kHz clock for keeping time. Is there anyway I could output this clock signal to a pin of the teensy?

Yes, but only to a small test point on the bottom side. That test point exists because we use it to test if the 32.768 kHz crystal is working and accurate.

Code:
void setup() {
	// Output 32 kHz to test pad on bottom side of Teensy 4.0 / 4.1
	IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_00 = 2; // REF_CLK_32K, pg 469
}

void loop() {
}

The RTC crystal used on Teensy 4.0 is rated for 20ppm initial accuracy at room temperature. It's not temperature compensated. Maybe not quite "reference" material?
 
Thank You,
I'd like to know which test point it is, as there are quite a few on the bottom of the PCB. I have previously attached some wires to the bottom GPIO pins of my teensy board. Desoldering these would take some time and I'd rather not do that if the test point turns out to be somewhere accesible.

The accuracy is not an issue in my case as at 20ppm it's still more accurate than the PWM solution (asuming the main CPU clock is perfect in the first place).
 
Image from the Teensy 4.0 product page.

test_points_teensy40.png
 
Back
Top