Funciones en Mikroc [cerrado]

-2

A continuación se muestra mi código que da error como "todas las funciones y variables no están definidas" Por favor ayuda Escribí un programa para el control de velocidad del motor dc para pic18f8722 en Mikroc Por favor ayuda

float pid (int actualOut)
{
    error = setPoint - actualOut;
    pOut = error*p;
    iOut = iOut + error*i;

    if (iOut > 255)
        iOut = 255;
    else if (iOut < 0)
        iOut = 0;

    dOut = (error - lastError)*d;
    out = pOut + iOut + dOut;
    lastError = error;

    if (out > 255)
        out = 255;
    else if (out < 0)
        out=0;

    return out;
}

void pwm (short duty) 
{
    short dutyCycle = duty;
    PWM1_Init (5000);
    PWM1_Start ();
    PWM1_Set_Duty (dutyCycle);
    delay_ms (500);
}

Int feedback () 
{
    T0CON = 0xC2;
    TMR0l = 193;
    INTCON = 0xA0;
    TMR1l = 0;
    TMR1H = 0;
    T1CON = 0x87;
    s = 1;
    while (s == 1) {}

    actualOut = (60 * 2 * TMR1L) / 24;
    return actualOut;
}

void interrupt ()
{
    T1CON = 0x00;
    S = 0;
}

void main ()
{

    float p = 100, i = 200, d = 10;
    int setPoint = 100, s = 1;
    int actualOut = 0;
    float pOut = 0, iOut = 0, dOut = 0;
    float out = 16;
    int error = 0, lastError = 0;
    short duty;

    TRISC = 1;
    TRISG = 0;


    while (1) {
        float out = pid (actualOut);
        duty = (short)out;
        pwm (duty);
        int actualOut = feedback ();
    }
}
    
pregunta user4380889

1 respuesta

2

Bien, permítame revisar y anotar su código con todos los errores que saltan inmediatamente hacia mí:

float pid (int actualOut)
{
    error = setPoint - actualOut;   <<== error and setPoint have not been defined
    pOut = error*p;                 <<== pOut and p have not been defined
    iOut = iOut + error*i;          <<== iOut and i have not been defined

    if (iOut > 255)
        iOut = 255;
    else if (iOut < 0)
        iOut = 0;

    dOut = (error - lastError)*d;   <<== dOut, lastError and d have not been defined.
    out = pOut + iOut + dOut;       <<== out has not been defined
    lastError = error;

    if (out > 255)
        out = 255;
    else if (out < 0)
        out=0;

    return out;
}

void pwm (short duty) 
{
    short dutyCycle = duty;
    PWM1_Init (5000);
    PWM1_Start ();
    PWM1_Set_Duty (dutyCycle);
    delay_ms (500);
}

Int feedback ()                     <<== Int is not a valid data type
{
    T0CON = 0xC2;
    TMR0l = 193;
    INTCON = 0xA0;
    TMR1l = 0;
    TMR1H = 0;
    T1CON = 0x87;
    s = 1;                          <<== s has not been defined
    while (s == 1) {}

    actualOut = (60 * 2 * TMR1L) / 24;  <<== actualOut has not been defined
    return actualOut;
}

void interrupt ()
{
    T1CON = 0x00;
    S = 0;  <<== S has not been defined
}

void main ()
{

    float p = 100, i = 200, d = 10;      <<== These are defined but not used
    int setPoint = 100, s = 1;           <<== These are defined but not used
    int actualOut = 0;                   <<== This is defined but not used
    float pOut = 0, iOut = 0, dOut = 0;  <<== These are defined byt not used
    float out = 16;                      <<== This is defined but not used
    int error = 0, lastError = 0;        <<== These are defined but not used
    short duty;

    TRISC = 1;
    TRISG = 0;


    while (1) {
        float out = pid (actualOut);     <<== This overrides an earlier definition
        duty = (short)out;
        pwm (duty);
        int actualOut = feedback ();     <<== This overrides an earlier definition
    }
}

Hay tantos errores que sospecho que le falta la comprensión básica de C para poder programarlo. Le sugiero que vuelva a lo básico y aprenda la estructura de C, especialmente en relación con scope .

    
respondido por el Majenko

Lea otras preguntas en las etiquetas