Help with modifying DC motor code 3phase motor

Hi everybody!

I have been working on my independent project. I am trying to build a speed control that is going to work with arduino and brushless motor. However I am having a problem with coding. I was wondering if anyone can help me to do modifications.

// Pin assignment for first half-bridge
const int IS_1 = A0; // current sense and diagnostics
const int IN_1 = 3; // input (PWM)
const int INH_1 = 12; // inhibit (low = sleep)

// Pin assignment for second half-bridge
const int IS_2 = A1; // current sense and diagnostics
const int IN_2 = 11; // input (PWM)
const int INH_2 = 13; // inhibit (low = sleep)

// Pin assignment for second half-bridge
const int IS_3 = A1; // current sense and diagnostics
const int IN_3 = 11; // input (PWM)
const int INH_3 = 13; // inhibit (low = sleep)

void setup() {
// Set correct input/output state
pinMode(IS_1, INPUT);
pinMode(IN_1, OUTPUT);
pinMode(INH_1, OUTPUT);
pinMode(IS_2, INPUT);
pinMode(IN_2, OUTPUT);
pinMode(INH_2, OUTPUT);
pinMode(IN_3, OUTPUT);
pinMode(INH_3, OUTPUT);
// Set initial output states
analogWrite(IN_1, 0); // set motor speed to 0
digitalWrite(INH_1, HIGH); // enable OUT1
analogWrite(IN_2, 0); // set motor speed to 0
digitalWrite(INH_2, HIGH); // enable OUT2
analogWrite(IN_3, 0); // set motor speed to 0
digitalWrite(INH_3, HIGH); // enable OUT3
}

void loop() {
/*
half bridge mode, two unidirectional motors
motor 1 connected to OUT1 and GND
motor 2 connected to OUT2 and GND
motor 3 connected to OUT3 and GND
*/
forward(127); // motor 1 and motor 2 at half speed
delay(5000);
forward(255); // motor 1 and motor 2 at full speed
delay(5000);
left(127); // motor 1 stopped, motor 2 at half speed
delay(5000);
left(255); // motor 1 stopped, motor 2 at half speed
delay(5000);
right(127); // motor 1 at half speed, motor 2 stopped
delay(5000);
right(255); // motor 1 at half speed, motor 2 stopped
delay(5000);
halt(); // motor 1 and motor 2 stopped
delay(5000);
/*
h-bridge mode, single bidirectional motor
motor connected to OUT1 and OUT2
*/
left(127); // direction 1 at half speed
delay(5000);
left(255); // direction 1 at full speed
delay(5000);
right(127); // direction 2 at half speed
delay(5000);
right(255); // direction 2 at full speed
delay(5000);
halt(); // stop motor
delay(5000);
}

void forward(int motorSpeed) { // motorSpeed from 0 to 255
analogWrite(IN_1, motorSpeed);
analogWrite(IN_2, motorSpeed);
}

void halt() {
analogWrite(IN_1, 0);
analogWrite(IN_2, 0);
}

void left(int motorSpeed) { // in case of two motors: assuming left wheel motor on OUT1 and right wheel motor on OUT2
analogWrite(IN_1, 0);
analogWrite(IN_2, motorSpeed);
}

void right(int motorSpeed) { // in case of two motors: assuming left wheel motor on OUT1 and right wheel motor on OUT2
analogWrite(IN_1, motorSpeed);
analogWrite(IN_2, 0);
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

However I am having a problem with coding.

You plan to tell us what it is, someday?

// Pin assignment for second half-bridge
const int IS_2 = A1; // current sense and diagnostics
const int IN_2 = 11; // input (PWM)
const int INH_2 = 13; // inhibit (low = sleep)

// Pin assignment for second half-bridge
const int IS_3 = A1; // current sense and diagnostics
const int IN_3 = 11; // input (PWM)
const int INH_3 = 13; // inhibit (low = sleep)

Generally, there is work to be done after a copy/paste action. You forgot to do that.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

So we can see what your sketch is attempting to drive.

Thanks...Tom..... :slight_smile: