Dual DC Motor Drive using PWM for RenBuggy; there are two inputs to feed a hall sensor for distance / speed feedback.
Diff: DCMotorDrive.h
- Revision:
- 1:0c8cb3439288
- Parent:
- 0:34800070e9dc
- Child:
- 2:5239659649d1
- Child:
- 3:50495c3c3c37
--- a/DCMotorDrive.h Tue Jan 14 10:45:19 2014 +0000 +++ b/DCMotorDrive.h Wed Jan 15 11:48:01 2014 +0000 @@ -30,33 +30,31 @@ #include "mbed.h" -#define WHEEL_CIRCUMFERENCE 114.4 -#define COUNTS_PER_ROTATION 64 -#define PWM_SPEED_ADJUST 20 -#define ROTATION_LIMIT 20 #define PWM_PERIOD 20 -#define PWM_PERIOD_US PWM_PERIOD * 1000 +#define BUFFER_SIZE 16 #define MOTOR_STALL_TIME 2 -#define CAL_SPEED 80 // CalSpeed is 80 mm/s -#define TWO_SECONDS 2000000 -#define US_IN_SECONDS 1000000 class DCMotorDrive { public: DCMotorDrive(PinName MotorOut, PinName SensorIn); - void SetMotorPwm(int PwmValue); + void SetMotorPwmAndRevolutions(int PwmValue, int MaxRevolutions); int GetAveragePulseTime(void); + int GetLastPulseTime(void); void ResetOdometer(void); int ReadOdometer(void); + int ReadCaptureTime(void); void ClearBuffer(void); private: Ticker timeout; Timer PulseClock; - volatile int ClockBuffer[16]; + volatile int ClockBuffer[BUFFER_SIZE]; volatile int ClockPointer; + volatile int CaptureTime; + volatile int LastPulseTime; volatile int RotationCounter; + volatile int RevolutionLimit; PwmOut _MotorPin; InterruptIn _SensorIn;