Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Two Stepper motor at different speeds

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
mastermindjp

Bascom Member



Joined: 18 Dec 2012
Posts: 56
Location: INDIA

india.gif
PostPosted: Thu Jan 11, 2018 4:26 pm    Post subject: Two Stepper motor at different speeds Reply with quote

Hello Friends,

I am trying to run two Stepper motors, with same controller, together but at different speeds, but no success..
Take a look at the code and suggest any possible solutions..

Code:

$crystal = 16000000
$hwstack = 40
$regfile = "m32def.dat"
$swstack = 40
$framesize = 40

X_step Alias Portd.4
X_dir Alias Portd.3
Y_step Alias Porta.3
Y_dir Alias Porta.2

Config Y_step = Output
Config X_dir = Output
Config X_step = Output
Config X_dir = Output

Config Porta.4 = Output
Config Portd.5 = Output
Config Pinb.4 = Input
Config Pinb.5 = Input
Config Pinb.6 = Input
Config Pinb.3 = Input

Dim N As Word , M As Word

Porta.4 = 0
Portd.5 = 0

Begin:
Porta.4 = 0
Portd.5 = 0

N = 0
Cls
Lcd "SYSTEM READY"
Waitms 100
If Pinb.4 = 0 Then
       Porta.4 = 1
       Portd.5 = 1
       Do
       Reset Y_dir
       Reset X_dir
       Set Y_step
       Set X_step
       Waitms 2
       Reset Y_step
       Reset X_step
       Waitms 2
       Loop Until Pinb.4 = 1
       Portd.5 = 0
       Porta.4 = 0
       Waitms 100
       End If
If Pinb.5 = 0 Then
       Porta.4 = 1
       Portd.5 = 1
       Do
       Set Y_dir
       Set Y_step
       Waitms 2
       Reset Y_step
       Waitms 2
       Set X_dir
       Set X_step
       Waitus 500
       Reset X_step
       Waitus 500
       Loop Until Pinb.5 = 1
       Portd.5 = 0
       Porta.4 = 0
       Waitms 100
       End If
waitms 100
goto begin


thanks

Regards

Aniruddha

(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.8.1 )

_________________
We are not innovating, we are just manipulating innovations done by Mother Nature.......
Back to top
View user's profile Visit poster's website
mastermindjp

Bascom Member



Joined: 18 Dec 2012
Posts: 56
Location: INDIA

india.gif
PostPosted: Fri Jan 12, 2018 9:36 am    Post subject: Reply with quote

Hello,

Forgot to add, using Stepper Motor Driver,
A4988.

Regards

Aniruddha

_________________
We are not innovating, we are just manipulating innovations done by Mother Nature.......
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1133

poland.gif
PostPosted: Fri Jan 12, 2018 3:33 pm    Post subject: Reply with quote

This should be almost as simply as the software PWM is.
You should define what resolution of steps you need then run some 2xspeed interrupt.
In this interrupt :
->
Code:
if steps for first_motor > 0 then
 If Speed1 = 0 Then
  Decr Speed1
 Else
  Speed1 = My_speed1 'My_speed1 is the divider or countdown for toggle port
   Toggle Clk1
    decr steps_for_first_motor
 End If
End if

if steps for second_motor2 > 0 then
 If Speed2 = 0 Then
  Decr Speed2
 Else
  Speed2 = My_speed2
   Toggle Clk2  'output for clocking second module
    decr steps_for_second_motor
 End If
End if
 


You can also use PWM of Timer1 and Timer2 in PWM8 Bit both....
Vary your needs
Back to top
View user's profile Visit poster's website
Per Svensson

Bascom Member



Joined: 03 Oct 2004
Posts: 238
Location: Gothenburg, Sweden

sweden.gif
PostPosted: Tue Jan 16, 2018 12:17 am    Post subject: Reply with quote

Have a look at this:
https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14042
Back to top
View user's profile Visit poster's website
mastermindjp

Bascom Member



Joined: 18 Dec 2012
Posts: 56
Location: INDIA

india.gif
PostPosted: Thu Jan 18, 2018 7:44 am    Post subject: Reply with quote

Hello friends,

Thank you both of you for the valuable suggestions and link.
Will work on it.

Regards

Aniruddha

_________________
We are not innovating, we are just manipulating innovations done by Mother Nature.......
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum