I took the L6565 application sheet circuit and replaced the L6565 with a PIC16f506.

It basically seems to work ok with two exceptions.
1/ On high power the transformer whistles very loudly.
2/ The transformer seems to get hot.

The PIC provides the mosfet pulse. It also looks at the winding for demagnetising sense.
It also looks at the opto for voltage feedback.

If anyone has any ideas how to fix these problems it would be greatly appreciated.