using any mcu for generating a sinal will not be pure as you need, it will be called pseudo sinusoidal, you'll need good filtering, if you want to acheive a somewhat good sinus wave out of it
You are right in case the code is not well written. For instance, I had to write my codes, since early 80's, in assembly language only because I couldn't get, for free or else, high language compilers as of C for example.
I managed to output the SPWM signals at pins OC1A and OC1B of ATmega8 (using fast PWM of timer 1). The rate is 15,625 Hz. The number of samples per cycle (50 Hz) is 312.
The amazing thing is that the small leakage inductance of the iron power transformer does the filtering with a relatively small high voltage capacitor (around 1 uF). I am not sure how good (speaking THD) the sinewave, I got, is. But it looks on the scope screen it looks a sine wave without ripple.
Naturally, to maintain 220V at the output, the MCU reads the output voltage in every cycle (50 Hz) to adjust the gain of the PWM for the next cycle. This voltage regulation allows a soft start at boot (from 0V to 220V, in 800ms). The MCU has other functions related to safety in case of faults.
you could have some equipment compatibility problems
IE i have some laptop chargers who wont refuses to start even with pseudo signal inverters, with pure sinewave they start etc .... some tv's dont work too (they use ac-dc adapters)
In the last 12 years, I produced and sold about 5 thousand 'adaptive square wave' inverters (regulated by varying the duty cycle). Lately, it became clear that every device (made for 50Hz sinewave) whose power supply uses a series capacitor to limit the internal supply current, is damaged, sooner or later, by a square wave inverter. Summer is at the door and electric fans will be used soon. Most of these fans are controlled by electronic boards supplied internally by a series capacitor (no more by a small transformer). So, I decided to also produce low-cost sinewave inverters, at least for these fans.
I admit that with the limited available components around me I can't do miracles by making such inverters also with high efficiency. Losses in the iron transformer whose available laminated core is also of the lowest possible grade! (Bs=1.05 Tesla, Br=0.7 Tesla and Hc=100 A/m) is much higher than of ferrite's.
while i salute your idea, you may face other challenges you dont even know
In the initial tests, it became clear that the transformer acts as a current source when overloaded. In this case, the output cannot reach the sine flat top and starts to look like a triangular wave instead. Fortunately this wave doesn't damage the series capacitor supplies, as the fast edges of a square wave do.