วันพฤหัสบดีที่ 29 กันยายน พ.ศ. 2559

induction motor speed website



/*

 * VTx - transistors

 * -------------------<<  + DC voltage (i.e. 250 V)

 *    |     |     |

 *    |     |     |

 *   VT1   VT2   VT3

 *    |     |     |

 *    *--------------------a

 *    |     |     |

 *    |     *--------------b

 *    |     |     |

 *    |     |     *--------c

 *   VT4   VT5   VT6

 *    |     |     |

 *    |     |     |

 * -------------------<<   GND

*/



/*

 * transistor - pin

 */

#define VT1 6

#define VT2 7

#define VT3 8

#define VT4 9

#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  // ~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*/

  TCCR1B = TCCR1B & 0b11111000 | 0x02;

  TCCR2B = TCCR1B & 0b11111000 | 0x02;

  TCCR3B = TCCR1B & 0b11111000 | 0x02;

  TCCR4B = TCCR1B & 0b11111000 | 0x02;



  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; /*count of repeats (because on small sw_time high frequency and unstable working*/

int i;//for loop



void loop()

{

  /*set microseconds delay between I..IV phases of work => define frequency */

  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();



}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น