Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PeripheralLayer/MotHatLib.h@0:633cef71e6ba, 2015-08-09 (annotated)
- Committer:
- nightseas
- Date:
- Sun Aug 09 09:37:55 2015 +0000
- Revision:
- 0:633cef71e6ba
- Child:
- 1:a6bcf44b90df
Basic DC motor and servo control lib finished!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nightseas | 0:633cef71e6ba | 1 | #ifndef _PE_BD_LIB_ |
nightseas | 0:633cef71e6ba | 2 | #define _PE_BD_LIB_ |
nightseas | 0:633cef71e6ba | 3 | |
nightseas | 0:633cef71e6ba | 4 | //Number of on-board devices |
nightseas | 0:633cef71e6ba | 5 | extern const int LED_NUM_MAX; |
nightseas | 0:633cef71e6ba | 6 | extern const int MOT_NUM_MAX; |
nightseas | 0:633cef71e6ba | 7 | extern const int SRV_NUM_MAX; |
nightseas | 0:633cef71e6ba | 8 | extern const int VMON_NUM_MAX; |
nightseas | 0:633cef71e6ba | 9 | //The speed difference rate of left/right side motors when the vehicle turns head |
nightseas | 0:633cef71e6ba | 10 | extern const int MOT_TURN_RATE; |
nightseas | 0:633cef71e6ba | 11 | //Fixed PWM period of servos |
nightseas | 0:633cef71e6ba | 12 | extern const int SRV_PERIOD_US; |
nightseas | 0:633cef71e6ba | 13 | |
nightseas | 0:633cef71e6ba | 14 | //LEDs on mother board and daughter board |
nightseas | 0:633cef71e6ba | 15 | extern DigitalOut led_mb; |
nightseas | 0:633cef71e6ba | 16 | |
nightseas | 0:633cef71e6ba | 17 | //GPIO for L293DD motor direction control |
nightseas | 0:633cef71e6ba | 18 | //Forward = 2b'01, Backward = 2b'10, Stop = 2b'00 |
nightseas | 0:633cef71e6ba | 19 | extern BusOut mot1_dir, mot2_dir, mot3_dir, mot4_dir; |
nightseas | 0:633cef71e6ba | 20 | |
nightseas | 0:633cef71e6ba | 21 | //Analog inputs for power voltage monitoring |
nightseas | 0:633cef71e6ba | 22 | extern AnalogIn vin_bat; |
nightseas | 0:633cef71e6ba | 23 | extern AnalogIn vin_12v; |
nightseas | 0:633cef71e6ba | 24 | extern AnalogIn vin_5v; |
nightseas | 0:633cef71e6ba | 25 | extern AnalogIn vin_3v; |
nightseas | 0:633cef71e6ba | 26 | |
nightseas | 0:633cef71e6ba | 27 | //TIM3 PWM channels |
nightseas | 0:633cef71e6ba | 28 | extern PwmOut mot1_pwm; |
nightseas | 0:633cef71e6ba | 29 | extern PwmOut mot2_pwm; |
nightseas | 0:633cef71e6ba | 30 | extern PwmOut mot3_pwm; |
nightseas | 0:633cef71e6ba | 31 | extern PwmOut mot4_pwm; |
nightseas | 0:633cef71e6ba | 32 | |
nightseas | 0:633cef71e6ba | 33 | //TIM15 PWM channels |
nightseas | 0:633cef71e6ba | 34 | extern PwmOut servo1_pwm; |
nightseas | 0:633cef71e6ba | 35 | extern PwmOut servo2_pwm; |
nightseas | 0:633cef71e6ba | 36 | //TIM16 PWM channels |
nightseas | 0:633cef71e6ba | 37 | extern PwmOut servo3_pwm; |
nightseas | 0:633cef71e6ba | 38 | //TIM17 PWM channels |
nightseas | 0:633cef71e6ba | 39 | extern PwmOut servo4_pwm; |
nightseas | 0:633cef71e6ba | 40 | |
nightseas | 0:633cef71e6ba | 41 | //Init functions |
nightseas | 0:633cef71e6ba | 42 | extern int BoardLibInit(void); |
nightseas | 0:633cef71e6ba | 43 | |
nightseas | 0:633cef71e6ba | 44 | //DC motor functions |
nightseas | 0:633cef71e6ba | 45 | extern void Mot_Init(void); |
nightseas | 0:633cef71e6ba | 46 | extern void Mot_Ctrl(char dir, char turn, float speed); |
nightseas | 0:633cef71e6ba | 47 | extern void Mot_PwmSetup(int channel, int period, float duty); |
nightseas | 0:633cef71e6ba | 48 | extern void Mot_PwmWrite(int channel, float duty); |
nightseas | 0:633cef71e6ba | 49 | extern void Mot_SetDirection(int channel, char dir); |
nightseas | 0:633cef71e6ba | 50 | |
nightseas | 0:633cef71e6ba | 51 | //Servo functions |
nightseas | 0:633cef71e6ba | 52 | extern void Servo_Init(void); |
nightseas | 0:633cef71e6ba | 53 | extern void Servo_SetAngle(int channel, float angle); |
nightseas | 0:633cef71e6ba | 54 | extern void Servo_PwmSetup(int channel, int pulse_us); |
nightseas | 0:633cef71e6ba | 55 | extern void Servo_PwmWrite(int channel, int pulse_us); |
nightseas | 0:633cef71e6ba | 56 | |
nightseas | 0:633cef71e6ba | 57 | //Voltage monitor functions |
nightseas | 0:633cef71e6ba | 58 | extern float Vmon_ReadVolt(int channel); |
nightseas | 0:633cef71e6ba | 59 | |
nightseas | 0:633cef71e6ba | 60 | //On-board LED functions |
nightseas | 0:633cef71e6ba | 61 | extern void LedOn(int ch); |
nightseas | 0:633cef71e6ba | 62 | extern void LedOff(int ch); |
nightseas | 0:633cef71e6ba | 63 | extern void LedToggle(int ch); |
nightseas | 0:633cef71e6ba | 64 | extern void LedOffAll(void); |
nightseas | 0:633cef71e6ba | 65 | extern void LedOnAll(void); |
nightseas | 0:633cef71e6ba | 66 | |
nightseas | 0:633cef71e6ba | 67 | #endif |