Teensy 3.6 internal clock fast at 2 Mhz

Status
Not open for further replies.

ColdFire

Member
The internal clock of my Teensy 3.6 is running too fast (84 seconds per hour) when setting the CPU speed to 2 Mhz, that's a lot. Is that so? I provide a simple test sketch for reproduction. As Serial USB output is not possible at 2 Mhz I print the time on a SSD1306 Oled display. Same behaviour on 2 Teensy 3.6. On a 3.2@2Mhz the time is fast by ~12 seconds per hour. Teensys purchased at antratek.de. I'm on Arduino 1.8.5 and Teensuduino 1.40.

Code:
#include <DS1307RTC.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(4);

int old_second = -1;

void setup()   
{                
  setTime(Teensy3Clock.get());
  pinMode(13, OUTPUT);
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3c);
}

void loop() 
{
  if (second() != old_second)
  {
    old_second = second();
    digitalWrite(13, HIGH);
    delay(30);
    digitalWrite(13, LOW);
    displayClock();
  }
}

void displayClock(void) 
{
  oled.clearDisplay();
  oled.setTextColor(WHITE);
  oled.setTextSize(1);
  oled.setCursor(0, 14); 
  oled.print(second());
  oled.display();
}

time_t getTeensy3Time(void)
{
  return Teensy3Clock.get();
}


Here is the scetch with no Oled output, you can see the blinking LED (every second) runs out of sync within seconds by comparing the second tick to a real clock.


Code:
#include <DS1307RTC.h>

int old_second = -1;

void setup()   
{                
  setTime(Teensy3Clock.get());
  pinMode(13, OUTPUT);
}

void loop() 
{
  if (second() != old_second)
  {
    old_second = second();
    digitalWrite(13, HIGH);
    delay(30);
    digitalWrite(13, LOW);
  }
}

time_t getTeensy3Time(void)
{
  return Teensy3Clock.get();
}
 
It uses 4MHz Fast Internal clock (BLPI) @2MHz to clock peripherals which has a trim register that might be of use here. If you have a scope look at the carrier frequency for the PWM (analogWrite) and see if measures ~488Hz for TeensyLC/3.5/3.6. In my Snooze library which dynamically sets the CPU from RUN mode to BLPI mode I see a slight offset to the pwm carrier frequency which I'm looking at how to trim the 4MHz internal clock t correct this possibly. Another thing I want to try is setting the MCG Clock Output to pin to measure the clock directly? I don't know how to do this yet or if it is possible?
 
@4Mhz the time is reasonably accurate.
Thats using the divided down external 16MHz crystal directly in BLPE mode cpu clock where at 2MHz its in BLPI mode and also is in VLPR low power mode which could account for some of the skew, maybe.
 
Status
Not open for further replies.
Back
Top