Hiroshi M / UniStepperMotor
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UniStepperMotor.h Source File

UniStepperMotor.h

00001 /**
00002  *****************************************************************************
00003  * File Name    : UniStepperMotor.h
00004  *
00005  * Title        : Unipolar Stepper Motor Class Header File
00006  * Revision     : 0.1
00007  * Notes        :
00008  * Target Board : mbed NXP LPC1768
00009  * Tool Chain   : ????
00010  *
00011  * Revision History:
00012  * When         Who         Description of change
00013  * -----------  ----------- -----------------------
00014  * 2012/07/8    Hiroshi M   init
00015  *****************************************************************************
00016  *
00017  * Copyright (C) 2012 Hiroshi M, MIT License
00018  *
00019  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00020  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00021  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00022  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00023  * furnished to do so, subject to the following conditions:
00024  *
00025  * The above copyright notice and this permission notice shall be included in all copies or
00026  * substantial portions of the Software.
00027  *
00028  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00029  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00030  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00031  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00032  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  **/
00035 
00036 #ifndef MBED_STEPPER_MOTOR_H
00037 #define MBED_STEPPER_MOTOR_H
00038  
00039 /* Includes ----------------------------------------------------------------- */
00040 #include "mbed.h"
00041                                                                                                                                     
00042 /* typedef ------------------------------------------------------------------ */
00043 typedef enum {PWM_ON, PWM_OFF} pwm_state;
00044 typedef enum {CLOCK_WISE, ANTI_CLOCK_WISE} motor_dir;
00045 
00046 struct speed_data_t {
00047     int max_pulse_count;
00048     int pwm_ratio;
00049     uint8_t *clockwise_ptn;
00050     uint8_t *anticlockwise_ptn;
00051     int ptn_count;
00052 };
00053 
00054 /* define ------------------------------------------------------------------- */
00055 #define PULSE_INTERVAL  14        // 14us
00056 #define MAXSPEED        255
00057 
00058 /* macro -------------------------------------------------------------------- */
00059 /* variables ---------------------------------------------------------------- */
00060 /* class -------------------------------------------------------------------- */
00061 
00062 class StepperMotor {
00063 public:
00064     StepperMotor(PinName x_pin_no, PinName y_pin_no, PinName nx_pin_no, PinName ny_pin_no, motor_dir set_direction);
00065     ~StepperMotor();
00066 
00067     void SetSpeed(int speed);
00068     void PulseEnable(void);
00069     void PulseDisable(void);
00070 
00071 private:
00072     pwm_state   state;
00073     motor_dir   direction;
00074     motor_dir   forward_direction;
00075     motor_dir   backward_direction;
00076 
00077     int         ptn_index;
00078     int         ptn_count;
00079     int         pwm_ratio;
00080     int         pwm_on_count;
00081     int         pwm_off_count;
00082     int         max_pulse_count;
00083     int         pulse_count;
00084     uint8_t     *ptn;
00085     uint8_t     ptn_data;
00086 
00087     DigitalOut _x;
00088     DigitalOut _y;
00089     DigitalOut _nx;
00090     DigitalOut _ny;
00091 
00092     Ticker Pulse;
00093 
00094     void SetPulse14us(void);
00095     void PulseOut(void);
00096     void PulseStop(void);
00097 };
00098 
00099 #endif