Salve a tutti. Qualche tempo fa mi è passato per la testa di realizzare un inverter a tre fasi tipo VFD per un motore di lavatrice che necessita di un alimentazione trifase con frequenza da 15 a 300Hz. Ho trovato questo sketch online e devo dire funziona davvero molto bene:
/*
* transistor - pin
*/
#define VT1 6
#define VT2 9
#define VT3 3
#define VT4 5
#define VT5 10
#define VT6 11
#define RELAY 2
/*
* max and min delay in microsecond
* must be <16300
* use for setup frequency
*/
#define MAX_FREQ 12150 // ~15 Hz
#define MIN_FREQ 1575 // 1575 for 100 Hz
/*
* pin A0 - SET_FREQ frequency setup potentiometer
* pin A1 - SET_K_ZAP filling factor setup potetiometer
*/
#define SET_FREQ A0
#define SET_K_ZAP A1
void setup() {
// put your setup code here, to run once:
pinMode(VT1, OUTPUT);
pinMode(VT2, OUTPUT);
pinMode(VT3, OUTPUT);
pinMode(VT4, OUTPUT);
pinMode(VT5, OUTPUT);
pinMode(VT6, OUTPUT);
pinMode(RELAY, OUTPUT);
//Serial.begin(9600);//закомментировать!
digitalWrite(RELAY, LOW); //IR2132 off on setup time/
analogWrite(VT1, 255);//all VTx close/
analogWrite(VT2, 255);//on HINx, LINx (inputs IR2132) +5 V/
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
pinMode(SET_FREQ, INPUT);
pinMode(SET_K_ZAP, INPUT);
//set 4-5kHz frequncy for PWM/
TCCR0B = TCCR1B & 0b11111000 | B00000010;
TCCR1B = TCCR1B & 0b11111000 | B00000010;
TCCR2B = TCCR1B & 0b11111000 | B00000010;
delay(5000);
digitalWrite(RELAY, HIGH); //turn on relay and wait 5 seconds/
delay(5000);
}
int sw_time = 60;
int K_zap = 130;
//int time_start;
void pwm_loop_fwd_a2(void)/*alpha/2 mode - transistors work 1/2 of period. three of them simultaneously */
{
int iteration;
for (iteration = 1; iteration <= 6; iteration++)
{
switch ( iteration )
{
case 1:
analogWrite(VT1, 255);//all VTx close/
analogWrite(VT2, 255);//on HINx, LINx (inputs IR2132) +5 V/
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
analogWrite(VT1, K_zap);//open VTx on K_zap value 255 = close, 0 = full open (inverse logic)/
analogWrite(VT3, K_zap);
analogWrite(VT5, K_zap);
delayMicroseconds(sw_time);
break;
case 2:
analogWrite(VT1, 255);
analogWrite(VT2, 255);
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
analogWrite(VT1, K_zap);
analogWrite(VT5, K_zap);
analogWrite(VT6, K_zap);
delayMicroseconds(sw_time);
break;
case 3:
analogWrite(VT1, 255);
analogWrite(VT2, 255);
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
analogWrite(VT1, K_zap);
analogWrite(VT2, K_zap);
analogWrite(VT6, K_zap);
delayMicroseconds(sw_time);
break;
case 4:
analogWrite(VT1, 255);
analogWrite(VT2, 255);
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
analogWrite(VT4, K_zap);
analogWrite(VT2, K_zap);
analogWrite(VT6, K_zap);
delayMicroseconds(sw_time);
break;
case 5:
analogWrite(VT1, 255);
analogWrite(VT2, 255);
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
analogWrite(VT4, K_zap);
analogWrite(VT2, K_zap);
analogWrite(VT3, K_zap);
delayMicroseconds(sw_time);
break;
case 6:
analogWrite(VT1, 255);
analogWrite(VT2, 255);
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
analogWrite(VT4, K_zap);
analogWrite(VT5, K_zap);
analogWrite(VT3, K_zap);
delayMicroseconds(sw_time);
break;
default:
delayMicroseconds(sw_time);
break;
}
}
}
/*
A0 - SET_FREQ frequency setup
A1 - SET_K_ZAP setup K_zap
*/
int repeat_count = 200;
int i;
void loop()
{
sw_time = map(analogRead(SET_FREQ), 0, 1023, 1, 100);
//on high frequency greater repeats, without arduino functions. Need for frequency stability/
repeat_count = map(sw_time, 1, 100, 400, 100);
/*calculate K_zap - filling coefficient
* 255 = close transistor, 0 = full open transistor (inverse logic)
*/
K_zap = map(analogRead(SET_K_ZAP), 0, 1023, 255, 1);
if (K_zap > 220)//stop
{
analogWrite(VT1, 255);//all VTx close/
analogWrite(VT2, 255);//on HINx, LINx (inputs IR2132) +5 V/
analogWrite(VT3, 255);
analogWrite(VT4, 255);
analogWrite(VT5, 255);
analogWrite(VT6, 255);
delayMicroseconds(sw_time);
}
else //generation ~3-phase voltage
{
// time_start = millis();
for (i = 1; i <= repeat_count; i++)
{
pwm_loop_fwd_a2();
if (!(i % 10))
{
sw_time = map(analogRead(SET_FREQ), 0, 1023, MIN_FREQ, MAX_FREQ);
K_zap = map(analogRead(SET_K_ZAP), 0, 1023, 255, 1);
}
}
// time_start = millis() - time_start;
//Serial.print("FREQUENCY: "); Serial.println(1000. / time_start * repeat_count);
}
//Serial.println(sw_time);
//Serial.println(K_zap);
//Serial.println();
}
Unico problema che mi funziona solo da 15 a 100Hz... Qualcuno di voi può aiutarmi ad aumentare la frequenza massima fino a 300Hz? Grazie in anticipo a chi mi aiuterà.