auto-sync

This commit is contained in:
rusEfi 2015-01-04 12:04:12 -06:00
parent a1bdc8b919
commit 0779d7b4fa
2 changed files with 18 additions and 5 deletions

View File

@ -10,17 +10,27 @@
#include "stepper.h" #include "stepper.h"
#include "pin_repository.h" #include "pin_repository.h"
#define ST_DELAY_MS 200 #define ST_DELAY_MS 10
#define ST_COUNT 200 #define ST_COUNT 100
static msg_t stThread(StepperMotor *motor) { static msg_t stThread(StepperMotor *motor) {
chRegSetThreadName("stepper"); chRegSetThreadName("stepper");
palWritePad(motor->directionPort, motor->directionPin, true);
// let's part the motor in a known position to begin with // let's part the motor in a known position to begin with
for (int i = 0; i < ST_COUNT; i++) { for (int i = 0; i < ST_COUNT; i++) {
motor->pulse(); motor->pulse();
} }
palWritePad(motor->directionPort, motor->directionPin, false);
// let's part the motor in a known position to begin with
for (int i = 0; i < ST_COUNT / 2; i++) {
motor->pulse();
}
} }
void StepperMotor::pulse() { void StepperMotor::pulse() {
@ -36,7 +46,10 @@ void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin) {
stepPort = getHwPort(stepPin); stepPort = getHwPort(stepPin);
this->stepPin = getHwPin(stepPin); this->stepPin = getHwPin(stepPin);
mySetPadMode("st step", stepPort, this->stepPin, PAL_MODE_OUTPUT_PUSHPULL); directionPort = getHwPort(directionPin);
this->directionPin = getHwPin(directionPin);
mySetPadMode2("st step", stepPin, PAL_MODE_OUTPUT_PUSHPULL);
mySetPadMode2("st dir", directionPin, PAL_MODE_OUTPUT_PUSHPULL); mySetPadMode2("st dir", directionPin, PAL_MODE_OUTPUT_PUSHPULL);
chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this); chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this);

View File

@ -13,12 +13,12 @@ class StepperMotor {
public: public:
void initialize(brain_pin_e stepPin, brain_pin_e directionPin); void initialize(brain_pin_e stepPin, brain_pin_e directionPin);
void pulse(); void pulse();
GPIO_TypeDef * directionPort;
ioportmask_t directionPin;
private: private:
GPIO_TypeDef * stepPort; GPIO_TypeDef * stepPort;
ioportmask_t stepPin; ioportmask_t stepPin;
GPIO_TypeDef * directionPort;
ioportmask_t directionPin;
int position; int position;