Created
December 27, 2014 10:45
-
-
Save d2rk/0c1fadd3ea1045527619 to your computer and use it in GitHub Desktop.
Test four-wire stepper motor with Propeller QuickStart board and A4988 stepper motor driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Press button FORWARD_BUTTON_ID to drive forward/backward and BACKWARD_BUTTON_ID to drive backward/forward respectively. | |
* | |
* How to compile: | |
* $ propeller-elf-gcc -mlmm -std=c99 test_stepper_motor.c -o test_stepper_motor | |
* | |
* How to load (EEPROM) and run: | |
* $ propeller-load -r -e test_stepper_motor | |
*/ | |
#include <propeller.h> | |
#define FORWARD_BUTTON_ID 7 | |
#define BACKWARD_BUTTON_ID 5 | |
#define STEP_PIN 8 | |
#define DIRECTION_PIN 9 | |
#define STEP_DELAY 10 | |
#define PAUSE(time) waitcnt((time * (CLKFREQ / 1000)) + CNT) | |
int main() { | |
int result; | |
char pin; | |
_DIRA |= 1 << STEP_PIN; | |
_DIRA |= 1 << DIRECTION_PIN; | |
while (1) { | |
result = INA & (unsigned)(0xFF); | |
for (pin = 0; pin < 16; pin++, result >>= 1) { | |
if ((result & 1UL) == 0) { | |
_OUTA &= ~(1 << (pin + 16)); | |
} else { | |
_OUTA |= 1 << (pin + 16); | |
} | |
if (result & 1UL) { | |
switch (pin) { | |
case FORWARD_BUTTON_ID: | |
_OUTA |= 1 << DIRECTION_PIN; | |
break; | |
case BACKWARD_BUTTON_ID: | |
_OUTA &= ~(1 << DIRECTION_PIN); | |
break; | |
} | |
_OUTA |= 1 << STEP_PIN; | |
PAUSE(STEP_DELAY); | |
_OUTA &= ~(1 << STEP_PIN); | |
PAUSE(STEP_DELAY); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment