4 Replies Latest reply on Dec 21, 2018 10:27 AM by CaDu_3933941

    PSoC 5LP PID Control




      I am somewhat new to PSoC and I am working on my senior thesis for which my part of the project is to design a DC-AC Converter. I am currently using a PSoC 5LP to generate my control signal using the top design in the figure below.

      The top DAC generates a 60 Hz sine wave. For my next step, I want to implement some sort of feedback control for which I need to subtract the reference sine wave from the measured one and pass it through a PI controller.


      I am planning on implementing the PI algorithm in C code so my question is: Is there a way I could read the output of the DAC and store in it a variable in my code so thatg i can implement the rest of the PI Algorithm?

        • 1. Re: PSoC 5LP PID Control


          The WaveDAC is essentially a VDAC8 component with DMA support. It is possible to read VDAC8 data back from the destination pointer VDAC8_Data_PTR. See the VDAC8_SetValue() API implementation. But....


          From your description of the project I assume that the goal is to adjust the amplitude of the second sine wave to match the reference signal, assuming that both waves have same frequency, phase, shape and offset (correct me if I am wrong). This can be done differently simply by reading analog values from DAC_1 and DAC_2 by sequential SAR_ADC and processing data in code. The 60Hz wave is slow enough to do it by PSoC CPU. To further simplify the task, you can sample amplitude value only at the peak/valley of the reference and synthesized waves. For that you would need to lock on the reference wave phase and derive a quadrature signal for ADC.  This can be easily accomplished in PSoC using Phase Locked Loop (PLL), which will produce both sync and high-frequency sampling clock for WaveDAC_2

          custom Phase-Locked Loop (PLL) implementation using PSoC5


          Note that on your schematic all information about the amplitude difference is being lost as soon it goes through comparator. At this point the PID control is no longer applicable (at least the traditional one), as PID  require knowledge of signal deviation (V1-V2) for further processing. Since you have only 1-bit digital info available from the comparator (>,<), the PID will never settle (this is like a cheap house thermostat with on/off action, which either overshoots or undersoots the set temperature, but never stay on target).


          There are other methods for 1-bit digital control, e.g. fuzzy logic or "take-back-half", which don't give same accuracy and speed as PID.




          • 2. Re: PSoC 5LP PID Control



            Thanks a lot! I decided for a different scheme where I compare a set RMS value with the actual RMS. The error is then passed through a PID algorithm and then multiplied with the control sine wave in order to control the modulation index.


            My question now is, once I sample some incoming signal using using the DAC component, how would I go about calculating its RMS value?

            • 3. Re: PSoC 5LP PID Control


              There are several examples of RMS measurement using PSoC5. What is the frequency range are you looking, 50-60Hz or >20kHz? Note, that the RMS value is calculated per period, so unless you have very precise and stable frequency (like 60Hz AC power mains), some frequency detection scheme has to be used to sync the sampling clock, e.g. PLL, frequency multiplier, or direct frequency measurement.


              Here is useful link about RMS by K. Castor-Perry:

              Five things you should know about RMS | eeNews Power



              P.S. What is modulation index?

              • 4. Re: PSoC 5LP PID Control

                The signal I will be sampling is a 60 Hz signal. The modulation index is the value of the amplitude of the control signal (Sine Wave) divided by the Triangle Wave generated by the seconds WaveDAC. The modulation index should always be less than or equal to 1 and this determines the amplitude of the fundamental frequency component hence controlling the output voltage. The PI controller will compensate the error between the set RMS and the actual RMS, and then multiply the output with the reference sine wave changing the modulation index depending on the set value.