tbi fiat com controle feedforward PID

Dependencies:   mbed reScale TextLCD

main.cpp

Committer:
Marcelocostanzo
Date:
2018-04-26
Revision:
4:9da4a46f38bc
Parent:
3:9d22aa32b223
Child:
5:e04419b1e369

File content as of revision 4:9da4a46f38bc:

#include "mbed.h"
#include "TextLCD.h"

I2C i2c_lcd(PTC9,PTC8); // SDA, SCL

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;

TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD16x2);                  // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type

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

    lcd.setBacklight(TextLCD::LightOn);    
    lcd.setCursor(TextLCD::CurOff_BlkOff);       
    lcd.setAddress(0,0);  
    lcd.printf("Controle de");
    lcd.setAddress(0,1);  
    lcd.printf("TRACAO");
    wait(1.5);
    lcd.cls(); 

    
    while(1) 
    {    
        
        delta = t_motora - t_movida;
        boost.pulsewidth_ms(delta);
        
        if(t_movida < t_motora)
        {
            ign=0;
            wait(0.1);
            lcd.setAddress(0,0);  
            lcd.printf("Destracionando");
        }
        
        else
        {
            ign=1;
            lcd.setAddress(0,0);  
            lcd.printf("Normal         ");
        }
    }
}