simple library for applying number of steps, direction, speed and a linear acceleration-deceleration to a Stepper Motor Controller

Dependents:   16A_Autopancakemaker

Committer:
franzachatz
Date:
Wed Nov 03 18:41:28 2010 +0000
Revision:
2:ad11f550b379
Parent:
1:ef0414c3ce83
added some doc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
franzachatz 0:27b548e34acc 1 /* mbed Stepper Library
franzachatz 0:27b548e34acc 2 * Copyright (c) 2010 fachatz
franzachatz 0:27b548e34acc 3 *
franzachatz 0:27b548e34acc 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
franzachatz 0:27b548e34acc 5 * of this software and associated documentation files (the "Software"), to deal
franzachatz 0:27b548e34acc 6 * in the Software without restriction, including without limitation the rights
franzachatz 0:27b548e34acc 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
franzachatz 0:27b548e34acc 8 * copies of the Software, and to permit persons to whom the Software is
franzachatz 0:27b548e34acc 9 * furnished to do so, subject to the following conditions:
franzachatz 0:27b548e34acc 10 *
franzachatz 0:27b548e34acc 11 * The above copyright notice and this permission notice shall be included in
franzachatz 0:27b548e34acc 12 * all copies or substantial portions of the Software.
franzachatz 0:27b548e34acc 13 *
franzachatz 0:27b548e34acc 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
franzachatz 0:27b548e34acc 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
franzachatz 0:27b548e34acc 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
franzachatz 0:27b548e34acc 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
franzachatz 0:27b548e34acc 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
franzachatz 0:27b548e34acc 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
franzachatz 0:27b548e34acc 20 * THE SOFTWARE.
franzachatz 0:27b548e34acc 21 */
franzachatz 0:27b548e34acc 22 #ifndef MBED_STEPPER_H
franzachatz 0:27b548e34acc 23 #define MBED_STEPPER_H
franzachatz 0:27b548e34acc 24
franzachatz 0:27b548e34acc 25 #include "mbed.h"
franzachatz 0:27b548e34acc 26
franzachatz 0:27b548e34acc 27 /** Stepper control class
franzachatz 0:27b548e34acc 28 *
franzachatz 0:27b548e34acc 29 * Example:
franzachatz 0:27b548e34acc 30 * @code
franzachatz 0:27b548e34acc 31 * // apply number of steps, direction, speed and
franzachatz 2:ad11f550b379 32 * // a linear acceleration/deceleration to a Stepper Motor Controller
franzachatz 0:27b548e34acc 33 * #include "mbed.h"
franzachatz 0:27b548e34acc 34 * #include "stepper.h"
franzachatz 0:27b548e34acc 35 *
franzachatz 0:27b548e34acc 36 * #define ACCEL_ON 1
franzachatz 0:27b548e34acc 37 * #define ACCEL_OFF 0
franzachatz 0:27b548e34acc 38 * #define SPEED 100
franzachatz 0:27b548e34acc 39 *
franzachatz 2:ad11f550b379 40 * stepper x(P18,P21);
franzachatz 2:ad11f550b379 41 * stepper y(P19,P22);
franzachatz 2:ad11f550b379 42 * stepper z(P20,P23);
franzachatz 0:27b548e34acc 43 *
franzachatz 0:27b548e34acc 44 * int main()
franzachatz 0:27b548e34acc 45 * {
franzachatz 0:27b548e34acc 46 * x.step(1000,1,SPEED,ACCEL_ON);
franzachatz 0:27b548e34acc 47 * y.step(5000,0,SPEED,ACCEL_ON);
franzachatz 0:27b548e34acc 48 * z.step(2000,1,SPEED,ACCEL_ON);
franzachatz 0:27b548e34acc 49 *
franzachatz 0:27b548e34acc 50 * }
franzachatz 0:27b548e34acc 51 * @endcode
franzachatz 0:27b548e34acc 52 */
franzachatz 0:27b548e34acc 53 class stepper {
franzachatz 0:27b548e34acc 54
franzachatz 0:27b548e34acc 55 public:
franzachatz 0:27b548e34acc 56
franzachatz 0:27b548e34acc 57 /** Create a stepper object connected to the specified clk pin and dir pin
franzachatz 0:27b548e34acc 58 *
franzachatz 0:27b548e34acc 59 * @param pin clk pin to connect to
franzachatz 0:27b548e34acc 60 * @param pin dir pin to connect to
franzachatz 0:27b548e34acc 61 */
franzachatz 0:27b548e34acc 62 stepper(PinName clk, PinName dir);
franzachatz 0:27b548e34acc 63
franzachatz 0:27b548e34acc 64 /** Set number of steps to direction with speed and
franzachatz 2:ad11f550b379 65 * a linear acceleration/deceleration [on/off]
franzachatz 2:ad11f550b379 66 * to a Stepper Motor Controller
franzachatz 0:27b548e34acc 67 *
franzachatz 0:27b548e34acc 68 * @param n_steps number of steps to go
franzachatz 0:27b548e34acc 69 * @param direction 1 or 0
franzachatz 0:27b548e34acc 70 * @param time value for value in us
franzachatz 2:ad11f550b379 71 * @param accel 1 or 0 for accel/decel [on/off]
franzachatz 0:27b548e34acc 72 */
franzachatz 0:27b548e34acc 73 void step(int n_steps, bool direction, int speed, bool accel);
franzachatz 0:27b548e34acc 74
franzachatz 0:27b548e34acc 75 /** get version number
franzachatz 0:27b548e34acc 76 *
franzachatz 0:27b548e34acc 77 * @param returns Library version number
franzachatz 0:27b548e34acc 78 */
franzachatz 0:27b548e34acc 79 float version(void);
franzachatz 0:27b548e34acc 80
franzachatz 0:27b548e34acc 81 private:
franzachatz 0:27b548e34acc 82 DigitalOut _clk;
franzachatz 0:27b548e34acc 83 DigitalOut _dir;
franzachatz 0:27b548e34acc 84
franzachatz 0:27b548e34acc 85 };
franzachatz 0:27b548e34acc 86
franzachatz 0:27b548e34acc 87 #endif