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.
Dependents: ME503_VehicleAssembly
DRV8835.cpp@0:0902ae053e3f, 2015-08-25 (annotated)
- Committer:
- DrCoyle
- Date:
- Tue Aug 25 20:29:27 2015 +0000
- Revision:
- 0:0902ae053e3f
- Child:
- 1:edc8af84b968
Library for ERAU ME503
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| DrCoyle | 0:0902ae053e3f | 1 | /* File: DRV8835.cpp |
| DrCoyle | 0:0902ae053e3f | 2 | * Adopted from work by Cameron Isbell |
| DrCoyle | 0:0902ae053e3f | 3 | * |
| DrCoyle | 0:0902ae053e3f | 4 | * Description: library for DRV8835 Motor Driver |
| DrCoyle | 0:0902ae053e3f | 5 | * Assumptions: A is left and B is right |
| DrCoyle | 0:0902ae053e3f | 6 | */ |
| DrCoyle | 0:0902ae053e3f | 7 | |
| DrCoyle | 0:0902ae053e3f | 8 | #include "mbed.h" |
| DrCoyle | 0:0902ae053e3f | 9 | #include "DRV8835.h" |
| DrCoyle | 0:0902ae053e3f | 10 | |
| DrCoyle | 0:0902ae053e3f | 11 | |
| DrCoyle | 0:0902ae053e3f | 12 | DRV8835::DRV8835( PinName pinPwmL, PinName pinLin, |
| DrCoyle | 0:0902ae053e3f | 13 | PinName pinPwmR, PinName pinRin) : |
| DrCoyle | 0:0902ae053e3f | 14 | pwmL(pinPwmL), |
| DrCoyle | 0:0902ae053e3f | 15 | Lin(pinLin), |
| DrCoyle | 0:0902ae053e3f | 16 | pwmR(pinPwmR), |
| DrCoyle | 0:0902ae053e3f | 17 | Rin(pinRin) |
| DrCoyle | 0:0902ae053e3f | 18 | { |
| DrCoyle | 0:0902ae053e3f | 19 | Lin = 0; |
| DrCoyle | 0:0902ae053e3f | 20 | Rin = 0; |
| DrCoyle | 0:0902ae053e3f | 21 | pwmL.period(DRV8835_PWM_PERIOD_DEFAULT); |
| DrCoyle | 0:0902ae053e3f | 22 | pwmL = DRV8835_PWM_PULSEWIDTH_DEFAULT; |
| DrCoyle | 0:0902ae053e3f | 23 | pwmR.period(DRV8835_PWM_PERIOD_DEFAULT); |
| DrCoyle | 0:0902ae053e3f | 24 | pwmR = DRV8835_PWM_PULSEWIDTH_DEFAULT; |
| DrCoyle | 0:0902ae053e3f | 25 | motorL_stop(); |
| DrCoyle | 0:0902ae053e3f | 26 | motorR_stop(); |
| DrCoyle | 0:0902ae053e3f | 27 | } |
| DrCoyle | 0:0902ae053e3f | 28 | |
| DrCoyle | 0:0902ae053e3f | 29 | |
| DrCoyle | 0:0902ae053e3f | 30 | void DRV8835::motorL_stop(void) |
| DrCoyle | 0:0902ae053e3f | 31 | { |
| DrCoyle | 0:0902ae053e3f | 32 | pwmL = 0; |
| DrCoyle | 0:0902ae053e3f | 33 | } |
| DrCoyle | 0:0902ae053e3f | 34 | |
| DrCoyle | 0:0902ae053e3f | 35 | void DRV8835::motorL_rev(float fPulsewidth) |
| DrCoyle | 0:0902ae053e3f | 36 | { |
| DrCoyle | 0:0902ae053e3f | 37 | Lin = 0; |
| DrCoyle | 0:0902ae053e3f | 38 | pwmL = fPulsewidth; |
| DrCoyle | 0:0902ae053e3f | 39 | } |
| DrCoyle | 0:0902ae053e3f | 40 | |
| DrCoyle | 0:0902ae053e3f | 41 | void DRV8835::motorL_fwd(float fPulsewidth) |
| DrCoyle | 0:0902ae053e3f | 42 | { |
| DrCoyle | 0:0902ae053e3f | 43 | Lin = 1; |
| DrCoyle | 0:0902ae053e3f | 44 | pwmL = fPulsewidth; |
| DrCoyle | 0:0902ae053e3f | 45 | } |
| DrCoyle | 0:0902ae053e3f | 46 | |
| DrCoyle | 0:0902ae053e3f | 47 | void DRV8835::motorR_stop(void) |
| DrCoyle | 0:0902ae053e3f | 48 | { |
| DrCoyle | 0:0902ae053e3f | 49 | pwmR = 0; |
| DrCoyle | 0:0902ae053e3f | 50 | } |
| DrCoyle | 0:0902ae053e3f | 51 | |
| DrCoyle | 0:0902ae053e3f | 52 | void DRV8835::motorR_fwd(float fPulsewidth) |
| DrCoyle | 0:0902ae053e3f | 53 | { |
| DrCoyle | 0:0902ae053e3f | 54 | Rin = 0; |
| DrCoyle | 0:0902ae053e3f | 55 | pwmR = fPulsewidth; |
| DrCoyle | 0:0902ae053e3f | 56 | } |
| DrCoyle | 0:0902ae053e3f | 57 | |
| DrCoyle | 0:0902ae053e3f | 58 | void DRV8835::motorR_rev(float fPulsewidth) |
| DrCoyle | 0:0902ae053e3f | 59 | { |
| DrCoyle | 0:0902ae053e3f | 60 | Rin = 1; |
| DrCoyle | 0:0902ae053e3f | 61 | pwmR = fPulsewidth; |
| DrCoyle | 0:0902ae053e3f | 62 | } |