Ahmet
S38>S85
- Katılım
- 31 Mayıs 2021
- Mesajlar
- 6,081
OP-AMP;
MOSFET SURUCU;
MOSFET SURUCU;
C:
float adc = 0.0;
const float cpu_v = 3.30;
const int max_adc = 4096;
float adc_v = 0.0;
float c = 0.0;
const int numReadings = 25;
int readings[numReadings];
int readIndex = 0;
int total = 0;
float average = 0;
long adcValue = 0;
int n = 25;
void setup() {
Serial.begin(115200);
analogReadResolution(12);
pinMode(A0, INPUT);
analogWriteResolution(16);
pinMode(0, OUTPUT_8MA);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
}
void loop() {
if(digitalRead(0) == LOW){
total = total - readings[readIndex];
readings[readIndex] = analogRead(A0);
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
}
average = total / numReadings;
adc_v = average * (cpu_v / max_adc);
c = adc_v * 248, 32;
c = c - 7,6;//KALBRASYON -
c = c + 0; //KALIBRASYON +
for(int i=0;i<n;i++)
adcValue = adcValue + c;
adcValue = adcValue / n;
adcValue = adcValue - 10;
Serial.println(adcValue);
}
if(c > 107){
c = c - 9;
}
if(c > 240){
c = c - 4;
}
if(c > 288){
c = c - 5;
}
PID(255);
}
float mn = 0; //MIN PWM COUNT
float mx = 54125;//MAX PWM COUNT
float lTime = 0;
float errSum = 0;
float lErr = 0;
float Kp = 70;//P
float Ki = 12;//I
float Kd = 66;//D
void PID(float setTemp) {
unsigned long now = millis();
int32_t timeChange = (int32_t)(now - lTime);
float error = setTemp - adcValue;
errSum += error * timeChange;
errSum = constrain(errSum, mn * 1.1, mx * 1.1);
float dErr = (error - lErr) / timeChange;
float newOutput = (Kp * error + Ki * errSum + Kd * dErr);
float output = constrain(newOutput, mn, mx);
analogWriteFreq(100);
analogWrite(0, output);
Son düzenleme: