![](/media/cache/profiles/Cristian_Castro_-_Foto.jpg.50x50_q85.jpg)
Control de velocidad y dirección de giro de un motor PAP con la tarjeta F407. Se incluyen las librerías con la clase Motor.
mainpwm.cpp@0:3ca0289b7f8a, 2021-09-03 (annotated)
- Committer:
- CCastrop1012
- Date:
- Fri Sep 03 04:58:03 2021 +0000
- Revision:
- 0:3ca0289b7f8a
Control de velocidad y direccion de giro de un motor PAP con la tarjeta F407. Se incluyen las librerias con la clase Motor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CCastrop1012 | 0:3ca0289b7f8a | 1 | #include "mbed.h" |
CCastrop1012 | 0:3ca0289b7f8a | 2 | |
CCastrop1012 | 0:3ca0289b7f8a | 3 | DigitalOut IzqDireccion(PD_13); |
CCastrop1012 | 0:3ca0289b7f8a | 4 | DigitalOut LED(PD_14); |
CCastrop1012 | 0:3ca0289b7f8a | 5 | DigitalOut DerDireccion(PD_11); |
CCastrop1012 | 0:3ca0289b7f8a | 6 | |
CCastrop1012 | 0:3ca0289b7f8a | 7 | |
CCastrop1012 | 0:3ca0289b7f8a | 8 | PwmOut Speed(PB_15); |
CCastrop1012 | 0:3ca0289b7f8a | 9 | |
CCastrop1012 | 0:3ca0289b7f8a | 10 | int main() { |
CCastrop1012 | 0:3ca0289b7f8a | 11 | |
CCastrop1012 | 0:3ca0289b7f8a | 12 | Speed.period_ms(5); |
CCastrop1012 | 0:3ca0289b7f8a | 13 | |
CCastrop1012 | 0:3ca0289b7f8a | 14 | while(1) |
CCastrop1012 | 0:3ca0289b7f8a | 15 | { |
CCastrop1012 | 0:3ca0289b7f8a | 16 | |
CCastrop1012 | 0:3ca0289b7f8a | 17 | /// direccion 1 |
CCastrop1012 | 0:3ca0289b7f8a | 18 | LED = 1; |
CCastrop1012 | 0:3ca0289b7f8a | 19 | IzqDireccion = 1; |
CCastrop1012 | 0:3ca0289b7f8a | 20 | DerDireccion = !IzqDireccion; |
CCastrop1012 | 0:3ca0289b7f8a | 21 | wait_ms(100); |
CCastrop1012 | 0:3ca0289b7f8a | 22 | |
CCastrop1012 | 0:3ca0289b7f8a | 23 | /// Speed setting |
CCastrop1012 | 0:3ca0289b7f8a | 24 | for(int i = 0; i < 100; i ++) |
CCastrop1012 | 0:3ca0289b7f8a | 25 | { |
CCastrop1012 | 0:3ca0289b7f8a | 26 | Speed.write(float(i/100.0)); |
CCastrop1012 | 0:3ca0289b7f8a | 27 | wait(1); |
CCastrop1012 | 0:3ca0289b7f8a | 28 | |
CCastrop1012 | 0:3ca0289b7f8a | 29 | } |
CCastrop1012 | 0:3ca0289b7f8a | 30 | |
CCastrop1012 | 0:3ca0289b7f8a | 31 | /// Set a 0 |
CCastrop1012 | 0:3ca0289b7f8a | 32 | IzqDireccion = 0; |
CCastrop1012 | 0:3ca0289b7f8a | 33 | DerDireccion = 0; |
CCastrop1012 | 0:3ca0289b7f8a | 34 | wait_ms(100); |
CCastrop1012 | 0:3ca0289b7f8a | 35 | |
CCastrop1012 | 0:3ca0289b7f8a | 36 | /// Direccion 2 |
CCastrop1012 | 0:3ca0289b7f8a | 37 | LED = 0; |
CCastrop1012 | 0:3ca0289b7f8a | 38 | IzqDireccion = 0; |
CCastrop1012 | 0:3ca0289b7f8a | 39 | DerDireccion = !IzqDireccion; |
CCastrop1012 | 0:3ca0289b7f8a | 40 | wait_ms(100); |
CCastrop1012 | 0:3ca0289b7f8a | 41 | |
CCastrop1012 | 0:3ca0289b7f8a | 42 | // Speed Setting |
CCastrop1012 | 0:3ca0289b7f8a | 43 | for(int i = 0; i < 10; i ++) |
CCastrop1012 | 0:3ca0289b7f8a | 44 | { |
CCastrop1012 | 0:3ca0289b7f8a | 45 | Speed.write(float(i/100.0)); |
CCastrop1012 | 0:3ca0289b7f8a | 46 | wait(1); |
CCastrop1012 | 0:3ca0289b7f8a | 47 | |
CCastrop1012 | 0:3ca0289b7f8a | 48 | } |
CCastrop1012 | 0:3ca0289b7f8a | 49 | |
CCastrop1012 | 0:3ca0289b7f8a | 50 | /// Set to 0 |
CCastrop1012 | 0:3ca0289b7f8a | 51 | IzqDireccion = 0; |
CCastrop1012 | 0:3ca0289b7f8a | 52 | DerDireccion = 0; |
CCastrop1012 | 0:3ca0289b7f8a | 53 | wait_ms(100); |
CCastrop1012 | 0:3ca0289b7f8a | 54 | } |
CCastrop1012 | 0:3ca0289b7f8a | 55 | } |