Baseline PWM frequency on Teensy 3?

Status
Not open for further replies.

darkness

Active member
Can someone tell me what is the baseline PWM frequency in Teensy 3 using analogRead? Thanks!

Also, has the beta code for analogReadFrequency been incorporated into the latest beta11 for the Teensyduino?
 
Can someone tell me what is the baseline PWM frequency in Teensy 3 using analogRead? Thanks!

I believe it's about 490 Hz. It's supposed to be the exact same frequency you'd get from an Arduino Uno.

Also, has the beta code for analogReadFrequency been incorporated into the latest beta11 for the Teensyduino?

Yes. Actually, it's analogWriteFrequency(pin, frequency).
 
Frequency and Duty Cycle checks out nicely

Thanks Paul... Great Work!

I tested out various combinations of Bit resolution, Base Frequency and Duty Cycles, and the outputs are very accurate.
Obviously there are limitations, but the included code can be used to check.
I was able to get base frequencies from 10Hz to over 5MHz with out problem at 8bits... but The duty cycle resolution starts to suffer at the high end.
Also good results also between 6 and 16 bits resolution at various frequencies

Here's a snap of the readings from my Digital Signal Analyser:
DigSigAnalyser.jpg

Code:
/*
  R. Wozniak
  01/18/2012

   PWMTEST

   Test Teensy 3.0 PWM base frequency and Duty Cycle
   This example code is in the public domain.
   
   Teensy 3.0 Beta 11 Software
   http://www.pjrc.com/teensy/beta/arduino-1.0.3-teensy3-beta11-windows.zip
   Teensy Loader 1.07
   Arduino 1.0.3 
*/

// *******************   INPUTS  ************************** 
  int res = 12;                  // <--- PWM Bit Resolution          <Tested with integers between 6 and 16>
  int FREQ = 50000;              // <--- PWM Base Frequency          <Tested with integers between 10 and 5,000,000>
  int PercentDutyCycle = 33;    // <--- PWM Duty Cycle in PERCENT   <Integer between 0 and 100>

// ***************Define Variables ***********************
  const int ledPin = 13;       // Teensy 3.0 onboard orange LED on pin 13
  const int pwmPin = 21;       // PWM output pin - Hook to Digital Signal Analyser
  int DutyCycle = 0;           // Duty Cycle in Counts
  
  void setup()   {                
  pinMode(ledPin, OUTPUT);     // Setup LED output
  pinMode(pwmPin, OUTPUT);     // Setup PEM output
  
  // Serial.begin(9600);          // USB serial on For Debugging
  
  //****************** Setup PWM  ************************************
  DutyCycle = (pow(2,res)-1)/(100/PercentDutyCycle);           // Calculate Duty Cycle Counts     
  analogWriteResolution(res);
  analogWriteFrequency(pwmPin, FREQ);
}

void loop()  {
  // Serial.println(DutyCycle);         // For Debugging
  analogWrite(pwmPin, DutyCycle);    // Start the PWM output
  delay(1000);                       // Delay 1 second
 
 //********  Flash th onboard LED so that you know I'm alive ************
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(25);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
 }
 
Last edited:
Status
Not open for further replies.
Back
Top