5 Replies Latest reply on Jan 7, 2019 4:48 PM by BoTa_264741

    Voltage Multiplication


      Hi all,


      For my senior capstone, my task is to design a feedback system for a DC-AC converter. My plan is implement a controller onto the PSoC 5LP. Right now, I am messing around to try to understand how multiplication works in code. I am generating a wave using the WaveDAC component in the top design. I am attempting to multiply the signal in order to change the amplitude of the sine wave based on the number I am multiplying it by, however, I am getting some pretty funky looking signals at the output. I am new to C programming so is there anything I may be doing wrong? below you can see part of the code I am using to multiply as well as the top design.


      Thank you,


      int main(void)




          double Vcontrol;

          int Out;

          double Peak_In;

          double Mult;

















              Peak_In = ADC_SAR_1_GetResult8();;

              Vcontrol = ADC_SAR_0_GetResult8() ;

              Mult = Vcontrol*Peak_In;

              Out = Mult;





        • 1. Re: Voltage Multiplication


          WaveDac8 Command:


          will not scale entire waveform, it will merely sets an instant single value to the internal VDAC8, which is getting overritten by the next DMA transfer.


          Please check this thread for simiar issue and possible solution in #4.

          WaveDAC8 Amplitude Control for PSOC5?


          All of  it can be fine excercize, but in the end you don't need analog output for AC generation. Instead you need a PWM output. That would be a waste of hardware resouces and source of errors to produce PWM from two analog waves and a comparator.

          To produce sinusoidally-modulated PWM output, just substitute VDAC8 with PWM in the above example (#4).


          • 2. Re: Voltage Multiplication

            I understand the PWM part. We already got the AC generation done, all I am trying to implement now is PI controller where the feedback is subtracted from a set value and then multiplied with a sine wave which then changes the amplitude, hence changing the amplitude of the fundamental frequency. An overall schematic can be seen on SIMULINK of system as a whole as well as the inner PSoC works.




            As you can see, the output is turned into an RMS value and then the subtracted from the set RMS and passed through a PI controller. The Output of the controller is then multiplied with the sine wave which I am generating using the WaveDAC. My goal is to set the sampled RMS value (Some DC value scaled down to below 5 V) equal to some variable RMS_In or something. This will then be passed through a PI controller and the output of the controller will be multiplied. The purpose of this was to try to understand if whether it was possible to multiply two sampled values together.


            I understand that the instantaneous value of the sine wave gets multiplied with the DC which means it should change every time right?


            My problem is that whenever I get the output, it looks like a distorted sine wave and not a scaled sine wave like I imagined it would.

            • 3. Re: Voltage Multiplication


              The Simulink modeling is surely helpful for understanding the invertor's operation and brings some luster to the capstone delivery. PSoC hardware, on the other hand, allows for direct control of the bridge FETs without involvement of analog sine generation and multiplication. Attached below is a project demo showing PWM modulation by 60Hz sine, utilizing DMA transfer of the wave from RAM buffer to PWM, which can directly control the H-bridge. No voltage multiplication inlolved.


              Attached is a project archive and output screenshots taken at various sine amplitudes.





              Fig. 1. PWM unfiltered output, sine amplitude 255, 60Hz, 32 points/period. Yellow trace - PWM, Fuchsia - DMA_nrq


              Fig. 2. PWM output filtered thru RC circuit, sine amplitude 255, 60Hz, 32 points/period


              Fig. 3. PWM output filtered by RC circuit, sine amplitude 0, 60Hz, 32 points/period


              • 4. Re: Voltage Multiplication

                Very neat!


                So now, say I choose to use this method, is there a way I could still use the PID control using this scheme after all?

                • 5. Re: Voltage Multiplication


                  This approach implements entire PWM control shown on your Simulink bottom page using PSoC specific hardware. You still have to come up with RMS measurement and PID feedback code.

                  In this demo PWM output is updated 32 times per period, providing hardware signal "tc", which can be used to strobe ADC_SAR 32 times per period and calculate RMS, and another output "nrq" and interrupt, signaling the end of period, when amplitude of the Sine wave can be updated using PID algorithm.


                  You still have to work out connection to H-bridge using PWM outputs ph1 and ph2, and to tune timing parameters. Typical power H-bridge frequency response cutoff is below 100kHz (and as low as 20kHz), while clock_1 in the demo is set to operate at ~500 kHz to provide 32 updates at 8-bit resolution each:

                  clock_1 = 32 x 256 x 60Hz = 491.52 kHz

                  This is too high for real application, as H-bridge won't respond correctly to short pulses, so you have to come up with some solution to lower It down. For example, using 8 samples per period, or using 6-bit PWM, etc., depending on whether you are going to build an actual device.