Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
HCMotor Arduino library for driving DC and stepper motors. 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 782
Post Re: HCMotor Arduino library for driving DC and stepper motor
I'm afraid the HCMotor library doesn't have a clock (step) multiplier feature. Mainly as that's not what the library is intended for. Also a TB6560 can only divide down a clock. I believe you need to multiply up your clock by a factor of 8 (?). Depending on your maximum step frequency you'd probably be able to do it with something like an Uno but you'll need a clock multiplier / PLL sketch to do achieve this.

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Mon Jan 29, 2018 10:23 am
Profile

Joined: Wed Mar 14, 2018 10:28 pm
Posts: 2
Post Re: HCMotor Arduino library for driving DC and stepper motor
Hi Andrew, I want to know how to use this code control 4 stepper motors? how to define more then one CLK_PIN in code?
Thanks :D


Thu Mar 15, 2018 4:31 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 782
Post Re: HCMotor Arduino library for driving DC and stepper motor
You can use the HCMotor.attach() function to add more motors (default maximum is 4 motors) like this:

#define MOTOR_PIN0 7
#define MOTOR_PIN1 8
#define MOTOR_PIN2 9
#define MOTOR_PIN3 10

HCMotor.attach(0, STEPPER, MOTOR_PIN0);
HCMotor.attach(1, STEPPER, MOTOR_PIN1);
HCMotor.attach(2, STEPPER, MOTOR_PIN2);
HCMotor.attach(3, STEPPER, MOTOR_PIN3);

From then on when you use any other of the library functions just set the MotorNum parameter to a value of either 0, 1, 2, or 3 depending on which motor you want it to apply to. E.g.

HCMotor.Direction(2, FORWARD);

Sets motor number 2 to the forward direction.

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Fri Mar 16, 2018 11:24 am
Profile

Joined: Wed Mar 14, 2018 10:28 pm
Posts: 2
Post Re: HCMotor Arduino library for driving DC and stepper motor
very helpful. Thanks Andrew!!


Fri Mar 16, 2018 10:00 pm
Profile

Joined: Sat May 05, 2018 3:19 pm
Posts: 1
Post Re: HCMotor Arduino library for driving DC and stepper motor
Hello Andrew! I'm verry newbie, never programmed. Can you help me, how can I add end limit switches to the the code? Example: we have two end point, when one is reach, motor stop, and it can only operate in the opposite direction. I think it would be useful to others too.


Sat May 05, 2018 3:32 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 782
Post Re: HCMotor Arduino library for driving DC and stepper motor
Assuming your endstops are just clean contact switches you can just connect them to a couple of the digital pins on your Arduino. So for example you could connect the common & normally open contacts of the forward endstop to digital pin 3 and ground, and the common & normally open of the reverse direction to digital pin 4 and ground. In either case when the endstop is reached the switch will close and pull the pin low (low = false).

You then need to tell your Arduino that these two pins will be will be 'inputs' by putting this somewhere in the setup() section of the sketch:

Code:
pinMode(3, INPUT_PULLUP);
 pinMode(4, INPUT_PULLUP);



Then on each iteration of the main() loop you can read the state of the two pins by putting this towards the top of the loop:

Code:
boolean Forward_endstop = digitalRead(3);
boolean Reverse_endstop = digitalRead(4);



Finally, in the sections of code that checks the position of the pot to determine which direction to turn the motor in you can add and extra condition that also checks the state of the appropriate endstop. So for the stepper motor example you would change this:

Code:
if (Pot >= POT_REV_MIN && Pot <= POT_REV_MAX)


to this...

Code:
if (Pot >= POT_REV_MIN && Pot <= POT_REV_MAX && Reverse_endstop != false)



and this...


Code:
}else if (Pot >= POT_FWD_MIN && Pot <= POT_FWD_MAX)


to this

Code:
}else if (Pot >= POT_FWD_MIN && Pot <= POT_FWD_MAX && Forward_endstop != false)

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Sun May 06, 2018 7:46 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 16 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD