A4988 module + stepping motor c code for RCM3000 [1 Attachment]

Started by "kar...@yahoo.com [rabbit-semi]" July 24, 2017
Hi, the following is the A4988 module + stepping motor c code for RCM3000,
But stepping motor will only shake without turning, is the program or hardware wiring problems ? thanks.

#use "hobbyist.lib"

#define START_SW HB_PF5
#define MOTOR_STEP HB_PF6
#define MOTOR_DIR HB_PF7
int x;

if(!HBpinRead(START_SW)){
sprintf (status_html, "Start\r");
HBpinHigh(MOTOR_DIR);
for(x = 0; x < 200; x++) {
HBpinHigh(MOTOR_STEP);
waitfor(DelayMs(500));
HBpinLow(MOTOR_STEP);
waitfor(DelayMs(500));
}

waitfor(DelayMs(1000));
In your inner loop, try changing the 500ms delay to a 1ms delay. Sample code on the net uses a 500uS delay (i.e., 0.5ms).

Also, make sure you’ve configured those pins as outputs (something that HBpinHigh() and HBpinLow() might already do for you).

-Tom
> On Jul 23, 2017, at 10:04 PM, k...@yahoo.com [rabbit-semi] wrote:
>
> Hi, the following is the A4988 module + stepping motor c code for RCM3000,
> But stepping motor will only shake without turning, is the program or hardware wiring problems ? thanks.
>
> #use "hobbyist.lib"
>
> #define START_SW HB_PF5
> #define MOTOR_STEP HB_PF6
> #define MOTOR_DIR HB_PF7
> int x;
>
> if(!HBpinRead(START_SW)){
> sprintf (status_html, "Start\r");
> HBpinHigh(MOTOR_DIR);
> for(x = 0; x < 200; x++) {
> HBpinHigh(MOTOR_STEP);
> waitfor(DelayMs(500));
> HBpinLow(MOTOR_STEP);
> waitfor(DelayMs(500));
> }
>
> waitfor(DelayMs(1000));
>
Tom, thanks

Yes,It is workable if waitfor (DelayMs (1));
but motor speed is a bit slow, if the time delay want to change to 0.5ms, is it as follows?

waitfor (DelayTicks (1));

or waitfor (IntervalMs (??)); how does this instruction use ?
kara,

a library (TimerB.lib) from Scott Henion offers you an exact Timer-Interupt.

See here: https://shdesigns.org/rabbit/freelibs.shtml

Barni
Am 25.09.2017 um 12:39 schrieb k...@yahoo.com [rabbit-semi]:
> Tom, thanks
>
>   Yes,It is workable if waitfor (DelayMs (1));
> but motor speed is a bit slow, if the time delay want to change to
> 0.5ms, is it as follows?
>
> waitfor (DelayTicks (1));
>
> or waitfor (IntervalMs (??)); how does this instruction use ?
Hi, Barni, Got it, I will study this, thanks for your help.
Kara