teensy 2 timer 4 at 64mhz

Status
Not open for further replies.

manitou

Senior Member+
I see that timer 4 on atmega32u4 (teensy 2, leonardo) can run at 64MHz with PLL. Does anyone have a sketch that sets up timer4 at 64mhz?

inquiring minds ...
 
OK, answering my own question, since it turned out to be "not so hard". Looking at PLLFRQ on Teensy 2, one can see the PLL is already configured in 48mhz mode for USB support. So the simple hack test I ran was to enable the 1.5 prescaler with PLL to 96mhz giving a 64mhz clock for timer4. The default PWM frequency for pins 4 and 10 is 3906 hz clocked from 16MHz F_CPU (16000000/8/2/256). In the sketch below with timer4 at 64mhz, pin 10 PWM is running 4 times faster at 15625 hz.

Code:
// run timer4 at 64mhz
void setup() {
  analogWrite(4, 128); // compare pwm signals on scope/analyzer  
  analogWrite(10, 128); // teensy 2 pin  is on timer4 OC4A
  PLLFRQ = _BV(PLLTM1) | _BV(PLLUSB) | _BV(PDIV3) | _BV(PDIV1);  // 96mhz/1.5
}

void loop() {
}

With TIMER4 running at 64MHz , you can run PWM at 250KHz with prescale of 1 and FAST PWM.
 
Last edited:
Status
Not open for further replies.
Back
Top