Hallo,
ich habe jetzt mal versucht den 1. Steuerkreis zu programmieren.
Es ist aus diversen Modulen zusammengesetzt,
leider krieg ich den Code nicht mehr compiliert,
seit dem ich den Lookup Table eingebaut habe.
Vielleicht kann jemand mal mit einem wachsamen Auge drüberschauen
und mir helfen.
Dankeeeee
Grüße Lena
#include <avr/pgmspace.h>
/*==============================================================================
* GLOBAL VARIABLES
*============================================================================*/
//Variables:
int nextCall = HIGH;
int S1Pin = 0; // Lüfterschalter
int S2Pin = 1; // Druckschalter
int S3Pin = 2; // Schalter Zwangskühlung
int S4Pin = 3; // Schalter NOT-AUS
int TempSensorPin = A0; // Wassertemperaturgeber
int tempval = 0;
int s1 = 0; //input Switch 1
int s2 = 0; //input Switch 2
int s3 = 0; //input Switch 3
int s4 = 0; //input Switch 4
int fanval = 0; //output % Wert Kühlgebläse
const int ledPin = 13; // Pin PWM Ausgang an Kühlgebläse
unsigned long pmicros;
//Lookup Table for the VDOtemperature (22 Values) Its Calibration curve 92-027-006
//from -30C-180C in steps of 10C, the list is in 12Bit Digital Reading when supplyed with 5V and a 200Ohm Resistor in series
//(measuring the Voltage on the Sensor)
//it has a decreasing Resistance with the Temperature
const unsigned int tempVDOTemp[] PROGMEM =
{
4053,
4019,
3957,
3857,
3706,
3497,
3224,
2893,
2527,
2150,
1790,
1471,
1200,
968,
782,
632,
515,
422,
348,
287,
238,
199
};
/*==============================================================================
* SETUP()
*============================================================================*/
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(S1Pin, INPUT); // sets input pin
pinMode(S2Pin, INPUT); // sets input pin
pinMode(S3Pin, INPUT); // sets input pin
pinMode(S4Pin, INPUT); // sets input pin
}
/*==============================================================================
* LOOP()
*============================================================================*/
void loop()
//Converts the ADW Reading into °C
int GetVDOTemp(int ADWreading)
{
int LookedupValue;
//This searches the 2 surrounding values, and then linear interpolates between them.
for(int i = 0; i<22;i++)
{
if(ADWreading <= pgm_read_word(&tempVDOTemp[i]) && ADWreading >= pgm_read_word(&tempVDOTemp[i+1]))
{
LookedupValue = (i*10) + 10 - ((10L *(ADWreading - pgm_read_word(&tempVDOTemp[i+1]))) / ((pgm_read_word(&tempVDOTemp[i]) - pgm_read_word(&tempVDOTemp[i+1]))));
break;
}
}
LookedupValue -= 30; //must be reduced as the lookup table starts at -30°C.
LookedupValue = constrain(LookedupValue,-40,999); //Limits the Output to 999°C, so an open circuit gets detectet!
return LookedupValue;
}
{
s1 = digitalRead(S1Pin); // read input pin
s2 = digitalRead(S1Pin); // read input pin
s3 = digitalRead(S1Pin); // read input pin
s4 = digitalRead(S1Pin); // read input pin
tempval = analogRead(TempSensorPin); // read analog input
if (s4 = HIGH)
{
fanval = 0;
}
else
{
if (s3 = HIGH)
{
fanval = 100;
}
else
{
if (s1 == HIGH || s2 == HIGH)
{
if (tempval > 92)
{
fanval = 100;
}
else if (tempval > 87)
{
fanval = 80;
}
else if (tempval > 84)
{
fanval = 60;
}
else
{
fanval = 20;
}
}
else
{
if (tempval > 92)
{
fanval = 100;
}
else if (tempval > 87)
{
fanval = 60;
}
else if (tempval > 84)
{
fanval = 30;
}
else
{
fanval = 0;
}
}
}
}
Low_PWM(13,10,fanval); //erster Wert AusgangsPin, Base Frequenz, Ontime 0-100%
}
void Low_PWM (int ledpin, int Fre, int Value){
long time;
long ontime;
time=1000000/Fre;
ontime=time/100*Value;
if (micros() - pmicros > time && nextCall==HIGH) {
digitalWrite(ledpin,HIGH);
pmicros=micros();
nextCall=LOW;
}
if (micros() - pmicros > ontime&& nextCall==LOW){
digitalWrite(ledpin,LOW);
nextCall=HIGH;
}
}