So I already have a 3 phase inverter that I have to use in controlling a high speed bldc motor which basically drives a cryo chamber which further cools a gas.
I have been trying various algorithms to drive the motor using arduino. the thing is, the code ive developed works, but ive only been able to achieve 25 percent of the motor's rated speed. This is a reverse engineering project, so basic details about the motor are not known, so im basically beating around the bush.
the motor is sensored, which makes coding it's drive easier. now, all i'm asking is, is it possible to kick up the frequency of the pwm signals to make it drive faster?
//const int FULL_TIME = 25000;
//const int STEP_TIME = FULL_TIME / 6;
//int count = 0;
const int DEAD_TIME = 10;
int HallState1; //Variables for the three hall sensors (3,2,1)
int HallState2;
int HallState3;
int HallVal = 1; //binary value of all 3 hall sensors
//int mspeed = 0; //speed level of the motor
//int bSpeed = 0; //braking level
int throttle = 0; //this variable is used with analog in to measure the position of the throttle potentiometer
// Pins to write to
const int DRIVER_PIN2 = 7;
const int DRIVER_PIN5 = 8;
const int DRIVER_PIN6 = 9;
const int DRIVER_PIN3 = 10;
const int DRIVER_PIN4 = 11;
const int DRIVER_PIN1 = 12;
void setup() {
// count = 0;
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A0,INPUT);
pinMode(DRIVER_PIN1, OUTPUT);
pinMode(DRIVER_PIN2, OUTPUT);
pinMode(DRIVER_PIN3, OUTPUT);
pinMode(DRIVER_PIN4, OUTPUT);
pinMode(DRIVER_PIN5, OUTPUT);
pinMode(DRIVER_PIN6, OUTPUT);
// digitalWrite(DRIVER_PIN1, LOW);
// digitalWrite(DRIVER_PIN2, LOW);
// digitalWrite(DRIVER_PIN3, LOW);
// digitalWrite(DRIVER_PIN4, HIGH);
// digitalWrite(DRIVER_PIN5, HIGH);
// digitalWrite(DRIVER_PIN6, HIGH);
throttle = analogRead(A0); //value of the throttle potentiometer
// mspeed = map(throttle, 0, 1023, 0, 255); //motoring is mapped to the top half of potentiometer
// int prescalerVal = 0x07; //create a variable called prescalerVal and set it equal to the binary number "00000111" number "00000111" number "00000111"
//TCCR1B &= ~prescalerVal; //AND the value in TCCR1B with binary number "11111000"
//Now set the appropriate prescaler bits:
// int prescalerVal2 = 1; //set prescalerVal equal to binary number "00000001"
//TCCR1B |= prescalerVal2; //OR the value in TCCR0B with binary number "00000001"
// Set PWM for pins 3,11 to 32 kHz (Only pin 11 is used in this program)
//First clear all three prescaler bits:
// TCCR2B &= ~prescalerVal; //AND the value in TCCR2B with binary number "11111000"
// TCCR2B |= prescalerVal2; //OR the value in TCCR2B with binary number "00000001"//First clear all three prescaler bits:
// TCCR4B &= ~prescalerVal; //AND the value in TCCR4B with binary number "11111000"
// TCCR4B |= prescalerVal2; //OR the value in TCCR4B with binary number "00000001"//First clear all three prescaler bits:
digitalWrite(DRIVER_PIN4, LOW);
delayMicroseconds(throttle/6);
digitalWrite(DRIVER_PIN1,LOW);
digitalWrite(DRIVER_PIN3, LOW);
digitalWrite(DRIVER_PIN5, HIGH); // this is mspeed
digitalWrite(DRIVER_PIN2, LOW);
digitalWrite(DRIVER_PIN6, HIGH); // this is 255
//Serial.begin(115200);
}
void loop() {
throttle = analogRead(A0); //value of the throttle potentiometer
int delay = map(throttle, 0, 1023, 0, 50);
HallState1 = digitalRead(A2);
HallState2 = digitalRead(A3);
HallState3 = digitalRead(A4);
HallVal = (HallState1*4) + (2*HallState2) + (HallState3);
delayMicroseconds(delay/6);
switch(HallVal) {
case 4:
// analogWrite(DRIVER_PIN4, 0);
delayMicroseconds(DEAD_TIME);
digitalWrite(DRIVER_PIN1, LOW);//0
// analogWrite(DRIVER_PIN3, 0);
digitalWrite(DRIVER_PIN5, HIGH); //mspeed
// analogWrite(DRIVER_PIN2, 0);
// analogWrite(DRIVER_PIN6, 255);
break;
case 6:
digitalWrite(DRIVER_PIN4, HIGH);//255
delayMicroseconds(DEAD_TIME);
// analogWrite(DRIVER_PIN1, mspeed);
// analogWrite(DRIVER_PIN3, 255);
// analogWrite(DRIVER_PIN5, 255);
// analogWrite(DRIVER_PIN2, 0);
digitalWrite(DRIVER_PIN6, LOW);//0
break;
case 2:
delayMicroseconds(DEAD_TIME);
// analogWrite(DRIVER_PIN1, 255);
digitalWrite(DRIVER_PIN3, HIGH);//mspeed
digitalWrite(DRIVER_PIN5, LOW);//0
// analogWrite(DRIVER_PIN4, 255);
// analogWrite(DRIVER_PIN6, mspeed);
// analogWrite(DRIVER_PIN2, 255);
break;
case 3:
delayMicroseconds(DEAD_TIME);
// analogWrite(DRIVER_PIN1, 255);
// analogWrite(DRIVER_PIN3, mspeed);
// analogWrite(DRIVER_PIN5, 255);
digitalWrite(DRIVER_PIN4, LOW);//0
// analogWrite(DRIVER_PIN6, 255);
digitalWrite(DRIVER_PIN2, HIGH); //255
break;
case 1:
delayMicroseconds(DEAD_TIME);
digitalWrite(DRIVER_PIN1, HIGH); //mspeed
digitalWrite(DRIVER_PIN3, LOW); //0
// analogWrite(DRIVER_PIN5, 0);
// analogWrite(DRIVER_PIN4, mspeed);
// analogWrite(DRIVER_PIN6, 255);
// analogWrite(DRIVER_PIN2, 255);
break;
case 5:
delayMicroseconds(DEAD_TIME);
// analogWrite(DRIVER_PIN1, 255);
// analogWrite(DRIVER_PIN3, 255);
// analogWrite(DRIVER_PIN5, mspeed);
// analogWrite(DRIVER_PIN4, 255);
digitalWrite(DRIVER_PIN6, HIGH); // 255
digitalWrite(DRIVER_PIN2, LOW); //0
break;
}
//count = (count + 1) % 6;
}
Ignore the commented out stuff.
Also, is it possible to generate the sgnals using timers? because syncing 3 timers together with a difference of exactly 120 degrees in angle looks impossible. I cant seem to wrap my head around it. Any help would be appreciated. I'll code it myself obviously, I just need more options. especially when it comes to algorithm. Is there a better way to do this?
Basic objective here, kicking up the frequency!
this code works btw