Phase control with feedback has several hardware/software functions that must work together.
I break down each function to its own operation and write the program so each function can be tested separately.... then the main program brings the functions together.
For Phase control you may need.....
-zero cross detector circuit and software (requires interrupts by microprocessor)
-Triac drive function ckt/routine , pulsed or timed pulse for inductive loads (inductive loads can 'bounce triac off at wrong time if gate not held on)
- voltage feedback ckt/routines.....takes some smoothing hardware to get reasonable DC level from the AC voltage.
- a main program loop to combine all the functions, control/on/off, adjust parameters, check and handle errors etc.
Breaking projects down to testable individual parts has been the easiest method to make working stuff for me.
don