Library for handle a Stepper Motor Driver Borad

Committer:
dury
Date:
Tue Nov 20 16:46:43 2012 +0000
Revision:
0:ce88091ae9fb
Child:
1:b96435078d4d
First Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dury 0:ce88091ae9fb 1 /* mbed Stepper Library
dury 0:ce88091ae9fb 2 * Copyright (c) 2012 Fabio Durigon
dury 0:ce88091ae9fb 3 *
dury 0:ce88091ae9fb 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
dury 0:ce88091ae9fb 5 * of this software and associated documentation files (the "Software"), to deal
dury 0:ce88091ae9fb 6 * in the Software without restriction, including without limitation the rights
dury 0:ce88091ae9fb 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
dury 0:ce88091ae9fb 8 * copies of the Software, and to permit persons to whom the Software is
dury 0:ce88091ae9fb 9 * furnished to do so, subject to the following conditions:
dury 0:ce88091ae9fb 10 *
dury 0:ce88091ae9fb 11 * The above copyright notice and this permission notice shall be included in
dury 0:ce88091ae9fb 12 * all copies or substantial portions of the Software.
dury 0:ce88091ae9fb 13 *
dury 0:ce88091ae9fb 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dury 0:ce88091ae9fb 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dury 0:ce88091ae9fb 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dury 0:ce88091ae9fb 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dury 0:ce88091ae9fb 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dury 0:ce88091ae9fb 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dury 0:ce88091ae9fb 20 * THE SOFTWARE.
dury 0:ce88091ae9fb 21 */
dury 0:ce88091ae9fb 22
dury 0:ce88091ae9fb 23 #ifndef STEPPERMOTOR_H
dury 0:ce88091ae9fb 24 #define STEPPERMOTOR_H
dury 0:ce88091ae9fb 25
dury 0:ce88091ae9fb 26 #include "mbed.h"
dury 0:ce88091ae9fb 27
dury 0:ce88091ae9fb 28 //!Library for handle Stepper Motor with a Power Module with Clock and Dir input
dury 0:ce88091ae9fb 29
dury 0:ce88091ae9fb 30 // Rotation direction
dury 0:ce88091ae9fb 31 #define CW 1
dury 0:ce88091ae9fb 32 #define CC 0
dury 0:ce88091ae9fb 33
dury 0:ce88091ae9fb 34 class StepperMotorDrv
dury 0:ce88091ae9fb 35 {
dury 0:ce88091ae9fb 36 public:
dury 0:ce88091ae9fb 37 /** Create a StepperMotorDrv Object
dury 0:ce88091ae9fb 38 *
dury 0:ce88091ae9fb 39 * @param PinDir Digital Output Pin to set Direction of motor
dury 0:ce88091ae9fb 40 * @param PinClk Pwm Output Pin for Clock signal
dury 0:ce88091ae9fb 41 */
dury 0:ce88091ae9fb 42 StepperMotorDrv(PinName PinDir, PinName PinClk);
dury 0:ce88091ae9fb 43
dury 0:ce88091ae9fb 44 /** Destroys an instance of SRD02
dury 0:ce88091ae9fb 45 */
dury 0:ce88091ae9fb 46 ~StepperMotorDrv();
dury 0:ce88091ae9fb 47
dury 0:ce88091ae9fb 48 /** Set duty cicle of clock pulse
dury 0:ce88091ae9fb 49 *
dury 0:ce88091ae9fb 50 * @param PercentualValue: Value 0-100%
dury 0:ce88091ae9fb 51 */
dury 0:ce88091ae9fb 52 float SetDutyCyclePerc(float PercentualValue);
dury 0:ce88091ae9fb 53 float SetDutyCycleValue(float DecimalValue);
dury 0:ce88091ae9fb 54 float SetRawSpeedHz(float SpeedHz);
dury 0:ce88091ae9fb 55 void SetMaxSpeedHz(float MaxSpeedHz);
dury 0:ce88091ae9fb 56 float SetSpeedPerc(float PercValue);
dury 0:ce88091ae9fb 57 float IncSpeedHz(float StepValueHz);
dury 0:ce88091ae9fb 58 float SpeedUp(void);
dury 0:ce88091ae9fb 59 float DecSpeedHz(float StepValueHz);
dury 0:ce88091ae9fb 60 float SpeedDown(void);
dury 0:ce88091ae9fb 61 void Stop(void);
dury 0:ce88091ae9fb 62 float GetSpeedHz(void);
dury 0:ce88091ae9fb 63 float GetSpeedPerc(void);
dury 0:ce88091ae9fb 64 float GetMaxSpeed(void);
dury 0:ce88091ae9fb 65 float GetDuryCyclePerc(void);
dury 0:ce88091ae9fb 66 float GetDuryCycleValue(void);
dury 0:ce88091ae9fb 67 float GetStepHz(void);
dury 0:ce88091ae9fb 68 void SetDir(bool RotationDir);
dury 0:ce88091ae9fb 69 void SetDirCW(void);
dury 0:ce88091ae9fb 70 void SetDirCC(void);
dury 0:ce88091ae9fb 71 void RevertDir(void);
dury 0:ce88091ae9fb 72 bool GetDir(void);
dury 0:ce88091ae9fb 73
dury 0:ce88091ae9fb 74 private:
dury 0:ce88091ae9fb 75 DigitalOut Dir;
dury 0:ce88091ae9fb 76 PwmOut Clock;
dury 0:ce88091ae9fb 77
dury 0:ce88091ae9fb 78 float MaxSpeed;
dury 0:ce88091ae9fb 79 float Speed;
dury 0:ce88091ae9fb 80 float Step;
dury 0:ce88091ae9fb 81 float DutyCycle;
dury 0:ce88091ae9fb 82 bool Direction;
dury 0:ce88091ae9fb 83
dury 0:ce88091ae9fb 84 };
dury 0:ce88091ae9fb 85 #endif