![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
tbi fiat com controle feedforward PID
Dependencies: mbed reScale TextLCD
main.cpp@3:9d22aa32b223, 2018-04-25 (annotated)
- Committer:
- Marcelocostanzo
- Date:
- Wed Apr 25 12:10:09 2018 +0000
- Revision:
- 3:9d22aa32b223
- Parent:
- 2:3c69c0772709
- Child:
- 4:9da4a46f38bc
Segunda vers?o com pwm, n?o testada
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:b5a9e0614efd | 1 | #include "mbed.h" |
Marcelocostanzo | 2:3c69c0772709 | 2 | |
Marcelocostanzo | 2:3c69c0772709 | 3 | InterruptIn motora(D0); |
Marcelocostanzo | 2:3c69c0772709 | 4 | InterruptIn movida(D1); |
Marcelocostanzo | 2:3c69c0772709 | 5 | |
Marcelocostanzo | 2:3c69c0772709 | 6 | DigitalOut ign(LED1); |
Marcelocostanzo | 3:9d22aa32b223 | 7 | PwmOut boost(LED2); |
mbed_official | 0:b5a9e0614efd | 8 | |
Marcelocostanzo | 2:3c69c0772709 | 9 | |
Marcelocostanzo | 2:3c69c0772709 | 10 | Timer tbase; |
Marcelocostanzo | 2:3c69c0772709 | 11 | Ticker call; |
Marcelocostanzo | 2:3c69c0772709 | 12 | |
Marcelocostanzo | 2:3c69c0772709 | 13 | Serial pc(USBTX, USBRX); // tx, rx |
Marcelocostanzo | 2:3c69c0772709 | 14 | |
Marcelocostanzo | 3:9d22aa32b223 | 15 | unsigned long int t_motora, t_movida, delta; |
mbed_official | 0:b5a9e0614efd | 16 | |
Marcelocostanzo | 2:3c69c0772709 | 17 | void tracao() |
Marcelocostanzo | 2:3c69c0772709 | 18 | { |
Marcelocostanzo | 2:3c69c0772709 | 19 | tbase.stop(); |
Marcelocostanzo | 2:3c69c0772709 | 20 | t_motora = tbase.read_us(); |
Marcelocostanzo | 2:3c69c0772709 | 21 | tbase.reset(); |
Marcelocostanzo | 2:3c69c0772709 | 22 | tbase.start(); |
Marcelocostanzo | 2:3c69c0772709 | 23 | } |
Marcelocostanzo | 2:3c69c0772709 | 24 | |
Marcelocostanzo | 2:3c69c0772709 | 25 | void livre() |
Marcelocostanzo | 2:3c69c0772709 | 26 | { |
Marcelocostanzo | 2:3c69c0772709 | 27 | tbase.stop(); |
Marcelocostanzo | 2:3c69c0772709 | 28 | t_movida = tbase.read_us(); |
Marcelocostanzo | 2:3c69c0772709 | 29 | tbase.reset(); |
Marcelocostanzo | 2:3c69c0772709 | 30 | tbase.start(); |
Marcelocostanzo | 2:3c69c0772709 | 31 | } |
Marcelocostanzo | 2:3c69c0772709 | 32 | |
Marcelocostanzo | 2:3c69c0772709 | 33 | void send() |
Marcelocostanzo | 2:3c69c0772709 | 34 | { |
Marcelocostanzo | 2:3c69c0772709 | 35 | pc.printf("Tempo: %.3f Hz \n\r"); |
Marcelocostanzo | 2:3c69c0772709 | 36 | } |
Marcelocostanzo | 2:3c69c0772709 | 37 | |
Marcelocostanzo | 2:3c69c0772709 | 38 | int main() |
Marcelocostanzo | 2:3c69c0772709 | 39 | { |
Marcelocostanzo | 2:3c69c0772709 | 40 | |
Marcelocostanzo | 2:3c69c0772709 | 41 | motora.fall(&tracao); // attach the address of the measure function to the rising edge |
Marcelocostanzo | 2:3c69c0772709 | 42 | movida.fall(&livre); // attach the address of the measure function to the rising edge |
Marcelocostanzo | 2:3c69c0772709 | 43 | |
Marcelocostanzo | 2:3c69c0772709 | 44 | //call.attach(&send, 0.5); |
Marcelocostanzo | 2:3c69c0772709 | 45 | |
Marcelocostanzo | 2:3c69c0772709 | 46 | while(1) |
Marcelocostanzo | 2:3c69c0772709 | 47 | { |
Marcelocostanzo | 3:9d22aa32b223 | 48 | |
Marcelocostanzo | 3:9d22aa32b223 | 49 | delta = t_motora - t_movida; |
Marcelocostanzo | 3:9d22aa32b223 | 50 | boost.pulsewidth_ms(delta); |
Marcelocostanzo | 3:9d22aa32b223 | 51 | |
Marcelocostanzo | 2:3c69c0772709 | 52 | if(t_movida < t_motora) |
Marcelocostanzo | 2:3c69c0772709 | 53 | { |
Marcelocostanzo | 2:3c69c0772709 | 54 | ign=0; |
Marcelocostanzo | 2:3c69c0772709 | 55 | wait(0.1); |
Marcelocostanzo | 2:3c69c0772709 | 56 | } |
Marcelocostanzo | 2:3c69c0772709 | 57 | |
Marcelocostanzo | 2:3c69c0772709 | 58 | else |
Marcelocostanzo | 2:3c69c0772709 | 59 | { |
Marcelocostanzo | 2:3c69c0772709 | 60 | ign=1; |
Marcelocostanzo | 2:3c69c0772709 | 61 | } |
mbed_official | 0:b5a9e0614efd | 62 | } |
Marcelocostanzo | 2:3c69c0772709 | 63 | } |