PROCESAMIENTO_DIGITAL
/
motor_control_2
2
main.cpp@0:af38ab8b4a29, 2017-11-27 (annotated)
- Committer:
- Sumobot
- Date:
- Mon Nov 27 01:28:37 2017 +0000
- Revision:
- 0:af38ab8b4a29
ujbhknlm,; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sumobot | 0:af38ab8b4a29 | 1 | #include "mbed.h" |
Sumobot | 0:af38ab8b4a29 | 2 | #include "rtos.h" |
Sumobot | 0:af38ab8b4a29 | 3 | |
Sumobot | 0:af38ab8b4a29 | 4 | DigitalIn opto(p23); //Se declara el pin donde entran los pulsos del optoacoplador 1 "en sucio" |
Sumobot | 0:af38ab8b4a29 | 5 | DigitalOut senal1(p21); //Se declara el pin de salida que da los pulsos al optoacoplador 2 |
Sumobot | 0:af38ab8b4a29 | 6 | Thread Thread2; |
Sumobot | 0:af38ab8b4a29 | 7 | AnalogIn pot(p19); |
Sumobot | 0:af38ab8b4a29 | 8 | |
Sumobot | 0:af38ab8b4a29 | 9 | float b, c, d=.9, Control1=0; //Variable flotante en la cual se guardará la velocidad en rpm |
Sumobot | 0:af38ab8b4a29 | 10 | int iteraciones=0; //iteraciones=Variable que contará el número de pulsos |
Sumobot | 0:af38ab8b4a29 | 11 | |
Sumobot | 0:af38ab8b4a29 | 12 | void contador() { //Función ejecutada por la interrupción inter, la cual es un contador para la variable iteración |
Sumobot | 0:af38ab8b4a29 | 13 | d=.9; |
Sumobot | 0:af38ab8b4a29 | 14 | Thread::wait(2000); |
Sumobot | 0:af38ab8b4a29 | 15 | d=.8; |
Sumobot | 0:af38ab8b4a29 | 16 | Thread::wait(2000); |
Sumobot | 0:af38ab8b4a29 | 17 | d=.7; |
Sumobot | 0:af38ab8b4a29 | 18 | Thread::wait(2000); |
Sumobot | 0:af38ab8b4a29 | 19 | d=.6; |
Sumobot | 0:af38ab8b4a29 | 20 | Thread::wait(2000); |
Sumobot | 0:af38ab8b4a29 | 21 | d=.5; |
Sumobot | 0:af38ab8b4a29 | 22 | while(1) |
Sumobot | 0:af38ab8b4a29 | 23 | { |
Sumobot | 0:af38ab8b4a29 | 24 | d= pot.read(); |
Sumobot | 0:af38ab8b4a29 | 25 | } |
Sumobot | 0:af38ab8b4a29 | 26 | |
Sumobot | 0:af38ab8b4a29 | 27 | } |
Sumobot | 0:af38ab8b4a29 | 28 | |
Sumobot | 0:af38ab8b4a29 | 29 | int main() { |
Sumobot | 0:af38ab8b4a29 | 30 | |
Sumobot | 0:af38ab8b4a29 | 31 | Thread2.start(contador); |
Sumobot | 0:af38ab8b4a29 | 32 | |
Sumobot | 0:af38ab8b4a29 | 33 | while(1) { |
Sumobot | 0:af38ab8b4a29 | 34 | |
Sumobot | 0:af38ab8b4a29 | 35 | senal1=0; |
Sumobot | 0:af38ab8b4a29 | 36 | c = d*0.00833; |
Sumobot | 0:af38ab8b4a29 | 37 | |
Sumobot | 0:af38ab8b4a29 | 38 | if (opto==1) |
Sumobot | 0:af38ab8b4a29 | 39 | { |
Sumobot | 0:af38ab8b4a29 | 40 | wait(c); |
Sumobot | 0:af38ab8b4a29 | 41 | senal1=1; |
Sumobot | 0:af38ab8b4a29 | 42 | wait(.0003); |
Sumobot | 0:af38ab8b4a29 | 43 | senal1=0; |
Sumobot | 0:af38ab8b4a29 | 44 | wait(.009-c); |
Sumobot | 0:af38ab8b4a29 | 45 | } |
Sumobot | 0:af38ab8b4a29 | 46 | |
Sumobot | 0:af38ab8b4a29 | 47 | } |
Sumobot | 0:af38ab8b4a29 | 48 | } |