Help, someone who has an oscilloscope and is willing to help me review my proyect
I worked on making Ac from an Arduino (to later drive MOSFETs and at the end a bigger proyect), I built a code that makes a 50khz pwm signal rise and fall to the proportions of a sine wave at 60 hz, but I don't know if my protect works as intended or not, since I do not own an ociloscope, I cannot see what is going on at the actual terminals, I would really appreciate someone who owns both, an Arduino uno, and an ociloscope to help me see if it works, and if not, to tell me why not (and if they take the time to fix it I wouldn't mind).
If it does what i believe it does, it should make a 50khz PWM signal of 5 volts go up and down 60 times per second (first on pin 9, and then on pin 10), that when connected the way it is intended, should show a 0-5v signal rise, then 5-0v signal fall, then 0-(-5)v fall, then a -5-0v rise in the span of almost 1/60 of a second, the rise and fall follows the rise and fall of a sine wave closely, although not exact, it is very close.
What I want to check with an oscilloscope is that it indeed is a 60 ish hz signal, that the pins 9 and 10 never have voltaje at the same time, and that the 50khz PWM signal is indeed working as intended. Any help is apreciated, the code I built is bellow. Also, anything the more skilled programmers see that I am missing/did wrong, I would really apreciate the feedback to see what I did, and where to improve (I am aware my code could use some optimizing, but for now, as long as it works, I am fine with it).
int Time;
int Reverse;
int NTime;
void setup() {
// put your setup code here, to run once:
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
TCCR1A = 0;
TCCR1B = 0;
TCCR1A |= (1 << WGM11);
TCCR1B |= (1 << WGM12) | (1 << WGM13);
TCCR1A &= ~(1 << COM1A1);
TCCR1A &= ~(1 << COM1B1);
TCCR1B |= (1 << CS10);
ICR1 = 319;
Time = 0;
NTime = 0;
Reverse = 0;
TCCR2A = 0;
TCCR2B = 0;
TCCR2A |= (1 << WGM21);
TCCR2B |= (1 << CS21) | (1 << CS20);
TIMSK2 |= (1 << OCIE2A);
OCR2A = 26;
TCNT2 = 0;
sei();
}
void loop() {
// put your main code here, to run repeatedly:
}
ISR(TIMER2_COMPA_vect)
{
OCR1A = Time;
OCR1B = NTime;
if(Reverse == 0)
{
if(Time < 160)
{
Time += 6;
} else if(Time < 222){
Time += 5;
} else if(Time < 267){
Time += 4;
} else if(Time < 292){
Time += 3;
} else if(Time < 310){
Time += 2;
} else {
Time += 1;
}
} else if(Reverse == 1){
if(Time > 310){
Time -= 1;
} else if(Time > 292){
Time -= 2;
} else if (Time > 267){
Time -= 3;
} else if (Time > 222){
Time -= 4;
} else if (Time > 160){
Time -= 5;
} else if (Time <= 160){
Time -=6;
}
} else if(Reverse == 2){
if(NTime < 160)
{
NTime += 6;
} else if(NTime < 222){
NTime += 5;
} else if(NTime < 267){
NTime += 4;
} else if(NTime < 292){
NTime += 3;
} else if(NTime < 310){
NTime += 2;
} else {
NTime += 1;
}
} else if (Reverse == 3){
if(NTime > 310){
NTime -= 1;
} else if(NTime > 292){
NTime -= 2;
} else if (NTime > 267){
NTime -= 3;
} else if (NTime > 222){
NTime -= 4;
} else if (NTime > 160){
NTime -= 5;
} else if (NTime <= 160){
NTime -=6;
}
}
if(Time >= 320)
{
Reverse = 1;
} else if(Time <= -1){
Reverse = 2;
Time = 0;
TCCR1A &= ~(1 << COM1A1);
PORTB &= ~B00000010; //This equal digitalWrite(9, LOW)
TCCR1A |= (1 << COM1B1);
} else if(NTime >= 320){
Reverse = 3;
} else if(NTime <= -1){
Reverse = 0;
NTime = 0;
TCCR1A &= ~(1 << COM1B1);
PORTB &= ~B00000100; //This equal digitalWrite(10, LOW)
TCCR1A |= (1 << COM1A1);
}
}