Library for handle a Stepper Motor Driver Borad

StepperMotor.h

Committer:
dury
Date:
2012-11-20
Revision:
0:ce88091ae9fb
Child:
1:b96435078d4d

File content as of revision 0:ce88091ae9fb:

/* mbed Stepper Library
 * Copyright (c) 2012 Fabio Durigon
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
 
#ifndef STEPPERMOTOR_H
#define STEPPERMOTOR_H

#include "mbed.h"

//!Library for handle Stepper Motor with a Power Module with Clock and Dir input

// Rotation direction
#define CW 1
#define CC 0

class StepperMotorDrv
{
    public:
        /** Create a StepperMotorDrv Object
        *
        * @param PinDir Digital Output Pin to set Direction of motor
        * @param PinClk Pwm Output Pin for Clock signal
        */
        StepperMotorDrv(PinName PinDir, PinName PinClk);
        
        /** Destroys an instance of SRD02
        */
        ~StepperMotorDrv();
        
        /** Set duty cicle of clock pulse
        *
        * @param PercentualValue: Value 0-100%
        */
        float SetDutyCyclePerc(float PercentualValue);
        float SetDutyCycleValue(float DecimalValue);
        float SetRawSpeedHz(float SpeedHz);
        void SetMaxSpeedHz(float MaxSpeedHz);
        float SetSpeedPerc(float PercValue);
        float IncSpeedHz(float StepValueHz);
        float SpeedUp(void);
        float DecSpeedHz(float StepValueHz);
        float SpeedDown(void);
        void Stop(void);
        float GetSpeedHz(void);
        float GetSpeedPerc(void);
        float GetMaxSpeed(void);
        float GetDuryCyclePerc(void);
        float GetDuryCycleValue(void);
        float GetStepHz(void);
        void SetDir(bool RotationDir);
        void SetDirCW(void);
        void SetDirCC(void);
        void RevertDir(void);
        bool GetDir(void);
            
    private:
        DigitalOut Dir;     
        PwmOut Clock;
        
        float MaxSpeed;
        float Speed;
        float Step;
        float DutyCycle;
        bool Direction;
        
};
#endif