MTRCTL - Sets initial frequency of DC motors. - Controls motor speed according to IC specifications. - Handles motors in order to help the car during curved paths.
Dependents: frdm_MasterVehicle
mtrctl.h@0:4fc76af15d0e, 2014-10-14 (annotated)
- Committer:
- JalilChavez
- Date:
- Tue Oct 14 03:55:04 2014 +0000
- Revision:
- 0:4fc76af15d0e
controller of DC motors, this module modifies the duty cycle provided to each motor and also handles the difference of speed necessary to help the car during curved paths.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JalilChavez | 0:4fc76af15d0e | 1 | #ifndef _MTRCTL_H_ |
JalilChavez | 0:4fc76af15d0e | 2 | #define _MTRCTL_H_ |
JalilChavez | 0:4fc76af15d0e | 3 | |
JalilChavez | 0:4fc76af15d0e | 4 | #include "mbed.h" |
JalilChavez | 0:4fc76af15d0e | 5 | |
JalilChavez | 0:4fc76af15d0e | 6 | /********************************************************************************** |
JalilChavez | 0:4fc76af15d0e | 7 | * Servo parameters |
JalilChavez | 0:4fc76af15d0e | 8 | ***********************************************************************************/ |
JalilChavez | 0:4fc76af15d0e | 9 | #define OP_PERIOD 90900/* us |
JalilChavez | 0:4fc76af15d0e | 10 | * Description: operation period to control propulsion motors |
JalilChavez | 0:4fc76af15d0e | 11 | */ |
JalilChavez | 0:4fc76af15d0e | 12 | |
JalilChavez | 0:4fc76af15d0e | 13 | #define MAX_POWER 1000/* |
JalilChavez | 0:4fc76af15d0e | 14 | * Description: logical, max value allowed for a PWM channel |
JalilChavez | 0:4fc76af15d0e | 15 | */ |
JalilChavez | 0:4fc76af15d0e | 16 | |
JalilChavez | 0:4fc76af15d0e | 17 | #define MIN_POWER 100/* |
JalilChavez | 0:4fc76af15d0e | 18 | * Description: logical, min value allowed for a PWM channel |
JalilChavez | 0:4fc76af15d0e | 19 | */ |
JalilChavez | 0:4fc76af15d0e | 20 | |
JalilChavez | 0:4fc76af15d0e | 21 | #define MAX_DIRECTION_VAL 128/* |
JalilChavez | 0:4fc76af15d0e | 22 | * Description: Maximum direction value, it means totally right, 0 means totally left |
JalilChavez | 0:4fc76af15d0e | 23 | */ |
JalilChavez | 0:4fc76af15d0e | 24 | |
JalilChavez | 0:4fc76af15d0e | 25 | #define SCALE_DIR2SPEED (uint16_t)(MAX_POWER/MAX_DIRECTION_VAL) |
JalilChavez | 0:4fc76af15d0e | 26 | |
JalilChavez | 0:4fc76af15d0e | 27 | /********************************************************************************** |
JalilChavez | 0:4fc76af15d0e | 28 | * Variable types definition |
JalilChavez | 0:4fc76af15d0e | 29 | ***********************************************************************************/ |
JalilChavez | 0:4fc76af15d0e | 30 | typedef enum |
JalilChavez | 0:4fc76af15d0e | 31 | { |
JalilChavez | 0:4fc76af15d0e | 32 | nLeftMotor = 0, |
JalilChavez | 0:4fc76af15d0e | 33 | nRightMotor, |
JalilChavez | 0:4fc76af15d0e | 34 | nNoOfMotors |
JalilChavez | 0:4fc76af15d0e | 35 | }MTRCTL_tenMotors; |
JalilChavez | 0:4fc76af15d0e | 36 | /********************************************************************************** |
JalilChavez | 0:4fc76af15d0e | 37 | * Global functions |
JalilChavez | 0:4fc76af15d0e | 38 | ***********************************************************************************/ |
JalilChavez | 0:4fc76af15d0e | 39 | void MTRCTL_vInit( void ); |
JalilChavez | 0:4fc76af15d0e | 40 | void MTRCTL_vSetMaxSpeed( uint16_t u16MaxSpeed ); |
JalilChavez | 0:4fc76af15d0e | 41 | void MTRCTL_vSetMotorPower( uint16_t u16InPwr, MTRCTL_tenMotors enMotor ); |
JalilChavez | 0:4fc76af15d0e | 42 | void MTRCTL_vSetSystemSpeed( uint16_t u16Speed, uint8_t u8Direction ); |
JalilChavez | 0:4fc76af15d0e | 43 | |
JalilChavez | 0:4fc76af15d0e | 44 | #endif |