Libraire pour la controler le module DRV8825
Dependents: AresCDFMainCode_capteur_US AresCDFMainCode_us2 AresCDFMainCode
DRV8825.cpp@4:d9e022811431, 2020-07-05 (annotated)
- Committer:
- g0dd4
- Date:
- Sun Jul 05 08:42:07 2020 +0000
- Revision:
- 4:d9e022811431
- Parent:
- 3:ec3e5c8dd41b
- Child:
- 6:12fa3864b532
Correction d'une erreur l.50 period_us -> period_ms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
g0dd4 | 0:4bf91783cb4d | 1 | #include "DRV8825.h" |
g0dd4 | 0:4bf91783cb4d | 2 | |
g0dd4 | 3:ec3e5c8dd41b | 3 | /** |
g0dd4 | 3:ec3e5c8dd41b | 4 | * @brief Initialisation du modul avec des paramètres par défaut |
g0dd4 | 3:ec3e5c8dd41b | 5 | */ |
g0dd4 | 3:ec3e5c8dd41b | 6 | DRV8825::DRV8825(){ |
g0dd4 | 3:ec3e5c8dd41b | 7 | |
g0dd4 | 0:4bf91783cb4d | 8 | |
g0dd4 | 3:ec3e5c8dd41b | 9 | m_en = new DigitalOut(PC_5); |
g0dd4 | 3:ec3e5c8dd41b | 10 | m_dir = new DigitalOut(PC_6); |
g0dd4 | 3:ec3e5c8dd41b | 11 | m_step = new FastPWM(PC_8); |
g0dd4 | 0:4bf91783cb4d | 12 | m_step->write(0.50); |
g0dd4 | 0:4bf91783cb4d | 13 | } |
g0dd4 | 0:4bf91783cb4d | 14 | |
g0dd4 | 0:4bf91783cb4d | 15 | |
g0dd4 | 3:ec3e5c8dd41b | 16 | /** |
g0dd4 | 3:ec3e5c8dd41b | 17 | * @brief Initialisation du modul avec des paramètres choisis |
g0dd4 | 3:ec3e5c8dd41b | 18 | * @param en : pin En |
g0dd4 | 3:ec3e5c8dd41b | 19 | * @param dir : pin Dir |
g0dd4 | 3:ec3e5c8dd41b | 20 | * @param step : pin Step |
g0dd4 | 3:ec3e5c8dd41b | 21 | */ |
g0dd4 | 0:4bf91783cb4d | 22 | DRV8825::DRV8825(PinName en, PinName dir ,PinName step){ |
g0dd4 | 0:4bf91783cb4d | 23 | m_en = new DigitalOut(en); |
g0dd4 | 0:4bf91783cb4d | 24 | m_dir = new DigitalOut(dir); |
g0dd4 | 0:4bf91783cb4d | 25 | m_step = new FastPWM(step); |
g0dd4 | 0:4bf91783cb4d | 26 | m_step->write(0.50); |
g0dd4 | 0:4bf91783cb4d | 27 | } |
g0dd4 | 0:4bf91783cb4d | 28 | |
g0dd4 | 3:ec3e5c8dd41b | 29 | /** |
g0dd4 | 3:ec3e5c8dd41b | 30 | * @brief Permet d'affecter une directions à notre module |
g0dd4 | 3:ec3e5c8dd41b | 31 | * @param dir : l'état que l'on souhaite appliquer |
g0dd4 | 3:ec3e5c8dd41b | 32 | */ |
g0dd4 | 0:4bf91783cb4d | 33 | void DRV8825::setDir(uint8_t dir){ |
g0dd4 | 0:4bf91783cb4d | 34 | m_dir->write(dir); |
g0dd4 | 0:4bf91783cb4d | 35 | } |
g0dd4 | 0:4bf91783cb4d | 36 | |
g0dd4 | 3:ec3e5c8dd41b | 37 | /** |
g0dd4 | 3:ec3e5c8dd41b | 38 | * @brief Permet de définir si l'on souhaite bloquer ou non le moteur |
g0dd4 | 3:ec3e5c8dd41b | 39 | * @param en : l'état que l'on douhaite appliquer |
g0dd4 | 3:ec3e5c8dd41b | 40 | */ |
g0dd4 | 0:4bf91783cb4d | 41 | void DRV8825::setEnable(uint8_t en){ |
g0dd4 | 0:4bf91783cb4d | 42 | m_en->write(en); |
g0dd4 | 0:4bf91783cb4d | 43 | } |
g0dd4 | 0:4bf91783cb4d | 44 | |
g0dd4 | 3:ec3e5c8dd41b | 45 | /** |
g0dd4 | 3:ec3e5c8dd41b | 46 | * @brief Permet de définir la vitesse du moteur pas à pas |
g0dd4 | 3:ec3e5c8dd41b | 47 | * @param ms : le temps en millis milliseconds |
g0dd4 | 3:ec3e5c8dd41b | 48 | */ |
g0dd4 | 2:6d084e96623d | 49 | void DRV8825::move(unsigned int ms){ |
g0dd4 | 4:d9e022811431 | 50 | m_step->period_ms(ms); |
g0dd4 | 0:4bf91783cb4d | 51 | m_step->write(0.50); |
g0dd4 | 0:4bf91783cb4d | 52 | } |