Three Phase SCR scalable firing angle

Hi all,

I am new to arduino coding, only started learning about a few weeks ago and I'm a little stuck. I created this code for my engineering capstone project. Essentially we are building a controlled rectifier circuit (SCRs) with a scalable firing angle using a potentiometer.

Overall, the code seems to be relatively working, however when the firing angle swaps from 0-90 degrees to 90-180 degrees, there seems to be a little skip of about ~1500-1750us. I'm unsure if its processing time of the analog read or the scaling of the float value (gateDelay), or something I'm not seeing.

Any suggestions or hints in the right direction would be greatly appreciated, I'll be sure to pay it forward in the future.

Thanks for taking the time!

int pulseState = 0;
float gateDelay = 0;
int potPin = A0;

void setup()
{
pinMode(2, INPUT);
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);
}

void loop()
{
pulseState = digitalRead(2);

analogRead(potPin);
gateDelay = analogRead(potPin)*8333.333/1023.0;

if (pulseState == HIGH) {        
  
  if (gateDelay <= 4166.6666) {	     //If gate delay is less than 90 degrees, there 
    delayMicroseconds(gateDelay);  //is no overlap between the third SCR pulse and
  							    //the ZCD trigger pulse, therefore the gate pulse
 digitalWrite(13, HIGH);                 //sequence is ABC.
 delayMicroseconds(900); 
 digitalWrite(13, LOW);
 delayMicroseconds(4655.55);
  
	digitalWrite(12, HIGH);
  delayMicroseconds(900);
  digitalWrite(12, LOW);
 delayMicroseconds(4655.55);
  
	digitalWrite(8, HIGH);
  delayMicroseconds(900);
	digitalWrite(8, LOW); 

  } else {
     
    delayMicroseconds(gateDelay - 4166.67);
  							//When the gate delay is beyond 90 degrees, an
 digitalWrite(8, HIGH);		        //overlap between ZCD trigger and pulse C occurs.
 delayMicroseconds(900); 	        //Therefore, the sequence must be shifted to CAB
  digitalWrite(8, LOW);		        //to allow process timing to execute properly.
 delayMicroseconds(4655.55);
  
	digitalWrite(13, HIGH);
  delayMicroseconds(900);
  digitalWrite(13, LOW);
 delayMicroseconds(4655.55);
  
	digitalWrite(12, HIGH);
  delayMicroseconds(900);
	digitalWrite(12, LOW); 
     
   }
}else{
  digitalWrite(13, LOW);		
  digitalWrite(12, LOW);		
  digitalWrite(8, LOW);			
}  

}

www.arduino.cc/en/Reference/DelayMicroseconds.html

No Decimals.

1 Like