- Wed May 07, 2014 2:23 am
#170853
Hello all,
I found what is called the PWM library in the arduino playground. Could someone please plase check my code and see if it does what the comments say, i dont have an oscilloscope at the moment and theres no way i know of that i can use to see if the code really does output a PWM.
I found what is called the PWM library in the arduino playground. Could someone please plase check my code and see if it does what the comments say, i dont have an oscilloscope at the moment and theres no way i know of that i can use to see if the code really does output a PWM.
Code: Select all
thanks./*
Aurthor: Open Source :)
Using the PWM library to generate a 25Khz PWM on pin 9
*/
#include <PWM.h>
int pwmPin = 9;
int32_t frequency = 25000; // desired frequency in Hertz
void setup()
{
//initialize all timers except for 0, to save time keeping functions
initTimerSafe();//why??? and what is time keeping??
//sets the frequency for the specified pin i.e 25Khz
bool success = SetPinFrequencySafe(led, frequency);
//if the pin frequency was set successfully, turn pin 13 on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
}
void loop()
{
//setting the duty to 50% with 8 bit pwm. 128 is 1/2 of 256
pwmWrite(led, 128);//loop PWM forever??
}