# Programing for pure sine wave inverter

**URL:** <https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162>\
**Category:** Programming\
**Created:** [September 2, 2025, 6:48pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162 "2025-09-02T18:48:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 2, 2025, 6:48pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/1 "2025-09-02T18:48:07Z")

</div>

Need to generate two complementery spwm with carrier frequency of 25khz and modulation frequency of 50hz also two pwm such that one pwm is active during positive half cycle on second is active during negative half cycle there is also some dead time between the two spwm.  
Also the spwm is a function of analog input that to read the Dc voltage to regulate the output voltage. By using esp32\_wroom32

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [September 2, 2025, 6:50pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/2 "2025-09-02T18:50:16Z")

</div>

Thanks for letting us know. Sounds like a challenging project. Do you have a question?

---

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 2, 2025, 7:00pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/3 "2025-09-02T19:00:17Z")

</div>

What about the project can you do it

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [September 2, 2025, 7:17pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/4 "2025-09-02T19:17:04Z")

</div>

on what hardware?

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [September 2, 2025, 7:26pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/5 "2025-09-02T19:26:14Z")

</div>

> [@ziaullah999](#):
>
> and modulation frequency of 50hz

What percent of modulation does your project require? And is it amplitude modulation, frequency modulation or phase modulation?

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [September 2, 2025, 7:51pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/6 "2025-09-02T19:51:28Z")

</div>

> [@ziaullah999](#):
>
> What about the project can you do it

No, it's your project. Post the code you have along with schematics, along with information requested by @gcjr and @Paul_KD7HB.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 2, 2025, 8:16pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/7 "2025-09-02T20:16:38Z")

</div>

is the spwm 25kHz carrier a triangular wave?  
use a [AD9833\_DDS\_Waveform\_Generator](https://www.analog.com/en/products/ad9833.html) to generate the triangular wave modulate it using a digital potentiometer?

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [September 2, 2025, 8:53pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/8 "2025-09-02T20:53:27Z")

</div>

i had never heard of [SPWM](https://www.google.com/search?q=spwm&rlz=1C1CHBF_enUS802US802&oq=spwm&gs_lcrp=EgZjaHJvbWUqDggAEEUYJxg7GIAEGIoFMg4IABBFGCcYOxiABBiKBTIHCAEQABiABDIJCAIQABgKGIAEMgcIAxAAGIAEMgcIBBAAGIAEMgYIBRBFGDwyBggGEEUYPDIGCAcQRRg80gEIMTgzMmowajeoAgCwAgA&sourceid=chrome&ie=UTF-8#vhid=JtTIDhwAWpSpTM&vssid=_6VS3aO7aIb3Y5NoP48mEuA8_38)

a google search provide the image below which looks like a PWM added to a 4-level (-2, -1, 0, 1) base analog level. Another image and description desribed it as PWM signal added to a sinusoidal power line voltage. It would be interesting to learn more

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/a/d/f/adfa3b27cc121054f487a8af341ac40cfa183dc6.jpeg)

> [@ziaullah999](#):
>
> carrier frequency of 25khz and modulation frequency of 50hz also two pwm such that one pwm is active during positive half cycle on second is active during negative half cycle

it's not clear to me what the OP is describing. Is it a 25 kHz sinusoid on top of a 50 Hz sinusoid plus a PWM or is it a PWM on top of a 25 kHz sinusoid with 2 different PWM signals, one every 10 msec with a gap in between, occuring 50 times a sec (i.e. 50 Hz)

is the PWM relatively constant during each half cycle and what is its frequency?

is the processor intended to generate the output signal or is it synchronized to the 25 kHz and just generates the PWM which is added to the 15 kHz carrier

i'm curious how it's demodulated

---

<div class="post-metadata">

**Author:** ![sherzaad](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sherzaad/32/226173_2.png) [@sherzaad](https://forum.arduino.cc/u/sherzaad)\
**Post date:** [September 3, 2025, 5:33am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/9 "2025-09-03T05:33:00Z")

</div>

> [@ziaullah999](#):
>
> What about the project can you do it

not doing the ‘project’ for you

10s google search

> **[Arduino SPWM sine inverter](https://electronoobs.com/eng_arduino_tut88.php)**
>
> In this project we look how SPWM works and get a full sine shape output for the inverter 220V AC. See more..

now go and adjust it as per your requirement.

good luck!

---

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 3, 2025, 7:13am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/10 "2025-09-03T07:13:39Z")

</div>

My need to generate two complementery spwm positive half cycle on one pin and negative half cycle on second pin with carrier frequency of 25khz and modulation frequency of 50hz also two pwm has frequency of 50hz and duty cycle of 50% one pwm is active during positive half cycle and second pwm is is active during negative half cycle there is also dead time between the spwm and the modulation of duty cycle for the purpose to regulate output voltage

---

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 3, 2025, 7:24am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/11 "2025-09-03T07:24:28Z")

</div>

Yes my requirement is four signals generating two spwm and two pwm the pwm has frequency of 50hz and duty cycle of 50% and the spwm has carrier frequency of 25khz and modulation frequency of 50hz such that one pwm is active during positive half cycle and second pwm is active during negative half cycle also the spwm is a function of analog input to regulate output voltage and some dead time between the spwm

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [September 3, 2025, 9:51am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/12 "2025-09-03T09:51:24Z")

</div>

> [@ziaullah999](#):
>
> Yes my requirement is four signals generating two spwm and i and duty cycle of 50% and the spwm has carrier frequency of 25khz and modulation frequency of 50hz such that one pwm is active during positive half cycle and second pwm is active during negative half cycle also the spwm is a function of analog input to regulate output voltage and some dead time between the spwm

this is mostly a repeat of what you've already posted.

would you mind specifically addressing by questions/guesses from post #8?

> [@ziaullah999](#):
>
> two pwm the pwm has frequency of 50hz

does this mean the PWM frequency is 50 Hz?

> [@ziaullah999](#):
>
> duty cycle of 50%

if the PWM duty cycle is always 50% , what information does it carry?

> [@ziaullah999](#):
>
> modulation frequency of 50hz

what does this mean? the 25 kHz is modulated by 50Hz as illustrated below?

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/8/e/1/8e155710f75ae2a15d2565f7e10997b34419aca2.png)

---

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 3, 2025, 10:04am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/13 "2025-09-03T10:04:51Z")

</div>

Yes definitely according to the wave form

---

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 3, 2025, 10:08am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/14 "2025-09-03T10:08:52Z")

</div>

Thanks but I am using esp32

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [September 3, 2025, 10:09am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/15 "2025-09-03T10:09:12Z")

</div>

it's not clear what you're trying to do?  
can you provide an example of the waveform?

---

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 3, 2025, 10:10am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/16 "2025-09-03T10:10:44Z")

</div>

Yes need Amplitude modulation

---

<div class="post-metadata">

**Author:** ![ziaullah999](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ziaullah999/32/1235265_2.png) [@ziaullah999](https://forum.arduino.cc/u/ziaullah999)\
**Post date:** [September 4, 2025, 4:08pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/17 "2025-09-04T16:08:19Z")

</div>

Yes

 ![20250824_132927](https://europe1.discourse-cdn.com/arduino/original/4X/4/6/e/46ed462fccc170bddf800500965070e9a74815a8.jpeg)

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [September 4, 2025, 4:41pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/18 "2025-09-04T16:41:47Z")

</div>

Then you need to include an amplifier with a variable gain that is controlled by your modulation signal.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 5, 2025, 7:32am UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/19 "2025-09-05T07:32:30Z")

</div>

ESP32 using a AD9833\_DDS\_Waveform\_Generator to generate the triangular wave modulated using a X9C103S digital potentiometer

```cpp
// ESP32 AD9833 DDS module and a X9C103S Digital Potentiometer
// 20 kHz carrier modulated at 50Hz
// note: output of AD9833 DDS requires a capacitor to X9C103S input to give +/- sine wave

// AD9833 library https://github.com/MajicDesigns/MD_AD9833
// X9C103S library https://github.com/minhaj6/DigiPotX9Cxxx/tree/main

#include <SPI.h>
#include <MD_AD9833.h>
#include <DigiPotX9Cxxx.h>

// ESP32 pins for X9C103S Digital Potentiometer
DigiPot pot(16, 17, 15); // INC, U/D and CS

// ESP32 AD9833 DDS IC Pins for SPI
#define DATA 19 ///< SPI MOSI AD9833 SDATA pin
#define CLK 18 ///< SPI SCK AD9833 SCLK Clock pin
#define FSYNC 5 ///< SPI SS AD9833 FSYNC Load pin
MD_AD9833 AD(DATA, CLK, FSYNC); // AD9833 setup SPI pins

// Sine LookUpTable & Index Variable for 50Hz modulation
uint8_t SampleIdx = 0;
const uint8_t sineLookupTable[] = {
  128, 136, 143, 151, 159, 167, 174, 182,
  189, 196, 202, 209, 215, 220, 226, 231,
  235, 239, 243, 246, 249, 251, 253, 254,
  255, 255, 255, 254, 253, 251, 249, 246,
  243, 239, 235, 231, 226, 220, 215, 209,
  202, 196, 189, 182, 174, 167, 159, 151,
  143, 136, 128, 119, 112, 104, 96, 88,
  81, 73, 66, 59, 53, 46, 40, 35,
  29, 24, 20, 16, 12, 9, 6, 4,
  2, 1, 0, 0, 0, 1, 2, 4,
  6, 9, 12, 16, 20, 24, 29, 35,
  40, 46, 53, 59, 66, 73, 81, 88,
  96, 104, 112, 119
};

void setup() {
  Serial.begin(115200);
  pinMode(4, OUTPUT);
  // start the AD9833 20kHz carrier
  AD.begin();
  // MD_AD9833::MODE_OFF MD_AD9833::MODE_SINE MD_AD9833::MODE_TRIANGLE MD_AD9833::MODE_SQUARE1
  AD.setMode(MD_AD9833::MODE_TRIANGLE);
  AD.setFrequency(MD_AD9833::CHAN_0, 20000.0f); // 20KHz sine wave
}

// loop modulating 20kHz carried with 50Hz
void loop() {
  pot.set(25 + sineLookupTable[SampleIdx++] * 10/100);//75 / 255); // X9C103S modulate
  digitalWrite(4, LOW); // scope trig signal
  yield();
  if (SampleIdx >= sizeof(sineLookupTable)) { // reset to start of lookup table?
    SampleIdx = 0;
    digitalWrite(4, HIGH); // scope trig signal
  }
  // ESP32 delay 100uS 83Hz 50uS 130Hz 20uS 217Hz 10uS 325Hz (bit distorted)
  delayMicroseconds(185); // 50Hz modulation
}

```

20kHz carrier

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/8/7/b/87bc341ca202ea6a57f0c4f048073277846f9145.png)

modulated output

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/1/f/9/1f93937e0c28f4b9584c6fed2c505649640e5978.jpeg)

---

<div class="post-metadata">

**Author:** ![tom321](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tom321/32/1126662_2.png) [@tom321](https://forum.arduino.cc/u/tom321)\
**Post date:** [September 5, 2025, 8:43pm UTC](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162/20 "2025-09-05T20:43:52Z")

</div>

> [@Paul\_KD7HB](#):
>
> amplifier with a variable gain

tda7052

 ![tda7052](https://europe1.discourse-cdn.com/arduino/original/4X/9/7/b/97bb16872abc6dacf8af859861aceb8aea298ef0.gif)

[Next page](https://forum.arduino.cc/t/programing-for-pure-sine-wave-inverter/1405162.md?page=2)
