libreria para manejo de easy driver
Fork of stepper by
stepper.cpp@3:9c7a33b8a771, 2015-05-07 (annotated)
- Committer:
- oscarvzfz
- Date:
- Thu May 07 23:02:53 2015 +0000
- Revision:
- 3:9c7a33b8a771
- Parent:
- 2:ad11f550b379
...
Who changed what in which revision?
User | Revision | Line number | New 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 | #include "stepper.h" |
franzachatz | 0:27b548e34acc | 23 | #include "mbed.h" |
franzachatz | 0:27b548e34acc | 24 | |
franzachatz | 0:27b548e34acc | 25 | // define the Stepper Motor save start/stop speed |
franzachatz | 0:27b548e34acc | 26 | #define START_STOP_SPEED 300 |
franzachatz | 0:27b548e34acc | 27 | |
franzachatz | 0:27b548e34acc | 28 | // define Library version number |
franzachatz | 2:ad11f550b379 | 29 | #define VERSION 0.3 |
franzachatz | 0:27b548e34acc | 30 | |
oscarvzfz | 3:9c7a33b8a771 | 31 | |
franzachatz | 0:27b548e34acc | 32 | |
franzachatz | 0:27b548e34acc | 33 | stepper::stepper(PinName clk, PinName dir) : _clk(clk), _dir(dir) { |
franzachatz | 0:27b548e34acc | 34 | _clk = 0, _dir = 0; |
franzachatz | 0:27b548e34acc | 35 | } |
franzachatz | 0:27b548e34acc | 36 | |
franzachatz | 0:27b548e34acc | 37 | void stepper::step(int n_steps, bool direction, int speed, bool accel) { |
franzachatz | 0:27b548e34acc | 38 | int accelspeed; |
franzachatz | 0:27b548e34acc | 39 | if(accel) accelspeed = START_STOP_SPEED; |
franzachatz | 0:27b548e34acc | 40 | else accelspeed = speed; |
franzachatz | 0:27b548e34acc | 41 | for(int i=0; i<n_steps; i++) |
franzachatz | 0:27b548e34acc | 42 | { |
franzachatz | 0:27b548e34acc | 43 | if(accel)//linear acceleration |
franzachatz | 0:27b548e34acc | 44 | { |
franzachatz | 0:27b548e34acc | 45 | if(i < START_STOP_SPEED) if (--accelspeed == speed) accelspeed ++; |
franzachatz | 0:27b548e34acc | 46 | if(i > (n_steps-START_STOP_SPEED)) if(++accelspeed == START_STOP_SPEED) accelspeed--; |
franzachatz | 0:27b548e34acc | 47 | } |
oscarvzfz | 3:9c7a33b8a771 | 48 | _dir = direction; |
franzachatz | 0:27b548e34acc | 49 | _clk = 1; |
franzachatz | 0:27b548e34acc | 50 | wait_us(1); |
franzachatz | 0:27b548e34acc | 51 | _clk = 0; |
franzachatz | 0:27b548e34acc | 52 | wait_us(1); |
franzachatz | 0:27b548e34acc | 53 | wait_us(accelspeed); |
franzachatz | 0:27b548e34acc | 54 | } |
franzachatz | 0:27b548e34acc | 55 | } |
franzachatz | 0:27b548e34acc | 56 | |
franzachatz | 0:27b548e34acc | 57 | // version() returns the version number of the library |
franzachatz | 0:27b548e34acc | 58 | float stepper::version(void) { |
franzachatz | 0:27b548e34acc | 59 | return VERSION; |
franzachatz | 0:27b548e34acc | 60 | } |