Hi, following by my spot weld machine base on Arduino, I got stuck and need your help again.
First of all, I want to trigger the solid-state-relay to turn on a power transformer, and the SSR is only turn on at zero crossing, and I need the exact time set for each pulse.
Therefore, I'm thinking about using interrupt on pin 2 Arduino to detect zero and turn-on time for SSR right at the zero to eliminate delay between zero and time of pushing the button. However, it doesn't work as I expected. With the time set less than 10ms, the trigger for SSR is not stable working, sometimes it triggers the transformer but sometimes it does not (it act as the same way before I'm using interrupt)
So could you please tell me that I'm thinking in the wrong way or the zero isn't working as I expected
in my country, using 50hz and 230VAC line, so each half-circle is 10ms
for wiring, pin 2 I follow bristolwatch but the 2.2k resistor I replaced with 1k. The output from pin 2 is exactly as described in bristolwatch website
pin 5 for triggering
here is my code, I removed some irrelevant code to make it clear
Thank so much for reading my issue
//
//
//
//
//
//--------------------------------------------------------------------------------------
// INCLUDES
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// DEFINES
//--------------------------------------------------------------------------------------
#define timerPin 12
//--------------------------------------------------------------------------------------
// VARIABLES
//--------------------------------------------------------------------------------------
int controlValue;
int timerValue;
volatile float j;
int period = 500;
unsigned long time_now = 0;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
//--------------------------------------------------------------------------------------
// MAIN PROGRAM
//--------------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600);
pinMode(5, INPUT_PULLUP); // set D5 as input of pedal
pinMode(2, INPUT);
pinMode(timerPin, OUTPUT);
digitalWrite(timerPin, LOW);
}
void loop()
{
int Switch = digitalRead(5);
int Switch1 = digitalRead(3);
// check if the pushbutton is pressed. If it is, the buttonState is LOW:
if (Switch == LOW) {
attachInterrupt(0, trig, CHANGE);
}
void trig() {
delayMicroseconds(9900);
digitalWrite(13, HIGH);
digitalWrite(timerPin, HIGH);
delayMicroseconds(j * 1000); // weld time
digitalWrite(timerPin, LOW);
digitalWrite(13, LOW);
detachInterrupt(0);
}