sine analog compare triangle signal to pwm

I think you mean PID controller.
Take a look at this PID library for arduino.
http://playground.arduino.cc/Code/PIDLibrary