tbi fiat com controle feedforward PID

Dependencies:   mbed reScale TextLCD

main.cpp

Committer:
Marcelocostanzo
Date:
2018-04-25
Revision:
3:9d22aa32b223
Parent:
2:3c69c0772709
Child:
4:9da4a46f38bc

File content as of revision 3:9d22aa32b223:

#include "mbed.h"
 
InterruptIn motora(D0);
InterruptIn movida(D1);

DigitalOut ign(LED1);
PwmOut boost(LED2);


Timer tbase;
Ticker call;

Serial pc(USBTX, USBRX); // tx, rx

unsigned long int t_motora, t_movida, delta;

void tracao() 
{
    tbase.stop();
    t_motora = tbase.read_us();
    tbase.reset();
    tbase.start();   
}
 
void livre() 
{
    tbase.stop();
    t_movida = tbase.read_us();
    tbase.reset();
    tbase.start();   
}
 
void send() 
{       
    pc.printf("Tempo: %.3f Hz  \n\r");       
}
 
int main() 
{
    
    motora.fall(&tracao);  // attach the address of the measure function to the rising edge
    movida.fall(&livre);  // attach the address of the measure function to the rising edge
    
    //call.attach(&send, 0.5);
    
    while(1) 
    {    
        
        delta = t_motora - t_movida;
        boost.pulsewidth_ms(delta);
        
        if(t_movida < t_motora)
        {
            ign=0;
            wait(0.1);
        }
        
        else
        {
            ign=1;
        }
    }
}