Free Running Clock with Variable Frequency and Variable PWM

Hello Guys, I'm a novice in programming and have tried my best shot at resolving the issue. The main issue is that i'm trying to generate variable frequency and variable PWM for my pet Project. I'm trying to give a range of 10Hz-16Mhz for varying the Frequency using Potentiometer and am trying to regulate the PWm according to the Frequency change but no avail. The Output pin and the code are described Below;

#include <PWM.h>

//analogInPin = A0;
int pwm = 11; //pin11 on the Uno
int dutycycle = 55;

int32_t freq = 35; //frequency (in Hz)

void setup()
{
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
Serial.begin(9600);
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(pwm, freq);

//if the pin frequency was set successfully, turn pin 13 on
//if(success) {
//pinMode(13, OUTPUT);
//digitalWrite(13, HIGH);
//}
}

void loop()
{
//use this functions instead of analogWrite on 'initialized' pins
//freq = analogRead(analogInPin);
//pwm = map(freq, 0,1023,0,255);
//analogWrite(analogOutPin,pwm);

SetPinFrequencySafe(pwm, freq);
pwmWrite(pwm, dutycycle);
//Serial.print("Freqency=");
// Serial.print(freq);
// Serial.print("pwm:");
// Serial.print (pwm);

delay(30);
}

PWMlel.ino (928 Bytes)

Can you make an unmodified example code work with that library?

Eventually you set the PWM frequency and duty cycle too often. Try setting it only if freq or dutycycle have changed.

NO CROSS POSTING!!!!!

Mark