Changing the code to run faster - direct port manipulation HELP!
hello,
i need program faster communication between encoder , arduino mini pulse , direction pin.
i enclose old program works @ higher speed encoderja losing signal faster movement of stepper motor.
replaced direct manipulation port. program has no errors not work.
i need program faster communication between encoder , arduino mini pulse , direction pin.
i enclose old program works @ higher speed encoderja losing signal faster movement of stepper motor.
code: [select]
void setup () {
//set various outputs
pinmode(motor_step, output);
pinmode(motor_direction, output);
// encoder inputs
pinmode(encoder_a, input);
pinmode(encoder_b, input);
// enable pullup using open collector encoder
digitalwrite(encoder_a, high);
digitalwrite(encoder_b, high);
// encoder pin on interrupt 0 (pin 2)
attachinterrupt(0, encoderpinchangea, change);
// encoder pin on interrupt 1 (pin 3)
attachinterrupt(1, encoderpinchangeb, change);
encoder = 0; //reseet encoder position 0
}
void loop() {
//do stuff dependent on encoder position here
//such move stepper motor match encoder position
//if want make 1:1 ensure encoder res matches motor res dividing/multiplying
if (encoder > 0) {
digitalwrite(motor_direction, high);// move stepper in reverse
digitalwrite(motor_step, high);
digitalwrite(motor_step, low);
delaymicroseconds(600); //_delay_us(200); //modify alter speed
motor_position++;
encoder = 0; //encoder--;
}
else if (encoder < 0) {
digitalwrite (motor_direction, low); //move stepper forward
digitalwrite (motor_step, high);
digitalwrite (motor_step, low);
delaymicroseconds(600); //_delay_us(200); //modify alter speed
motor_position--;
encoder = 0; //encoder++;
}
}
replaced direct manipulation port. program has no errors not work.
code: [select]
void setup () {
//set various outputs
pinmode(motor_step, output);
pinmode(motor_direction, output);
// encoder inputs
pinmode(encoder_a, input);
pinmode(encoder_b, input);
// enable pullup using open collector encoder
digitalwrite(encoder_a, high);
digitalwrite(encoder_b, high);
// encoder pin on interrupt 0 (pin 2)
attachinterrupt(0, encoderpinchangea, change);
// encoder pin on interrupt 1 (pin 3)
attachinterrupt(1, encoderpinchangeb, change);
encoder = 0; //reseet encoder position 0
}
void loop() {
//do stuff dependent on encoder position here
//such move stepper motor match encoder position
//if want make 1:1 ensure encoder res matches motor res dividing/multiplying
if (encoder > 0) {
//digitalwrite(motor_direction, high);// move stepper in reverse
portd = portd | 0b00100000;
//digitalwrite(motor_step, high);
portd = portd | 0b00010000;
//digitalwrite(motor_step, low);
portd = portd & 0b11101111;
delaymicroseconds(600); //_delay_us(200); //modify alter speed
motor_position++;
encoder = 0; //encoder--;
}
else if (encoder < 0) {
//digitalwrite (motor_direction, low); //move stepper forward
portd = portd & 0b11011111;
//digitalwrite (motor_step, high);
portd = portd | 0b00010000;
//digitalwrite (motor_step, low);
portd = portd & 0b11101111;
delaymicroseconds(600); //_delay_us(200); //modify alter speed
motor_position--;
encoder = 0; //encoder++;
}
}
all of declarations , isr routines missing code won't compile.
Arduino Forum > Using Arduino > Programming Questions > Changing the code to run faster - direct port manipulation HELP!
arduino
Comments
Post a Comment