Hi Mincing,

I am sorry I need to put some time and scratch my head to explain the C code. Currently I am a bit involved in some projects (pulling my hair almost always ) But here is a crude explanation.

For a simple proportional control system the PWM for the sinewave for the current pointer is looked up and the previous PWM is used with the feedback to determine the error. Thus before the current PWM is made through it is corrected for errors by proportionally modifying it.

Since for your system the max PWM is 255 (8bits) you cannot scale it up any more so your maximum gain is 1.0. Means your hardware should be able to step up the voltage and provide the current at maximum load, minimum permitted input supply. Now what we found in using the 16F is that the multiplication routines were not fast enough (18F has got a hardware multiply) to be calculated on the fly and still leave room for other tasks such as AC Restore Sense (F/V permit), Batt-low sense (+ Indication), PC communication, Overload (Thermal/Power) and Fault sense. So what we did was implement a pseudo hardware PWM. We used the compare in 16 bits and used the High Byte from the sinetable and lowbyte from the error computation. Now we find that PWM results are unsatisfactory. So we decided for lookups table that contains some precomputed results for current and voltage. This speeded up the whole thing but we lost resolution. However for a domestic inverter it was acceptable as the regulation were within specs. I am sorry I cannot reveal any more details.

So far you have not posted any codes and thus I cannot help you on your code.
We (Me and Pramod) are planning for a dsPIC based inverter for the next season and if that happens as a reality then we may release the old code to public. No promises however at this moment.

Best of Luck