I am writing my own instructions for a FPGA processor that I have made and I have a question about how to best produce a PWM signal from a PID control loop. I am confused how I should use the PID output signal to change the PWM duty cycle. I will explain how I plan on doing this and you can let me know if I am on the right track. Let's assume these inputs are 8 bits in size for simplicity.
So I have an analog input that will be connected to the FPGA through an ADC chip for the user to set the speed setpoint. The actual speed is measured via another analog signal and is also connected to the FPGA through another ADC chip. This gives binary values for setpoint and actual speeds somewhere between 0 and 255.
From these binary values, I can calculate the speed setpoint and the actual speed setpoint in my measurement term, which is RPM in this case.
As I will only use PI control, I can calculate the error value, find the integral value and finally calculate the output signal which will be in RPM.
Now I have a PWM generator block which has a triangular like waveform (basically a free running counter). I plan on feeding my calculated PI output signal into this PWM generator block and comparing the values cyclically in my program. If the output signal is less than triangular waveform, PWM signal is high etc. As the comparison value of one of the signals is changed, this will produce a changing PWM signal. (I know to cap the max PWM signal to whatever 100% when saturation occurs and to only change comparison value when counter is at max value to prevent false PWM signals).
Is there better ways to implement a PWM signal that is controlled via a PI control loop? I am interested to hear your thoughts?
Thanks guys