Hi, i´d like to know if anyone knows why my values are getting stuck. I'm controlling the temperature of a liquid with a PID controller. To measure the temperature, i'm using a 50kOhm NTC 3950 thermistor. Since i need to convert the voltages to degrees, i created a function block (I took this part from a project posted in another thread, Thanks, Admin!). I then display this value on an LCD screen. So far, it works correctly. When i implement the PID controller, it also work correctly. However, when i try to use the ramp block or create my own, my microcontroller (arduino UNO) freezes. The fist value read is displayed on the screen and the PWM output remains static. I don't understand why this is happening. There are the variables i used:
Hola quisiera saber si alguien sabe porque mis valores quedan tildados. Estoy haciendo un control de temperatura de un liquido por medio de PID, para medir la temperatura uso un NTC 50K 3950 y como debo convertir los voltajes a grados creo un bloque de funcion (esta parte lo tome de un proyecto que se subio en otro tema, gracias admin 🙂 ) y luego muestro este valor por medio de un LCD hasta aca funciona como se espera, luego cuando implemento un PID tambien funciona como se espera, ahora cuando intento usar el bloque rampa o crear mi propio bloque rampa, mi Microcontrolador (arduino uno) queda tildado es decir por pantalla se muestra el primer valor leido y queda congelado y en la salida PWM queda estatica y no entiendo porque sucede esto.
Estas son las variables que use:
![[203128%2F9715915%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9715915%2Fmceclip0.png)
and the "ladder" I tried to make work:
y el ladder con el que intente hacer que funcione:
![[203128%2F9715916%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9715916%2Fmceclip0.png)
The idea is that if the read value (degrees) is less than the difference between the setpoint and SetPointDiff, the RAMP0 block is activated and the resulting value is sent to the PID block i created, which has the following varibles in th ST:
la idea es que si el valor leido (grados) es menor que la diferencia entre el setpoint y SetPointDiff se active el bloque RAMP0 y que el valor obtenido vaya al bloque PID que yo cree:
que tiene las siguientes variables en el ST:
![[203128%2F9715917%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9715917%2Fmceclip0.png)
![[203128%2F9715919%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9715919%2Fmceclip0.png)
(*Calculo de error*)
Error := SetPoint - Temperatura;
(*Proporcional*)
Proporcional := Kp * Error;
(*Derivativo*)
Derivativo := Kd * ((Error - Error_Prev)/Ts_refresco);
(*Integral solo cerca del setpoint*)
IF (Error > -3.0) AND (Error < 3.0) THEN
Integrador := Integrador + (Ki * Error);
ELSE
Integrador := 0.0;
END_IF;
PID_TOTAL := Proporcional + Integrador + Derivativo;
(*Escalado equivalente a map (0..150 -> 0..255)*)
(*PID_TOTAL := (PID_TOTAL * 255.0) / 150.0;*)
PID_TOTAL := (PID_TOTAL * 1023.0) / 150.0;
(*SATURACIÓN*)
IF PID_TOTAL < 0.0 THEN
PID_TOTAL :=0.0;
END_IF;
(*IF PID_TOTAL > 255.0 THEN
PID_TOTAL := 255.0;
END_IF;*)
IF PID_TOTAL > 1023.0 THEN
PID_TOTAL := 1023.0;
END_IF;
(*Salida := 255.0 - PID_TOTAL;*)
Salida := REAL_TO_WORD(PID_TOTAL);
(*Guardar Error anterior*)
Error_Prev := Error;
led3 :=REAL_TO_WORD(500.0);
-------------------------------
Another way:
otra forma en la que intente es la siguiente:
![[203128%2F9715974%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9715974%2Fmceclip0.png)
![[203128%2F9715975%2Fmceclip0]](https://d28lcup14p4e72.cloudfront.net/203128%2F9715975%2Fmceclip0.png)
y el ST de CONTROL_DE_ESTADOS es:
(* ============================================================
Control de Estados - Inicio automático al energizar
Estado 0: RAMP UP - Potencia máxima hasta acercarse al SP
Estado 1: PID - Control PID activo
============================================================ *)
CASE Estado OF
0: (* ---- RAMP UP ---- *)
Salida := INT_TO_WORD(1023);
LED := TRUE;
IF Temperatura >= (SetPoint - SetPointDiff) THEN
Estado := 1;
END_IF;
1: (* ---- PID CONTROL ---- *)
PID1(
Temperatura := Temperatura,
SetPoint := SetPoint,
Kp := Kp,
Ki := Ki,
Kd := Kd,
Ts_refresco := Ts_refresco,
Salida => Salida
);
(* Parpadeo LED como indicador de PID activo *)
Blink_Count := Blink_Count + 1;
IF Blink_Count >= 50 THEN
LED_State := NOT LED_State;
LED := LED_State;
Blink_Count := 0;
END_IF;
ELSE
(* Estado inválido: volver a empezar *)
Estado := 0;
Salida := INT_TO_WORD(0);
LED := FALSE;
END_CASE;
------------------------
The arduino extension used in all cases is the following:
Para poder usar el LCD con I2C emplee una extension de arduino con el siguiente codigo para todos los casos:
//////////////////////////////// sketch section ////////////////////////////////
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void sketch_setup(){
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Control Temp");
delay(1500);
}
void sketch_loop() {
static unsigned long lastUpdate = 0;
if (millis() - lastUpdate >= 500) { // actualizar cada 500ms
lastUpdate = millis();
lcd.setCursor(6, 1);
lcd.print(" "); // limpiar 6 chars primero
lcd.setCursor(6, 1);
lcd.print(Grados_Centigrados, 1);
}
}
------------------------
The block for the NTC is as follows:
el bloque de conversion_temp es el siguiente: