I am trying to understand and implement FOC algorithm in MATLAB for a PMSM. I understand we are converting the 3 phase stator currents into 2 time-invariant stator currents: (direct and quadrature currents or Id and Iq, respectively). But I do not unsderstand how PWM is applied here since PWM can only alternate between High and Low currents but I do not understand why this is required or how it will help in torque control since. I thought the PI controllers adjusted Id and Iq to be the same as the reference currents and then inverse Park transform and inverse Clarke transfroms would be applied to get 3 phase voltages. PWM shouldn't be used since we are feeding 3 phase voltages into the stator. So what is the function of PWM here ? What does it do ? Please your help would be really appreciated since I am struggling a lot with this. Thank you in advance.

Also could someone explain me how the PI controllers manage to convert currents into voltages to be fed into the inverse Park transform ?

Also why is SPWM employed ? what makes is that good ? (Could you also point me to a source (preferably academic) which explains SPWM ?