1

I am working on building a pure sine wave inverter using an Arduino Uno to output two PWM signals for the top and bottom half of the wave. Currently I am outputting pre-calculated values with an interrupt as PWM. This seems to be working but I was wondering if anyone had any feedback on my design, and whether there is a better way to go about doing this. I will also need to incorporate feedback into this to vary the max PWM duty cycle, and I am worried the ATMEGA will not be able to keep up do this fast enough.

Please let me know if you want any more details, thanks in advance!

Olls

The spreadsheet I'm using to calculate the values.

#include "TimerOne.h"

int duty_cycle;
int x = 0;

// sin_table is made up of sin(0-400) values multiplied by PWM_PERIOD
// https://docs.google.com/spreadsheets/d/1iyveHnOxIzqg907T6pu4znsJE-6tg40juMihDvU8Tbg/edit?usp=sharing
uint8_t _sin[] = { // Calculated for 50Hz at 200 pulses per half wave.
    0,0,0,1,1,1,2,2,3,3,3,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,9,10,10,10,11,11,12,12,12,13,13,13,14,14,14,15,15,15,15,16,16,16,17,17,17,17,18,18,18,19,19,19,19,19,20,20,20,20,21,21,21,21,21,22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,20,20,20,20,19,19,19,19,19,18,18,18,17,17,17,17,16,16,16,15,15,15,15,14,14,14,13,13,13,12,12,12,11,11,10,10,10,9,9,9,8,8,8,7,7,6,6,6,5,5,5,4,4,3,3,3,2,2,1,1,1,0,0,0,0,0,1,1,1,2,2,3,3,3,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,9,10,10,10,11,11,12,12,12,13,13,13,14,14,14,15,15,15,15,16,16,16,17,17,17,17,18,18,18,19,19,19,19,19,20,20,20,20,21,21,21,21,21,22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,20,20,20,20,19,19,19,19,19,18,18,18,17,17,17,17,16,16,16,15,15,15,15,14,14,14,13,13,13,12,12,12,11,11,10,10,10,9,9,9,8,8,8,7,7,6,6,6,5,5,5,4,4,3,3,3,2,2,1,1,1,0,0,0
};

void setup() {
    // Pin mode, and set low.
    DDRD = DDRD | B00011000;
    PORTD = B00000000;

    Timer1.initialize(47);
    Timer1.attachInterrupt(pwm);
}

void pwm() {
    if (PIND & B00000100) { // Inhibit switch

        // Lower half or upper half of wave, start PWM pulse
        if (x > 200) {
            PORTD = B00010000;
        } else {
            PORTD = B00001000;
        }

        duty_cycle = _sin[x];
        if (duty_cycle > 3) {
            delayMicroseconds(duty_cycle);
        }

        PORTD = B00000000;

        x++;
        if (x > 400) {
            x = 0;
        }
    }
}

void loop() {}
  • Why not use one timer to do the PWM on the pins, and a second (slower) timer to change the duty cycle to match the sine wave. That way you also don't need to change the code to have a different frequency. You'd probably also need to add a RC filter to the output pins, and maybe a voltage follower to get a consistent output, no matter how much current you are drawing. – Gerben Sep 11 '14 at 17:55
  • Did the circuit work correctly ?Can you share the schematic ? – user7895 Mar 14 '15 at 17:09
  • I did get it working. The schematic isn't mine to share unfortunately, but it consisted of some transistors to shift the PWM up to 20v, which then went into an inverter circuit (not made by me, quite complex) which merged the two PWM signals together into a AC signal. Then there was a transformer and RC filter to smooth out and amplify the PWM. Sorry I can't be more help, but it was a while ago, and I didn't make all of it. – olls Mar 16 '15 at 22:30
  • arduino.stackexchange.com/questions/23842/… points to an article with some circuitry. – Dave X Jun 4 '16 at 1:31
1

Comment by olls converted to an answer:

I did get it working. The schematic isn't mine to share unfortunately, but it consisted of some transistors to shift the PWM up to 20v, which then went into an inverter circuit (not made by me, quite complex) which merged the two PWM signals together into a AC signal. Then there was a transformer and RC filter to smooth out and amplify the PWM. Sorry I can't be more help, but it was a while ago, and I didn't make all of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.