Li Weiyi
/
BalanceCar
虽然移植完毕,但是不work。需要细调……
Embed:
(wiki syntax)
Show/hide line numbers
Microduino_Stepper_PWM.h
00001 // Microduino_Stepper.cpp 00002 // 00003 // Copyright (C) 2009-2013 Shenyang 00004 // $Id: Microduino_Stepper.cpp,v 1.00 2016/04/07 $ 00005 00006 #ifndef __MICRODUINO_STEPPER_H__ 00007 #define __MICRODUINO_STEPPER_H__ 00008 00009 //#include "MicroduinoPinNames.h" 00010 #include "mbed.h" 00011 #include <stdlib.h> 00012 //#include <Arduino.h> 00013 00014 //#define _useTimer1 00015 #define MAX_SPEED_S 4096 00016 #define TIMER_COMP 327680/MAX_SPEED_S 00017 00018 00019 //#define PIN_SET(pin) (*portOutputRegister(digitalPinToPort(pin)) |= digitalPinToBitMask(pin)) 00020 //#define PIN_CLR(pin) (*portOutputRegister(digitalPinToPort(pin)) &= ~digitalPinToBitMask(pin)) 00021 00022 #define MAX_STEPPERS 4 00023 #define INVALID_STEPPER 255 00024 00025 #if 0 00026 #define PIN_EN 4 //PORTB,0 00027 #define PIN_DIRA A0 //PORTA,7 00028 #define PIN_STEPA 5 //PORTB,1 00029 #define PIN_DIRB A1 //PORTA,6 00030 #define PIN_STEPB 6 //PORTB,2 00031 #define PIN_DIRC A2 //PORTA,5 00032 #define PIN_STEPC 7 //PORTB,3 00033 #define PIN_DIRD A3 //PORTA,4 00034 #define PIN_STEPD 8 //PORTD,6 00035 #elif 0 00036 #define PIN_EN D4 00037 #define PIN_DIRA A0 00038 #define PIN_STEPA D5 00039 #define PIN_DIRB A1 00040 #define PIN_STEPB D6 00041 #define PIN_DIRC A2 00042 #define PIN_STEPC D7 00043 #define PIN_DIRD A3 00044 #define PIN_STEPD D8 00045 #else 00046 #define PIN_EN P0_25 00047 #define PIN_DIRA P0_7 00048 #define PIN_STEPA P0_24 00049 #define PIN_DIRB P0_6 00050 #define PIN_STEPB P0_1 00051 #define PIN_DIRC P0_14 00052 #define PIN_STEPC P0_20 00053 #define PIN_DIRD P0_23 00054 #define PIN_STEPD P0_19 00055 #endif 00056 00057 #define DEFAULT_ACCEL 120 00058 00059 /* PWM的周期越小,频率越大,测试时发现这款步进电机的最大频率是2500Hz,也就是说周期为400us 00060 * 频率频率越大,步进电机的速度越大,至于脉冲的宽度,1us即可 00061 */ 00062 #define PERIOD_MAX 2000 00063 #define PERIOD_MIN 450 00064 00065 void stepperAllEnable(); 00066 void stepperAllDisable(); 00067 00068 class Stepper 00069 { 00070 public: 00071 00072 Stepper(PinName dirPin, PinName stepPin); 00073 00074 uint8_t begin(); 00075 00076 void setSpeed(int16_t _speed); 00077 00078 void setMaxAccel(uint16_t _accel); 00079 00080 int16_t getSpeed(); 00081 00082 uint16_t getMaxAccel(); 00083 00084 void computeStep(); 00085 00086 private: 00087 pwmout_t pwmStep; 00088 gpio_t dirOUT; 00089 //gpio_t stepOUT; 00090 uint8_t stepperIndex; 00091 //uint8_t dirPin; 00092 //uint8_t stepPin; 00093 int16_t speed; 00094 uint16_t maxAccel; 00095 uint16_t period; 00096 //uint16_t counter; 00097 00098 }; 00099 00100 typedef struct { 00101 //uint8_t isActive = false; 00102 uint8_t isActive; 00103 Stepper *stepper; 00104 } Stepper_t; 00105 00106 #endif // __MICRODUINO_STEPPER_H__
Generated on Wed Jul 13 2022 03:34:51 by 1.7.2