stepper motor controling using matlab GUI, speed very slow


hi everyone, got problem stepper motor controlling using matlab gui--the motor rotates compared using same code on arduino ide.
there arduino code used

code: [select]
#define steppin 5
#define dirpin 6

int pauseje2schritte = 400;  // pause between 2 steps
int zahlderschritte = 1000;  // how many steps motor rotates
 
void setup() {
  serial.begin(9600);
  serial.println("starting stepper exerciser.");

  pinmode(steppin, output);
  pinmode(dirpin, output);

  digitalwrite(dirpin, high);
  digitalwrite(steppin, low);
 

}

    void loop() {
 
      digitalwrite(dirpin,high); // enables motor move in particular direction
      // makes 200 pulses making 1 full cycle rotation
      for(int x = 0; x < zahlderschritte; x++) {
        digitalwrite(steppin,high);
        delaymicroseconds(pauseje2schritte);
        digitalwrite(steppin,low);
        delaymicroseconds(pauseje2schritte);
      }
      delay(1000); // 1 second delay
     
      digitalwrite(dirpin,low); //changes rotations direction
      // makes 400 pulses making 2 full cycle rotation
      for(int x = 0; x < zahlderschritte; x++) {
        digitalwrite(steppin,high);
        delaymicroseconds(pauseje2schritte);
        digitalwrite(steppin,low);
        delaymicroseconds(pauseje2schritte);
      }
      delay(1000);
     
      digitalwrite(steppin,low);
      delay(3000);
     
    }


there part of matlab gui code

code: [select]
function pushbutton1_callback(hobject, eventdata, handles)
% hobject    handle pushbutton1 (see gcbo)
% eventdata  reserved - defined in future version of matlab
% handles    structure handles , user data (see guidata)
global a;
global pauseje2schritte;
writedigitalpin(a,'d6',1);
% pauseje2schritte = 0.0000001;
zahlderschritte= 300;

for x = 1:zahlderschritte
    writedigitalpin(a,'d5',1);
       
    pause(pauseje2schritte);
       
    writedigitalpin(a,'d5',0);
       
    pause(pauseje2schritte);
       
end


i read lot , reason may communication between matlabgui , arduino board needs more time. don't find solution. have idea how improve speed?? appreciate

i not familiar matlab can certainty impractical send individual step instructions pc program arduino. usb system slow small amounts of data , has unpredictable latency.

my suggestion send arduino message telling how many steps take , interval between steps , let on - example <400, 20> 400 steps , 20 millisecs between steps. how control motors on small lathe.

...r
stepper motor basics
simple stepper code


Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > stepper motor controling using matlab GUI, speed very slow


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'