expected ';' before '{' token compiling error

Hello Everyone,
New member here. Not new to Arduino, ( I've build two table top CNC milling machines using Arduino Unos), but new to programming them. Trying to build a TIG welder pulse control for a welder friend of mine. Saw this Youtube video, and decided to give it a try.[Build a TIG welder pulser add-on for $10. Cheap and Easy. - YouTube. The guy who posted it didn't have a link to his code, so I copied it off the screen. It did not run, didn't recognize his potentiometer declarations. After several tries at trying to get it to work, I decided to do some research, and re-write the code. Spent many hours this weekend, and I am stuck at the error mentioned in the subject box. As far as I can see, have have all the semi-colons in the right places. What am I not seeing? Thanks in advance for any help you can give me.

Fred
P.S. The error occurs at line #34. P.P.S If my code is ridiculously wrong, I apologize. I don't mind putting
my ignorance on display in the pursuit of knowledge. :slight_smile:

[
int potD = A0; // Duty Cycle Pot
int PWM_DutyCycle=0;
int PWM_DutyCycle_Pin=A0;
int t1 = 0;
int t2 = 0;
int potP = A1; // Period Cycle Pot
int PWM_Period=512; //period in milliseconds
int PWM_Period_Pin=A1;
int t3 = 0;
int t4 = 0;
int PWM_PeriodScale=4;
int PWM_DutyScale=4;
int PWM_Out_Pin=9; //31250 base frequency (Timer1)
bool SimpleMode = 1; // Note: Other mode is not implemented
int ADC1Vals[] = {0,0,0};
int ADC2Vals[] = {0,0,0};
unsigned long HighTime = 1;
unsigned long LowTime = 0;

void setup()
{
pinMode(potD, OUTPUT);
pinMode(potP, OUTPUT);
}
void loop()
{
t2= analogRead(A0); //ReadPotD
t1= (PWM_DutyCyclePWM_DutyScale); //Hightime
t4= analogRead(A1); //ReadPotP
t3= (PWM_Period
PWM_PeriodScale); // Lowtime
digitalWrite(PWM_Out_Pin, HIGH);
delayMicroseconds{t1};
delayMicroseconds{t3};

t2= analogRead(A0); //ReadPotD
t1= (PWM_DutyCyclePWM_DutyScale); //Hightime
t4= analogRead(A1); //ReadPotP
t3= (PWM_Period
PWM_PeriodScale); // Lowtime
digitalWrite(PWM_Out_Pin, LOW);
delayMicroseconds(t2);
delayMicroseconds(t4);
}

delayMicroseconds{t1};

Curly brackets for a function call?

Ignoring the use of curly brackets for the moment, this code has other problems that the compiler will not complain about:

void loop()
{
t2= analogRead(A0);  //ReadPotD
t1= (PWM_DutyCycle*PWM_DutyScale);  //Hightime
t4= analogRead(A1);  //ReadPotP
t3= (PWM_Period*PWM_PeriodScale);  // Lowtime
digitalWrite(PWM_Out_Pin, HIGH);
delayMicroseconds{t1};
delayMicroseconds{t3};

t2= analogRead(A0);  //ReadPotD
t1= (PWM_DutyCycle*PWM_DutyScale);  //Hightime
t4= analogRead(A1);  //ReadPotP
t3= (PWM_Period*PWM_PeriodScale);  // Lowtime
digitalWrite(PWM_Out_Pin, LOW);
delayMicroseconds(t2);
delayMicroseconds(t4);
}

t2 and t4 are set twice but only the second setting is used.
t1 and t3 are set twice but only the first setting is used.
There are variables defined for potD (or PWM_DutyCycle_Pin) and potP (or PWM_Period_Pin) but A0 and A1 (and comments) are used instead.
It would save program space to use const in many of the variable definitions.

Good Luck!

Thanks for your input. I am working on the points that you mentioned, and will also remove any redundant and/or unneeded code.

delayMicroseconds{t1};
delayMicroseconds{t3};

Use parens ( ) instead of curlys { }

delayMicroseconds(t1);
delayMicroseconds(t3);

Also note that:

delayMicroseconds(t1);
delayMicroseconds(t3);

is basically the same as saying delayMicroseconds(t1+t3);

O.K., Progress! Re-wrote program per members suggestions, and it now compiles with no errors. At this point it seems to be working as planned. I will know for sure after some more bench testing. I am now in the process of tweaking the calculations so that the outputs fall into the desired parameters. New code is listed with this post. Thanks again for everyone's help thus far. If anything in the new program doesn't seem correct, please comment. I will post an update soon.
Fred

const int PWM_DutyCycle_Pin=A0;  // Duty Cycle Pot on A0
const int PWM_Period_Pin=A1; // Period Cycle Pot A1
const int PWM_Out_Pin = 9;  //31250 base frequency 
bool SimpleMode = 1;  // Note: Other mode is not implemented

int PWM_DutyCycle=0;
int PWM_Period=512; //period in milliseconds

int PWM_PeriodScale=4;
int PWM_DutyScale=4;

int ADC1Vals[] = {0,0,0};
int ADC2Vals[] = {0,0,0};

void setup(){

pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
}

void loop(){
  
unsigned long HighTime = 1; 
unsigned long LowTime = 0;

analogRead(A0);  //ReadPotD
analogRead(A1);  //ReadPotP
HighTime - (PWM_DutyCycle*PWM_DutyScale);  //Hightime
LowTime = (PWM_Period*PWM_PeriodScale);  // Lowtime

   // Turn pin on
digitalWrite(PWM_Out_Pin, HIGH);
delay(HighTime);


analogRead(A0);  //ReadPotD
analogRead(A1);  //ReadPotP
HighTime = (PWM_DutyCycle*PWM_DutyScale);  //Hightime
LowTime = (PWM_Period*PWM_PeriodScale);  // Lowtime

   // Turn pin off
digitalWrite(PWM_Out_Pin, LOW);
delay(LowTime);
}
void setup(){

pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
}

void loop(){
 
analogRead(A0);  //ReadPotD
analogRead(A1);  //ReadPotP

Novel.
Make a pin an output, and then read it, but throw away the value.

HighTime - (PWM_DutyCycle*PWM_DutyScale);  //Hightime
LowTime = (PWM_Period*PWM_PeriodScale);  // Lowtime

Did you mean to write "HighTime ="?

Oops. Yes I did. :slight_smile:

"Novel.
Make a pin an output, and then read it, but throw away the value."

Closer? ;D

const int PWM_DutyCycle_Pin=A0;  // Duty Cycle Pot on A0
const int PWM_Period_Pin=A1; // Period Cycle Pot A1
const int PWM_Out_Pin = 9;  //31250 base frequency 
bool SimpleMode = 1;  // Note: Other mode is not implemented

int PWM_DutyCycle=0;
int PWM_Period=512; //period in milliseconds
int readValueD; 
int readValueP; 

int HighTime; 
int LowTime; 

int PWM_PeriodScale=4;
int PWM_DutyScale=4;

int ADC1Vals[] = {0,0,0};
int ADC2Vals[] = {0,0,0};

void setup(){

pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
}

void loop(){
 
unsigned long HighTime = 1; 
unsigned long LowTime = 0;

readValueD = analogRead(A0);  //ReadPotD
HighTime = (readValueD*PWM_DutyScale);  //Hightime //Calculate  
analogWrite(PWM_Out_Pin,HighTime);

readValueP = analogRead(A1);  //ReadPotP 
LowTime = (readValueP*PWM_PeriodScale);  // Lowtime
analogWrite(PWM_Out_Pin,LowTime);

   // Turn pin on
digitalWrite(PWM_Out_Pin, HIGH);
delay (HighTime);


readValueD = analogRead(A0);  //ReadPotD
HighTime = (readValueD*PWM_DutyScale);   //Calculate  
analogWrite(PWM_Out_Pin,HighTime);

readValueP = analogRead(A1);  //ReadPotP 
LowTime = (readValueP*PWM_PeriodScale);  // Lowtime
analogWrite(PWM_Out_Pin,LowTime);

   // Turn pin off
digitalWrite(PWM_Out_Pin, LOW);
delay (LowTime);

}

Better, but why make A0 and A1 digital outputs and then read them as analog inputs?

I could hand you the code but I sense that you can do this yourself.

Closer, but still a lot of redundant or useless code. You can throw out all but:

void loop(){
  unsigned long HighTime, LowTime;

  readValueD = analogRead(A0);  //ReadPotD
  HighTime = (readValueD*PWM_DutyScale);  //Hightime //Calculate  
   // Turn pin on
  digitalWrite(PWM_Out_Pin, HIGH);
  delay (HighTime);

  readValueP = analogRead(A1);  //ReadPotP 
  LowTime = (readValueP*PWM_PeriodScale);  // Lowtime
   // Turn pin off
  digitalWrite(PWM_Out_Pin, LOW);
  delay (LowTime);
}

And that can all be reduced to:

void loop(){
   // Turn pin on
  digitalWrite(PWM_Out_Pin, HIGH);
  delay (analogRead(A0) * PWM_DutyScale);

   // Turn pin off
  digitalWrite(PWM_Out_Pin, LOW);
  delay(analogRead(A1) * PWM_DutyScale);
}

Hey Everyone,
This is the latest version of my program. It seems to do everything that I was looking to do, change pulse frequency and current. It is probably longer than it needs to be ( redundant and unneeded code and such), but I will eventually learn how to streamline my programs. Thanks you to everyone for their input. Don't now if any of you had a chance to view the video that I posted a link to in my original post. It would clarify what I was looking to achieve. Also if you do watch it, please comment on his program. I looks like it there is no way it would run. It didn't when I tried it. Here is a link to my DropBox that shows the circuit in operation.
Dropbox - TIG Pulser.mp4 - Simplify your life Thanks again.

Fred

 const int PWM_DutyCycle_Pin=A2;  // Duty Cycle Pot on A0
 const int PWM_Period_Pin=A3; // Period Cycle Pot A1
 const int PWM_Out_Pin = 9;  //31250 base frequency 
 const int PWM_Low_Pin = 2;
 const int PWM_High_Pin = 11;
  

bool SimpleMode = 1;  // Note: Other mode is not implemented

int PWM_DutyCycle=0;
int PWM_Period=128; //Period in milliseconds
int readValueD;     // Value of Delay Cycle Pot
int readValueP;     // Value of Period Cycle Pot

int HighTime; 
int LowTime; 

int PWM_PeriodScale=4;
int PWM_DutyScale=4;

int ADC1Vals[] = {0,0,0};
int ADC2Vals[] = {0,0,0};

void setup(){

pinMode(2, OUTPUT);  // Green LED-Pulse On - for visual reference
pinMode(11, OUTPUT);  // Blue LED-Pulse Off - for visual reference

}

void loop(){

  
unsigned long HighTime = 1; 
unsigned long LowTime = 0;

readValueD = analogRead(A2);  //ReadPotD
HighTime = (readValueD*PWM_DutyScale);  //Calculate HightimeD   
digitalWrite(PWM_Out_Pin,HighTime);

readValueP = analogRead(A3);  //ReadPotP 
LowTime = (readValueP*PWM_PeriodScale);  // Lowtime
digitalWrite(PWM_Out_Pin,LowTime);

   // Turn pin on
digitalWrite(PWM_Out_Pin, HIGH);
digitalWrite(PWM_Low_Pin, LOW);
digitalWrite(PWM_High_Pin, HIGH);
delay (HighTime);


readValueD = analogRead(A2);  //ReadPotD
HighTime = (readValueD*PWM_DutyScale);   //Calculate  
digitalWrite(PWM_Out_Pin,HighTime);

readValueP = analogRead(A3);  //ReadPotP 
LowTime = (readValueP*PWM_PeriodScale);  // Lowtime
digitalWrite(PWM_Out_Pin,LowTime);

   // Turn pin off
digitalWrite(PWM_Out_Pin, LOW);
digitalWrite(PWM_Low_Pin, HIGH);
digitalWrite(PWM_High_Pin, LOW);
delay (LowTime);

}