LV8548 Motor Driver Stepper Motor Dc MOtor

Dependents:   LV8548_ON_MD_Modlle_kit_DCMtr_And_STEPMtr

Committer:
yamasho
Date:
Mon Nov 19 01:52:22 2018 +0000
Revision:
2:627825272d30
Parent:
1:e60c7c42e6fc
bug Fix;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamasho 0:04db82da014d 1 /**
yamasho 0:04db82da014d 2 [LV8548.h]
yamasho 0:04db82da014d 3 Copyright (c) [2018] [YAMASHO]
yamasho 0:04db82da014d 4 This software is released under the MIT License.
yamasho 0:04db82da014d 5 http://opensource.org/licenses/mit-license.php
yamasho 0:04db82da014d 6 */
yamasho 0:04db82da014d 7
yamasho 0:04db82da014d 8 #ifndef MBED_LV8548_H
yamasho 0:04db82da014d 9 #define MBED_LV8548_H
yamasho 0:04db82da014d 10
yamasho 0:04db82da014d 11 #include "mbed.h"
yamasho 0:04db82da014d 12
yamasho 0:04db82da014d 13 #define MAXCH (2)
yamasho 0:04db82da014d 14
yamasho 0:04db82da014d 15 #define STEPMAX_FREQ (4800)
yamasho 2:627825272d30 16 #define USE_PWM_PORT (1) // if use stepper then (0)
yamasho 0:04db82da014d 17
yamasho 0:04db82da014d 18 /** Motor Use */
yamasho 0:04db82da014d 19 enum DriverType {
yamasho 0:04db82da014d 20 DCMOTOR /** DC Motor x2 */
yamasho 0:04db82da014d 21 , STEPERMOTOR /** STEPER x1 */
yamasho 0:04db82da014d 22 };
yamasho 0:04db82da014d 23
yamasho 0:04db82da014d 24 enum DriverPwmMode {
yamasho 0:04db82da014d 25 FWD_OPEN, /** FWD_OPEN */
yamasho 0:04db82da014d 26 FWD_BRAKE, /** FWD_BREAKE */
yamasho 0:04db82da014d 27 RVS_OPEN, /** REVERS OPEN */
yamasho 0:04db82da014d 28 RVS_BRAKE /** REVSRS BRAKE */
yamasho 0:04db82da014d 29 };
yamasho 0:04db82da014d 30
yamasho 0:04db82da014d 31 enum DriverPwmOut {
yamasho 0:04db82da014d 32 OUTPUT_OFF, /* OFF */
yamasho 0:04db82da014d 33 OUTPUT_START, /* START */
yamasho 0:04db82da014d 34 OUTPUT_BRAKE /* BRAAKE */
yamasho 0:04db82da014d 35 };
yamasho 0:04db82da014d 36
yamasho 0:04db82da014d 37 /** Motor Number */
yamasho 0:04db82da014d 38 enum DriverMotorNumber {
yamasho 0:04db82da014d 39 MOTOR_A = 0
yamasho 0:04db82da014d 40 , MOTOR_B = 1
yamasho 0:04db82da014d 41 , MOTOR_MAX
yamasho 0:04db82da014d 42 };
yamasho 0:04db82da014d 43
yamasho 0:04db82da014d 44
yamasho 0:04db82da014d 45 /** Motor Dirction */
yamasho 0:04db82da014d 46 enum DriverMotorDirction {
yamasho 0:04db82da014d 47 DIR_CW = 0
yamasho 0:04db82da014d 48 , DIR_CCW = 1
yamasho 0:04db82da014d 49 , DIR_MAX
yamasho 0:04db82da014d 50 };
yamasho 0:04db82da014d 51
yamasho 0:04db82da014d 52 /** Motor Step Mode */
yamasho 0:04db82da014d 53 enum DriverStepMode {
yamasho 0:04db82da014d 54 FULLSTEP = 0
yamasho 0:04db82da014d 55 , HALFSTEP = 1
yamasho 0:04db82da014d 56 , MOTORSTEP_MAX
yamasho 0:04db82da014d 57 };
yamasho 0:04db82da014d 58
yamasho 0:04db82da014d 59 /** Motor Step Mode */
yamasho 0:04db82da014d 60 enum DriverPhaseStep {
yamasho 0:04db82da014d 61 STEPPHASE0 = 0,
yamasho 0:04db82da014d 62 STEPPHASE1 = 1,
yamasho 0:04db82da014d 63 STEPPHASE2 = 2,
yamasho 0:04db82da014d 64 STEPPHASE3 = 3,
yamasho 0:04db82da014d 65 STEPPHASE4 = 4,
yamasho 0:04db82da014d 66 STEPPHASE5 = 5,
yamasho 0:04db82da014d 67 STEPPHASE6 = 6,
yamasho 0:04db82da014d 68 STEPPHASE7 = 7,
yamasho 0:04db82da014d 69 STEPPHASEMAX = 8 /* 必ず8 */
yamasho 0:04db82da014d 70 };
yamasho 0:04db82da014d 71
yamasho 0:04db82da014d 72 class LV8548 {
yamasho 0:04db82da014d 73 public:
yamasho 0:04db82da014d 74 LV8548(PinName in1, PinName in2, PinName in3, PinName in4, DriverType drivertype = DCMOTOR ,uint16_t baseus = 64);
yamasho 1:e60c7c42e6fc 75 #if USE_PWM_PORT
yamasho 0:04db82da014d 76 PwmOut _in1,_in2,_in3,_in4;
yamasho 1:e60c7c42e6fc 77 #else
yamasho 1:e60c7c42e6fc 78 DigitalOut _in1,_in2,_in3,_in4;
yamasho 1:e60c7c42e6fc 79 #endif
yamasho 0:04db82da014d 80 DriverType _Drivertype;
yamasho 0:04db82da014d 81 uint16_t _baseus;
yamasho 0:04db82da014d 82 /***************************************************************************************************/
yamasho 0:04db82da014d 83 DriverPwmMode _Pwmmode[MOTOR_MAX]; // pwmのモード FWD.OPEN FWD.BRAKE RVS.OPEN REV.BRAKE
yamasho 0:04db82da014d 84 DriverPwmOut _Pwmout [MOTOR_MAX]; // Start Stop Breke
yamasho 0:04db82da014d 85 float _PwmPeriod [MOTOR_MAX]; // ポートのPwm周波数
yamasho 0:04db82da014d 86 float _PwmDuty [MOTOR_MAX]; // 各Motor のduty 1.0f-0.0fまで
yamasho 0:04db82da014d 87 // uint8_t _testx;
yamasho 0:04db82da014d 88
yamasho 0:04db82da014d 89 Ticker _Lv8548BaseTimer;
yamasho 0:04db82da014d 90
yamasho 0:04db82da014d 91 void SetDcPwmFreqency( uint8_t ch ,float Freq );
yamasho 0:04db82da014d 92 void SetDcPwmMode( uint8_t ch ,DriverPwmMode Mode );
yamasho 0:04db82da014d 93 void SetDcPwmDuty( uint8_t ch ,float Duty ); // 01まで
yamasho 0:04db82da014d 94 void SetDcOutPut ( uint8_t ch ,DriverPwmOut Mode );
yamasho 0:04db82da014d 95 void SetDcMotor ( uint8_t ch );
yamasho 0:04db82da014d 96 void SetDcMotorStop( uint8_t ch );
yamasho 0:04db82da014d 97 /*******************************************************************************************************************/
yamasho 0:04db82da014d 98 float _StepAngle;
yamasho 0:04db82da014d 99 float _StepDeg; // 角度 0-360度
yamasho 0:04db82da014d 100 float _StepFreq; // 周波数
yamasho 0:04db82da014d 101 float _TimerCounter;
yamasho 0:04db82da014d 102 volatile uint8_t _StepPhase; // Step Motorのphase
yamasho 0:04db82da014d 103 volatile uint32_t _IntTimerCount;
yamasho 0:04db82da014d 104 // volatile uint32_t _PhaseCounter;
yamasho 0:04db82da014d 105 volatile uint32_t _StepTimeCount;
yamasho 0:04db82da014d 106 volatile bool _StepOperation; // 割込内の動作状況
yamasho 0:04db82da014d 107 volatile DriverStepMode _TargetStepMode; // 目標のStep状態 Full(0)/Half(1)
yamasho 0:04db82da014d 108 volatile DriverStepMode _NowStepMode; // 動作中のStep状態 Full(0)/Half(1)
yamasho 0:04db82da014d 109 volatile DriverMotorDirction _TragetStepDirection; // 目標のDirection Cw/Ccw
yamasho 0:04db82da014d 110 volatile DriverMotorDirction _NowStepDirection; // 動作中のDirection cw/CCW
yamasho 0:04db82da014d 111 volatile uint32_t _NowStep; // 現状のStep
yamasho 0:04db82da014d 112 volatile uint32_t _TargetStep; // ターゲットのStep
yamasho 0:04db82da014d 113 void SetStepAngle( uint16_t Angle); // 角度の設定
yamasho 0:04db82da014d 114 void SetStepDeg ( uint16_t frequency , uint16_t deg , uint8_t Direction, uint8_t StepMode);
yamasho 0:04db82da014d 115 void SetStepTime ( uint16_t frequency , uint16_t time , uint8_t Direction, uint8_t StepMode);
yamasho 0:04db82da014d 116 void SetStepStep ( uint16_t frequency , uint16_t step , uint8_t Direction, uint8_t StepMode);
yamasho 0:04db82da014d 117 void SetStepStop ( void );
yamasho 0:04db82da014d 118 void SetStepFree ( void );
yamasho 0:04db82da014d 119 void SetStepMotor( void );
yamasho 0:04db82da014d 120 void SetStepTimerInt ( void );
yamasho 0:04db82da014d 121 };
yamasho 0:04db82da014d 122
yamasho 0:04db82da014d 123
yamasho 0:04db82da014d 124 #endif