View previous topic :: View next topic |
Author |
Message |
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Fri Sep 22, 2017 11:59 am Post subject: Is this a right way to write code for Stepper Motor? |
|
|
Hello friends,
i have written a code for stepper control, its working, but i would like to know is it the right way to write this code or can be modified?? I have used L298 as the driver IC and stepper is a NEMA24 Bipolar 24V motor (current per phase is 2.8Amp).
Code: |
$crystal = 16000000
$hwstack = 32
$regfile = "m32def.dat"
$swstack = 10
$framesize = 40
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.3 = Output
Config Portd.4 = Output
Do
Portd = 4
Waitms 2
Portd = 16
Waitms 2
Portd = 2
Waitms 2
Portd = 8
Waitms 2
Loop
|
further, how can i control its speed, apart from using PWM with the enable pin of L298? can i change delay in between using ADC?
Thanks
Regards
Aniruddha
(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.7.8 ) _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
luizabbadia
Joined: 11 Dec 2007 Posts: 112 Location: rio de janeiro
|
Posted: Fri Sep 22, 2017 8:23 pm Post subject: |
|
|
Hi! I think there will be many ways to do it, but, as a start point:
I remember there is a link to Glena program
https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=6800&highlight=
Itīs a eight servo controller and maybe, with little study you can modify it in such a manner that youīll use 4 channels alternating like this:
Channel#1 -> the first wire of the stepper motor, channel #2 will be one delay, channel#3 the second wire of the stepper motor, channel #4 another delay and so on untill you use 8 channels and 4 wires, being 4 channels to deal with and compose your delay that will affect the speed, but I donīt know how much.
It is not the best way but youīll have an excellent program from the shelf in your hands, oppotunity to learn a lot and other advantages, I am not a great programmer but Iīd start with this program and thank Glena a lot for this .
Hope you get there!! |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Sat Sep 23, 2017 7:21 am Post subject: |
|
|
RC servo <> stepper motor. |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
|
Back to top |
|
|
luizabbadia
Joined: 11 Dec 2007 Posts: 112 Location: rio de janeiro
|
Posted: Sat Sep 23, 2017 12:32 pm Post subject: |
|
|
Yes step motor <> RC motor, but in terms of interface.
About timing, using Glena code you can do it...yes you can use Arduino Uno + CNC Shield or Mega2560 and Ramps as interface...but the timing can be achieved with Glena code changing the 20mS interval in between pulses and the pulses in between the phase pulses...exotic...or use GRBL ...if you will but...thatīs not Bascom... |
|
Back to top |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Sat Sep 23, 2017 2:29 pm Post subject: |
|
|
Hello Duval JP Sir,
Thank you for the nice and fast examples.
I will go through it.
Thank You
Regards
Aniruddha _________________ 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: Sat Sep 23, 2017 2:31 pm Post subject: |
|
|
Hello luizabbadia,
Thank you for sharing the link, i can use that in my other projects also containing Servos..
Thank you
Regards
Aniruddha _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
luizabbadia
Joined: 11 Dec 2007 Posts: 112 Location: rio de janeiro
|
Posted: Sat Sep 23, 2017 2:55 pm Post subject: |
|
|
Glad to help! |
|
Back to top |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Mon Oct 09, 2017 8:34 am Post subject: |
|
|
Hello friends,
Ok i tried with the solution Duval JP sir suggested, did some changes in the code and i got it working with adjustable speed (RPM) using a simple POT at ADC of controller.
Although its highest speed is not achieved as the maximum phase current A4988 can deliver is 2 AMP, whereas Stepper needs 2.8 AMP phase current. So i am planning to make a MOSFET based driver for the stepper.
Here is the code
Code: | $regfile = "m32def.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 40
$framesize = 40
Config Adc = Single , Prescaler = Auto
Stop Adc
'A4988 steppermotor drivers
X_step Alias Portd.2
X_dir Alias Portd.1
Config X_step = Output
Config X_dir = Output
Dim Us As Word
Dim X As Word
Start Adc
Do
Reset X_dir
X = Getadc(0)
If X < 300 Then X = 300
Us = X
Set X_step
Waitus Us
Reset X_step
Waitus Us
Loop
End |
Thank you friends, any suggestions to improve?
Regards
Aniruddha _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
|