4 Replies Latest reply on Jan 21, 2019 4:34 AM by LePo_1062026

    PSoC 5LP Proportional controller

    CaDu_3933941

      Hi all,

       

      I have been working on a proportional controller to control the output of an RLC circuit with the voltage taken across the capacitor. I am feeding back the voltage reading through an ADC into the micro controller and using it to subtract from some set value. I was using the following code to apply proportional gain

      #include "project.h"

      #include <math.h>

       

       

      uint32_t Set;

      int32_t Actual;

      int32_t Error;

      int32_t PI;

      int32_t Proportional;

      int32_t Kp;

       

       

      int main(void)

      {

          CyGlobalIntEnable; /* Enable global interrupts. */

            VDAC8_1_Start();

            VDAC8_2_Start();

            PGA_1_Start();

            ADC_SAR_1_Start();

            ADC_SAR_1_StartConvert();

           

          for(;;)

          {    

         

              Kp = 3;

              Actual = 2*ADC_SAR_1_GetResult8();

              Set = 250;      

              Error = Set-Actual;

              Proportional = Kp*Error;

              PI = Proportional;

              VDAC8_1_SetValue(PI);

              VDAC8_2_SetValue(Error);

       

       

             

          }

      }

       

      This, however, gives the right value at the error instead of the output of the RLC circuit. Meanwhile, it only gives the right output if I use a PGA instead of multiplying through code as seen below:

       

      Would anyone know why this is?

        • 1. Re: PSoC 5LP Proportional controller
          EmHo_296241

          Hi,

           

          Could you please share your circuit too ?

          • 2. Re: PSoC 5LP Proportional controller
            LePo_1062026

            Molinac5,

             

            What is the impedance of your external RLC circuit?  I wonder if the problem you're seeing is that you are exceeding the drive capability of the pin's output when you don't use the PGA.

             

            It possible I don't fully understand your issue.  However here goes:  The VDAC output is very limited in current drive.  so if the issue you're seeing is when you drive the RLC circuit directly with the VDAC output, the lower impedance can cause the higher internal impedance of the VDAC (4K ohms for 1V range and 16K ohms for 4V range) to be significant.  However routing the VDAC through an Op-amp or PGA can allow the PSoC Creator to assign certain port pins that allow up to 25mA drive (<200 ohms).

             

            In short:  Be careful using VDACs directly to the external world.  It can be used when connecting to circuits of high impedance.  This means that the out circuit will be lower in bandwidth.  If higher drive (and bandwidth) is required, go through an Op-Amp or PGA component for leaving the IC.

             

            I hope this helps.

             

            Len

            • 3. Re: PSoC 5LP Proportional controller
              CaDu_3933941

              Could the issue be the fact that the VDAC is an 8-bit DAC?

              • 4. Re: PSoC 5LP Proportional controller
                LePo_1062026

                Molinac5,

                 

                Both the VDACs and IDACs are limited in current drive.  Using these components for more than signal-level analog will be problematic.

                Luckily, Cypress provides 4 Opamps in the PSoC5 with 25mA drive if routed to pins P0[0], P0[1], P3[6]  and P[37].

                 

                In modern HW design general terms, it's good practice to assume that a CPU current drive is limited to 5mA.  Therefore all power dependent circuits should be external to the CPU.

                 

                There are at least two primary reasons for this.

                • The more current sourced or sunk from CPU pins, the more power dissipation required by the CPU.  Since CPUs can operate near 100MHz, there is enough internal power dissipation (PD).  Adding I/O into the PD equation brings its challenges.
                • When "large" current sourcing or sinking is occurs, there is a voltage drop at VDD or VSS (respectively).  This is called supply or ground "bounce".  If there are very sensitive analog circuits needing a reliable (no-ripple) VDD or VSS as supplies or references (like an ADC), this could cause some undesirable variation in these circuits.  You can't eliminate supply and ground bouncing but you can minimize it.  This is why I try to use differential mode inputs for ADCs even if the '-' input is straight to GND.  Single-end mode uses internal common grounds as its reference.

                Len