p kj
/
LPC824-BalanceCar
Microduino
Fork of BalanceCar by
Diff: Microduino_Stepper.h
- Revision:
- 0:a4d8f5b3c546
- Child:
- 2:99785a1007a4
diff -r 000000000000 -r a4d8f5b3c546 Microduino_Stepper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Microduino_Stepper.h Sat Jun 04 03:16:52 2016 +0000 @@ -0,0 +1,90 @@ +// Microduino_Stepper.cpp +// +// Copyright (C) 2009-2013 Shenyang +// $Id: Microduino_Stepper.cpp,v 1.00 2016/04/07 $ + +#ifndef __MICRODUINO_STEPPER_H__ +#define __MICRODUINO_STEPPER_H__ + +#include "mbed.h" +#include "MicroduinoPinNames.h" +#include <stdlib.h> +//#include <Arduino.h> + +//#define _useTimer1 +#define MAX_SPEED_S 4096 +#define TIMER_COMP 327680/MAX_SPEED_S + + +#define PIN_SET(pin) (*portOutputRegister(digitalPinToPort(pin)) |= digitalPinToBitMask(pin)) +#define PIN_CLR(pin) (*portOutputRegister(digitalPinToPort(pin)) &= ~digitalPinToBitMask(pin)) + +#define MAX_STEPPERS 4 +#define INVALID_STEPPER 255 + +#if 0 +#define PIN_EN 4 //PORTB,0 +#define PIN_DIRA A0 //PORTA,7 +#define PIN_STEPA 5 //PORTB,1 +#define PIN_DIRB A1 //PORTA,6 +#define PIN_STEPB 6 //PORTB,2 +#define PIN_DIRC A2 //PORTA,5 +#define PIN_STEPC 7 //PORTB,3 +#define PIN_DIRD A3 //PORTA,4 +#define PIN_STEPD 8 //PORTD,6 +#else +#define PIN_EN D4 +#define PIN_DIRA A0 +#define PIN_STEPA D5 +#define PIN_DIRB A1 +#define PIN_STEPB D6 +#define PIN_DIRC A2 +#define PIN_STEPC D7 +#define PIN_DIRD A3 +#define PIN_STEPD D8 +#endif + +#define DEFAULT_ACCEL 120 + +void stepperAllEnable(); +void stepperAllDisable(); + +class Stepper +{ +public: + + Stepper(uint8_t _dirPin, uint8_t _stepPin); + + uint8_t begin(); + + void setSpeed(int16_t _speed); + + void setMaxAccel(uint16_t _accel); + + int16_t getSpeed(); + + uint16_t getMaxAccel(); + + void computeStep(); + +private: + + gpio_t dirOUT; + gpio_t stepOUT; + uint8_t stepperIndex; + uint8_t dirPin; + uint8_t stepPin; + int16_t speed; + uint16_t maxAccel; + uint16_t period; + uint16_t counter; + +}; + +typedef struct { + //uint8_t isActive = false; + uint8_t isActive; + Stepper *stepper; +} Stepper_t; + +#endif