View previous topic :: View next topic |
Author |
Message |
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Thu Jan 11, 2018 4:26 pm Post subject: Two Stepper motor at different speeds |
|
|
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 |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Fri Jan 12, 2018 9:36 am Post subject: |
|
|
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 |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Fri Jan 12, 2018 3:33 pm Post subject: |
|
|
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 |
|
|
Per Svensson
Joined: 03 Oct 2004 Posts: 235 Location: Gothenburg, Sweden
|
|
Back to top |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Thu Jan 18, 2018 7:44 am Post subject: |
|
|
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 |
|
|
|