/*
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
}