Guys, I got this wonderful library for PWM from google codes. (forgot the link, but it's available after a few search).
Now, I have installed it accordingly, the way Arduino suggests... then it shows me the error of this:
PWM_Test.ino: In function 'void setup()':
PWM_Test:25: error: 'InitTimersSafe' was not declared in this scope
PWM_Test:28: error: 'SetPinFrequencySafe' was not declared in this scope
PWM_Test.ino: In function 'void loop()':
PWM_Test:45: error: 'pwmWrite' was not declared in this scope
Now, here is my code:
/*
Mimics the fade example but with an extra parameter for frequency. It should dim but with a flicker
because the frequency has been set low enough for the human eye to detect. This flicker is easiest to see when
the LED is moving with respect to the eye and when it is between about 20% - 60% brighness. The library
allows for a frequency range from 1Hz - 2MHz on 16 bit timers and 31Hz - 2 MHz on 8 bit timers. When
SetPinFrequency()/SetPinFrequencySafe() is called, a bool is returned which can be tested to verify the
frequency was actually changed.
This example runs on mega and uno.
*/
#include <PWM.h>
//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int led = 11; // the pin that the LED is attached to
int32_t frequency = 200000; //frequency (in Hz)
int duty = 0;
void setup()
{
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
//sets the frequency for the specified pin
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()
{
while (Serial.available() > 0) {
duty = (255*Serial.parseInt())/100;
//use this functions instead of analogWrite on 'initialized' pins
pwmWrite(led, duty);
}
}
PWM_Test.ino: In function 'void setup()':
PWM_Test:25: error: 'InitTimersSafe' was not declared in this scope
PWM_Test:28: error: 'SetPinFrequencySafe' was not declared in this scope
PWM_Test.ino: In function 'void loop()':
PWM_Test:45: error: 'pwmWrite' was not declared in this scope
Why do you want 200kHz pwm? it's not trivial to do switching at such a high frequency. The only application i can think of is a class D (audio) amplifier but i think you would be better off with sigma/delta than pwm
guys... it's working... i had to copy files manually as the supply did not dropped perfectly..
And now all i need to know is how exactly can i use ONLY one timer (1-n) except 0. Plus a way to ON or OFF the PWM on demand from the code... need research though...
But such a high frequency? There is very little to be gained once the switching is out of the audio spectrum. Except for smaller inductors. Most converters work between 30kHz and 50kHz
500kHz converters using GaN MOSFETs mean inductors and capacitors can be
a lot smaller for high power levels (I doubt you are using GaN's though)! EPC
do some development boards for these new GaN devices.
If you are wanting to generate a carrier wave you probably need to replace the
ceramic resonator with a quartz crystal so you get a stable frequency.
MarkT:
500kHz converters using GaN MOSFETs mean inductors and capacitors can be
a lot smaller for high power levels (I doubt you are using GaN's though)! EPC
do some development boards for these new GaN devices.
If you are wanting to generate a carrier wave you probably need to replace the
ceramic resonator with a quartz crystal so you get a stable frequency.
Good piece of advice...
Yepp, number one is I'm making a buck and a buck-boost converter out of arduino [for feedback based pwm] so that variable in can be made for variable out, depending on logic. [no room for a bunch of programming resistors and selecting one from there like traditional buck converter ICs]. And yes, 200khz is my point of interest due to smaller inductor for both small and high current... [yes, i know both way there are limitations]...
and of course, since i'm gonna use arduino with 16mhz XTAL, i hope that will be smooth... so i can generate CW @ 500khz... [it's a distress beacon]...
and if this seems "ok" to you guys, next then i am looking for a further assistance... how exactly can i make this square pulsating wave in to an AC... [not + and GND but i need - and + (-2.5 - 0 - +2.5)] Any ideas???
So how are you going to detect saturation in the inductor? Once saturated an inductor
becomes just a short length of copper wire and large currents will flow.
MarkT:
So how are you going to detect saturation in the inductor? Once saturated an inductor
becomes just a short length of copper wire and large currents will flow.