The sample code is this:
Sample code for Edgar Bonet
Thank for everything. This is my new circuit for Arduino input. Considerably improved in the coupling of impedancesI have questions.
I must clarify certain things, my proyect is an Cosine-Mode Controller for SCR Converters, look the referense paper IEEE.
I need to integrate the analog sine wave of 60Hz, this signal described in the next picture, The op.amp isolates the mid-point voltage at the junction of R3 & R4 from the AC-AC adapter and voltage divider. This significantly reduces the impedance of the voltage source, resulting in enhanced performance.
Addingadding an offset near 2.5v, because I can damage the Arduino board with the negative signal cycle. Internally on the Arduino board, I remove this offset, multiplying by 2, and subtracting 1.
Vac_input=analogReadV1=analogRead(A0)*2/1023.0-1.0;
The sampling period must be at least fs=300hz, T=1/fs and V1 is the signal I need integrate.
And this is my oldWhat modifications can I make to Edgar Bonet's code,
unsigned long time1=0.0;
float Vac_input,Vb_integral,Valpha,Vc,Vd,Ve,Vf;
const float Vpeak_detector=1;
const float deltaT=0.1;
const float T=1.0e6/60.0;
float Vb_last;
int time2=0,time3=0;
void setup() {
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}
void loop() {
deltaT=(micros()-time1);
time1=micros();
//Vac_input=sin(2*3.1416/T*micros()); //Asuming the sine wave
Vac_input=analogRead(A0)*2.0/1023.0-1.0; //Analog input
//Vb_integral=cos(2*3.1416/T*micros()); // Asuming the integral
Vb_integral=(deltaT/1.0e6*Vac_input*377.0+Vb_last);
Vpeak_detector=1;// peak detector [P.D]
Vc=Vpeak_detector+Vb_integral;
Vd=Vpeak_detectord-Vb_integral;
Valpha=analogRead(A1)/1023.0*2; // control variable Valpha(potenciometer)
Vb_last=Vb_integral;
if (Vc>Valpha){
Ve=0;}else{Ve=1;time2=micros();}
if (Vd>Valpha){
Vf=0;}else{Vf=1;time3=micros();}
if (Ve==Vf){if(time2>time3){Ve=0;digitalWrite(13,LOW);Vf=1;digitalWrite(12,HIGH);}else{Ve=1;digitalWrite(13,HIGH);Vf=0;digitalWrite(12,LOW);}}else{
if(Ve==1){digitalWrite(13,HIGH);}else{digitalWrite(13,LOW);};
if(Vf==1){digitalWrite(12,HIGH);}else{digitalWrite(12,LOW);}}
}
References
link of paper IEEE http://www.mediafire.com/file/nomyxva2w90dau2/Paper+IEEE.pdf?
Thank you very much. Thank you very much.

