I build on bread board the attached schematic and I uploaded the attached code to an Arduino Uno.
I tested each part of the schematic (the pot, the OpAmp, the zero crossing detector, the optotriac) and they are working.
The problem is that when I start the circuit I got the attached screenshot from the oscilloscope, and if I rotate the pot, then nothing happens. Also, the heating of the soldering iron does not stop.
What should I do ? I tried different types of modifications in code, for example making some variables from int to long or from long to int, reading in the zero crossing function the value of the pot.
I tested each part of the schematic (the pot, the OpAmp, the zero crossing detector, the optotriac) and they are working.
The problem is that when I start the circuit I got the attached screenshot from the oscilloscope, and if I rotate the pot, then nothing happens. Also, the heating of the soldering iron does not stop.
What should I do ? I tried different types of modifications in code, for example making some variables from int to long or from long to int, reading in the zero crossing function the value of the pot.
C:
#include <PID_v1.h>
int firing_triac = 1; // OUTPUT TO CONTROL TRIAC
int zero_in = 2; // INPUT FROM ZERO DETECTION
double value_zero = 0;
int pot_pin = A1;
int temperature = 0;
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
double lastupdate;
double newSetpointPot;
double newSetpoint;
double consKp = 1, consKi = 0.05, consKd = 0.25;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);
void setup()
{
myPID.SetOutputLimits(0, 220);
myPID.SetMode(AUTOMATIC);
lastupdate = millis();
Setpoint = 0;
pinMode(firing_triac, OUTPUT); // Set the AC Load as output
pinMode(zero_in, INPUT);
digitalWrite(zero_in, HIGH); // pull up
attachInterrupt(0, zero_crosss_int, RISING);
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
int dimtime = (40*Output);
delayMicroseconds(dimtime); // Off cycle
digitalWrite(firing_triac, HIGH); // triac firing
delayMicroseconds(10); // triac On propagation delay
digitalWrite(firing_triac, LOW); // triac Off
}
void loop()
{
Input = 0;
for(int i=0;i<50;i++)
Input += analogRead(A0);
Input /= 50;
Input = map(Input, 0, 550, 25, 400);
temperature = Input;
newSetpointPot = analogRead(pot_pin);
newSetpoint = map(newSetpointPot, 0, 1023, 150, 400);
//Display setpoint
if (abs(newSetpoint - Setpoint) > 3) {
Setpoint = newSetpoint;
temperature = newSetpoint;
lastupdate = millis();
}
myPID.SetTunings(consKp, consKi, consKd);
noInterrupts();
myPID.Compute();
interrupts();
//delay(1000);
}
Attachments
-
72.8 KB Views: 36
-
33.4 KB Views: 30