I will try and keep this initial post short and informative as possible:
Hardware:
Arduino Uno being replaced with Arduino Mega 2560
1k Pot (control the duty of the pwm signal out of arduino)
1k Pot (control the frequency of the PWM Signals)
IRAMS10UP60B on PCB with required cap etc.
Power Supply for the DC bus of the power module
Resistor bank (load to mimic motor for prototyping)
This is the code for single phase DC operation (Only switching the lower V phase):
int PWMUH = 11; // LED connected to digital pin 11
int PWMVH = 10; //LED connected to digital pin 10
int PWMVL = 9; //LED connected to digital pin 9
int PWMWH = 6; //LED connected to digital pin 6 for single phase this will be set high to pull the upper gate open
int PWMWL = 5; //LED connected to digital pin 5 for single phase this will be set high to pull the lower gate open
int PWMUL = 3; //LED connected to digital pin 3
//These Are crossed to ensure that the higher frequency set below is associated with the W phase upper and lower
int PHASEUupper = 0;
int PHASEUlower = 0;
int PHASEVupper = 0;
int PHASEVlower = 0;
int PHASEWupper = 0;
int PHASEWlower = 0;
const int potPin = 0;
int val = 0;
void setup()
{
Serial.begin(9600);
/*
The below adjusts the time function of Timer 0, 1, 2
It must be noted that when adjusting the timers in this way
to adjust frequency functions such as delay() are effected,
for prototype testing this is adequate.
*/
//TCCR0B = TCCR0B & 0b11111000 | 0x02; //Timer 0 Adjustment this will give a frequency value of 7812.5Hz on pins 5&6, due to the different frequency this will be not used for single phase switching
//TCCR1B = TCCR1B & 0b11111000 | 0x02; //Timer 1 Adjustment this will give a frequency value of 3906.25Hz on pins 9&10
//TCCR2B = TCCR2B & 0b11111000 | 0x02; //Timer 2 Adjustment this will give a frequency value of 3906.25Hz on pins 11&3
}
void loop()
{
val=analogRead(potPin);
val=map(val,0,1023,0,255);
PHASEVlower=val;
Serial.print("Val = ");
Serial.println(val);
/*
assign the various integers (above)
to the various pins.
0-255 represents 0-100% Duty Cycle
*/
analogWrite(PWMWH, PHASEWupper);
analogWrite(PWMWL, PHASEWlower);
analogWrite(PWMVH, PHASEVupper);
analogWrite(PWMVL, PHASEVlower);
analogWrite(PWMUH, PHASEUupper);
analogWrite(PWMUL, PHASEUlower);
Serial.print ("PWMVL = ");
Serial.println (PWMVL);
//A delay can be implemented here when testing with LED lights, however this is effected by the adjustment to the timers above to set frequency.
//only use the delay function when the functions in the Void setup loop is commented out.
delay(100);
}
The question is how do i develop single phase AC and three phase AC motor control using the above hardware or with additional required hardware?
How can i adjust the frequency of the PWM in order to change the frequency of the three phase power signal out of the Power Module while running the system?
I know how to set the frequency in the Arduino by changing the prescalers but would like a way to adjust the frequency on the fly with a potentiometer.
This is the three phase code so far when i was using the UNO
int PWMUH = 11; // LED connected to digital pin 11
int PWMVH = 10; //LED connected to digital pin 10
int PWMVL = 9; //LED connected to digital pin 9
int PWMWH = 6; //LED connected to digital pin 6
int PWMWL = 5; //LED connected to digital pin 5
int PWMUL = 3; //LED connected to digital pin 3
//These Are crossed to ensure that the higher frequency set below is associated with the W phase upper and lower
//set the start positions of the various waves
int PHASEUupper = 255;
int PHASEUlower = 0;
int PHASEVupper = 0;
int PHASEVlower = 85;
int PHASEWupper = 0;
int PHASEWlower = 85;
/*
The Below sets the intial direction of travel
this variable is adjusted below to vary the
top and bottom half of each phase
Set the directions of travel
*/
int DirectionUpper1 = 1;
int DirectionUpper2 = 0;
int DirectionUpper3 = 0;
int DirectionLower1 = 0;
int DirectionLower2 =-1;
int DirectionLower3 = 1;
void setup()
{
/*
The below adjusts the time function of Timer 0, 1, 2
It must be noted that when adjusting the timers in this way
to adjust frequency functions such as delay() are effected,
for prototype testing this is adequate.
*/
TCCR0B = TCCR0B & 0b11111000 | 0x02; //Timer 0 Adjustment this will give a frequency value of 7812.5Hz on pins 5&6
TCCR1B = TCCR1B & 0b11111000 | 0x02; //Timer 1 Adjustment this will give a frequency value of 3906.25Hz on pins 9&10
TCCR2B = TCCR2B & 0b11111000 | 0x02; //Timer 2 Adjustment this will give a frequency value of 3906.25Hz on pins 11&3
}
void loop()
{
/*
assign the various integers (above)
to the various pins.
0-255 represents 0-100% Duty Cycle
*/
analogWrite(PWMWH, PHASEWupper);
analogWrite(PWMWL, PHASEWlower);
analogWrite(PWMVH, PHASEVupper);
analogWrite(PWMVL, PHASEVlower);
analogWrite(PWMUH, PHASEUupper);
analogWrite(PWMUL, PHASEUlower);
/*
In the below each phase is checked to see whether
it has reached the top or bottom half of the phase,
when it has it will then ramp up the other half of the phase
*/
if ((PHASEUupper == 255) & (DirectionUpper1 == 1)) { DirectionUpper1 = -1; }
if ((PHASEUupper == 0) & (DirectionUpper1 == -1)) { DirectionUpper1 = 0; DirectionLower1 = +1; } if ((PHASEVupper == 255) & (DirectionUpper2 == 1)) { DirectionUpper2 = -1; }
if ((PHASEVupper == 0) & (DirectionUpper2 == -1)) { DirectionUpper2 = 0; DirectionLower2 = + 1; } if ((PHASEWupper == 255) & (DirectionUpper3 == 1)) { DirectionUpper3 = -1; }
if ((PHASEWupper== 0) & (DirectionUpper3 == -1)) { DirectionUpper3 = 0; DirectionLower3 = +1; } if ((PHASEUlower == 255) & (DirectionLower1 == 1)) { DirectionLower1 = -1; }
if ((PHASEUlower == 0) & (DirectionLower1 == -1)) { DirectionLower1 = 0; DirectionUpper1 = 1; } if ((PHASEVlower == 255) & (DirectionLower2 == 1)) { DirectionLower2 = -1; }
if ((PHASEVlower == 0) & (DirectionLower2 == -1)) { DirectionLower2 = 0; DirectionUpper2 = 1; } if ((PHASEWlower == 255) & (DirectionLower3 == 1)) { DirectionLower3 = -1; }
if ((PHASEWlower == 0) & (DirectionLower3 == -1)) { DirectionLower3 = 0; DirectionUpper3 = 1; }
/*
This section is where the waves are powered up or down.
If you add a positive value to a number, it increments.
But if you add a negative number it /de/crements.
In this way, the pos/neg flipping above makes the waves
travel in the right direction when we do the addition
down here.
*/
PHASEUupper = PHASEUupper + DirectionUpper1;
PHASEVupper = PHASEVupper + DirectionUpper2;
PHASEWupper = PHASEWupper + DirectionUpper3;
PHASEUlower = PHASEUlower + DirectionLower1;
PHASEVlower = PHASEVlower + DirectionLower2;
PHASEWlower = PHASEWlower + DirectionLower3;
/*
A delay can be implemented here when testing with LED lights, however this is effected by the adjustment to the timers above to set frequency.
only use the delay function when the functions in the Void setup loop is commented out.
delay(100);
*/
}