VFD

Hi all!
I am new to arduino and am having some issues programming it to put out a pwm 3 phase sin wave for my VFD project. I know the pins only put out a default of 490Hz approx. and was wondering how I can change the freq?
This is a code i have right now but i want to modify it so i can use LED's for visual representation. The code I have now I can basically generate the 3 phase sin waves and control the speed with a 10k Potentiometer. Using timers would be a good option as well.

I'd appreciate any help or input.

Code:
int Output1 = 11;
int Output2 = 10;
int Output3 = 9;
int potVal = 0;
float A = 0;
float B = 0.104;
int Freq_IN = A0;
int var1 = 0;
int var2 = 0;
int var3 = 0;
int var4 = 0;
int var5 = 0;
int var6 = 0;
float Phase1 = 2 * PI / 3;
float Phase2 = 4 * PI / 3;
float Phase3 = 2 * PI;
boolean toggle = true; // true = Enabling Serial Plotter Output
void setup()
{
Serial.begin(9600);
pinMode(Output1, OUTPUT);
pinMode(Output2, OUTPUT);
pinMode(Output3, OUTPUT);
pinMode(Freq_IN, INPUT);
}
void loop()
{
A += B;
analogWrite(Output1, var1);
analogWrite(Output2, var2);
analogWrite(Output3, var3);
if (toggle == true)
{
Serial.print(var1);
Serial.print(" ");
Serial.print(var2);
Serial.print(" ");
Serial.println(var3);
}
var4 = 126 * sin(A + Phase1);
var1 = var4 + 128;
var5 = 126 * sin(A + Phase2);
var2 = var5 + 128;
var6 = 126 * sin(A + Phase3);
var3 = var6 + 128;
if (A >= 2 * PI)
{
A = 0;
}
potVal = analogRead(Freq_IN);
delay(potVal);
}

If you want to go with timers I suggest the Arduino Mega which has more timers and 3 PWM outputs per timer so that only one timer is required for the 3 phases.

If you study existing code you'll find lookup tables (arrays) instead of sin() function calls for higher speed and more steps.

I'm not a programmer so don't know if this can help you, but in this document there is an HEX table (table IIIa) for a 360 degrees sine wave ...

Anyway, if you want to make smooth gradient color changes, you probably have to keep in consideration also that the human eye does not have the same sensibility to all colors (other than the fact that sine is not the better way to obtain it), and modify the sequences for compensate this ...

DrDiettrich:
If you want to go with timers I suggest the Arduino Mega which has more timers and 3 PWM outputs per timer so that only one timer is required for the 3 phases.

If you study existing code you'll find lookup tables (arrays) instead of sin() function calls for higher speed and more steps.

Okay :), i'm not exactly sure how to do it.. but i will try that

Hello,
What you are trying to do will not give accurate sine waves. But if the result is OK, it is OK to you.
If you enable the plotter, Serial.print() will change the speed of the main loop, so B also needs to change to have decent wave forms. (depending on the frequency).
You might consider:

  • An array where your sin() values are stored (as advised by other forum members)
  • A hardware timer-based interrupt hander that selects the right values out of these arrays and increments A with the proper value of B. The value of B is defined by the potmeter;
    Using delay(potVal) creates a freeze in your outputs, but i do not assume (unless i am wrong) that you want a sine wave that looks like a stair?
    Best Regards,
    Johi.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
https://forum.arduino.cc/index.php?topic=712198.0
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

I think you will get more responses by editing the subject to this thread.
VFD
Does not really say what you want advice on.
You can go and edit it to something like.

PWM frequency for 3phase VFD (Variable Frequency Drive) project.

Tom... :slight_smile:
PS. What model Arduino are you using?

Well, "VFD" actually stands for Vacuum Fluorescent Display. :astonished:

So without clarification, the subject heading is misleading. :roll_eyes:

Hi,

Tom... :slight_smile:

Paul__B:
Well, "VFD" actually stands for Vacuum Fluorescent Display. :astonished:

Well actually VFD is a track on Michelle Shocked's album Short, Sharp, Shocked.

Lots of things wrong with this. For one your pointer wrap round is wrong for a fractional incremented pointer, it should be

   if (A >= 2 * PI)
  {
    A -= 2 * PI;
  }

Then as DrDiettrich says, put only one look up table in and array and use three pointers to extract the right phase of the wave.

Don’t use print it slow as thing down tremendously.

Don’t do this

 delay(potVal);

Use the pot value to map a value to the pointer increment, so you can change the speed without killing the processor stone dead for a time.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.