I tried using this code to output AC power from one H-bridge and then another, switching every second, but when I connected a motor to it, it just seemed to output direct current. This is the code I was using (by the way, the motor controller I'm using has a max frequency of 20 kHz, so that's not the problem as far as I know):
int EnablePin = 8;
int duty;
int PWMPinA;
int PWMPinB;
const byte CPin = 0; // analog input channel
int CRaw; // raw A/D value
float CVal; // adjusted Amps value
void setup() {
pinMode(EnablePin, OUTPUT);
pinMode(PWMPinA, OUTPUT);
pinMode(PWMPinB, OUTPUT);
}
void loop() {
digitalWrite(EnablePin, HIGH);
for(duty = 0; duty <= 20000; duty += 1){
PWMPinA=11; // Timer2
PWMPinB=3;
analogWrite(PWMPinA, 255);
analogWrite(PWMPinB, 0);
delayMicroseconds(50);
if(PWMPinA == 11) {
PWMPinA = 3;
PWMPinB = 11;
} else {
PWMPinA = 11;
PWMPinB = 3;
}
}
for(duty = 20000; duty>=0; duty -= 1){
PWMPinA=6; // Timer2
PWMPinB=5;
analogWrite(PWMPinA, 255);
analogWrite(PWMPinB, 0);
delayMicroseconds(50);
if(PWMPinA == 6) {
PWMPinA = 5;
PWMPinB = 6;
} else {
PWMPinA = 6;
PWMPinB = 5;
}
}
}