Juan Carlos Suárez Barón
/
L298
PWM with L298
Fork of L298 by
main.cpp@2:2e93c305bb62, 2016-06-23 (annotated)
- Committer:
- juanitoinig84
- Date:
- Thu Jun 23 12:43:49 2016 +0000
- Revision:
- 2:2e93c305bb62
- Parent:
- 1:c83539e7f8a0
PWM wirh L298 for 2 DC motors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
satelite | 0:f3cd2e9ab89b | 1 | #include "mbed.h" |
satelite | 0:f3cd2e9ab89b | 2 | |
juanitoinig84 | 2:2e93c305bb62 | 3 | |
juanitoinig84 | 2:2e93c305bb62 | 4 | Serial pc(USBTX,USBRX); // tx,rx |
satelite | 0:f3cd2e9ab89b | 5 | DigitalOut in1(PTC3); |
satelite | 0:f3cd2e9ab89b | 6 | DigitalOut in2(PTC2); |
satelite | 0:f3cd2e9ab89b | 7 | PwmOut ena(PTA2); |
satelite | 0:f3cd2e9ab89b | 8 | |
juanitoinig84 | 1:c83539e7f8a0 | 9 | DigitalOut in3(PTD1); |
juanitoinig84 | 1:c83539e7f8a0 | 10 | DigitalOut in4(PTD2); |
juanitoinig84 | 1:c83539e7f8a0 | 11 | PwmOut enb(PTD3); |
juanitoinig84 | 1:c83539e7f8a0 | 12 | |
juanitoinig84 | 2:2e93c305bb62 | 13 | void rxInterrupt(){ |
juanitoinig84 | 2:2e93c305bb62 | 14 | } |
satelite | 0:f3cd2e9ab89b | 15 | int main() |
juanitoinig84 | 2:2e93c305bb62 | 16 | |
satelite | 0:f3cd2e9ab89b | 17 | { |
juanitoinig84 | 2:2e93c305bb62 | 18 | pc.baud(115200); |
juanitoinig84 | 2:2e93c305bb62 | 19 | pc.attach(&rxInterrupt); |
satelite | 0:f3cd2e9ab89b | 20 | while (true) { |
juanitoinig84 | 1:c83539e7f8a0 | 21 | /////******MOTOR 1****//// |
satelite | 0:f3cd2e9ab89b | 22 | // Detiene el motor |
satelite | 0:f3cd2e9ab89b | 23 | in1 = 0; |
satelite | 0:f3cd2e9ab89b | 24 | in2 = 0; |
satelite | 0:f3cd2e9ab89b | 25 | wait(0.5f); |
satelite | 0:f3cd2e9ab89b | 26 | // Gira en sentido 1 con velocidad 50% |
satelite | 0:f3cd2e9ab89b | 27 | in1 = 1; |
satelite | 0:f3cd2e9ab89b | 28 | in2 = 0; |
satelite | 0:f3cd2e9ab89b | 29 | ena.write(0.50f); |
satelite | 0:f3cd2e9ab89b | 30 | wait(0.5f); |
satelite | 0:f3cd2e9ab89b | 31 | // Gira en sentido 2 con velocidad 100% |
satelite | 0:f3cd2e9ab89b | 32 | in1 = 0; |
satelite | 0:f3cd2e9ab89b | 33 | in2 = 1; |
satelite | 0:f3cd2e9ab89b | 34 | ena.write(1.00f); |
satelite | 0:f3cd2e9ab89b | 35 | wait(0.5f); |
juanitoinig84 | 1:c83539e7f8a0 | 36 | |
juanitoinig84 | 1:c83539e7f8a0 | 37 | /////******MOTOR 2****//// |
juanitoinig84 | 2:2e93c305bb62 | 38 | /* in3 = 0; |
juanitoinig84 | 1:c83539e7f8a0 | 39 | in4 = 0; |
juanitoinig84 | 1:c83539e7f8a0 | 40 | wait(0.5f); |
juanitoinig84 | 1:c83539e7f8a0 | 41 | // Gira en sentido 1 con velocidad 50% |
juanitoinig84 | 1:c83539e7f8a0 | 42 | in3 = 1; |
juanitoinig84 | 1:c83539e7f8a0 | 43 | in4 = 0; |
juanitoinig84 | 1:c83539e7f8a0 | 44 | ena.write(0.50f); |
juanitoinig84 | 1:c83539e7f8a0 | 45 | wait(0.5f); |
juanitoinig84 | 1:c83539e7f8a0 | 46 | // Gira en sentido 2 con velocidad 100% |
juanitoinig84 | 1:c83539e7f8a0 | 47 | in3 = 0; |
juanitoinig84 | 1:c83539e7f8a0 | 48 | in4 = 1; |
juanitoinig84 | 1:c83539e7f8a0 | 49 | ena.write(1.00f); |
juanitoinig84 | 2:2e93c305bb62 | 50 | wait(0.5f);*/ |
juanitoinig84 | 2:2e93c305bb62 | 51 | pc.printf("MOTOR Funcionando\n"); |
juanitoinig84 | 2:2e93c305bb62 | 52 | |
satelite | 0:f3cd2e9ab89b | 53 | } |
satelite | 0:f3cd2e9ab89b | 54 | } |