confusion in controlling voltage with PID

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
tabishmisbah
Employee
Employee
First like given 5 replies posted 25 sign-ins

Hello Everyone,
hope you all are doing good. 

I need your suggestions and help on my following tasks:
"note: a long question"

I have psoc5 lp , a mosfet (bsl802sn) and drain resistor 2.2 ohms and at source shunt resistor of 100m ohms .

My 1st-task is to maintain desired dc voltage at shunt resistor.

For this what i am doing is taking a reference volts from across shunt resistor connects it to DELSIG ADC (differential mode) in psoc 5 converts it in samples , setting a desired voltage(in between 20 to 50mv dc),implementing pid controller, calculating controlled output and send to VDAC  and vdac is connected to gate of mosfet and it control the gate and maintains desired dc voltage at shunt resistor even though if I change vdd of mosfet with in a range of 2 to 4 volts , and this is working fine with some errors. 
I am not sure whether this approach is good or there are some other ways for my 1st task.

my 2nd task is :
it is a continuation of 1st task in which i have to shape the output dc voltage at shunt in a rectangular wave for this i am thinking that setting two desired voltage in PID and one is zero and one is, again in between(20mv to 50mv) and oscillate between two desired voltage with frequency between 1 Hz to 2KHz  hence will get rectangular wave  with a high level voltage equal to our desired voltage. and here also if my vdd will change for any reason between 2 to 4 volts my desired voltage should not be change. 
and for this task i am confused if this is a applicable solution to my task 2 or there are some other ways?

and 3rd task is to generate a sine wave just like a square wave. and setting a peak to peak voltage by changing desired voltage in pid in a sine wave manner.

i am not sure for all my tasks the approach i am thinking is the practical and applicable approach  or there are other ways to do these tasks. let me know I will share more details if anyone does not get my point 

thanks for your time to read my long query.
thank you.

0 Likes
1 Solution
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

For the Par 3 you may use this project as a reference

Sine wave generation using WaveGen and PWM (SPWM)

However, yor description of the specs is rather vague. I believe that you want to control the current, not voltage, and have to decide whether you want to control a per-pulse curent or an average one (RMS -like)

 

View solution in original post

0 Likes
4 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

For the Par 3 you may use this project as a reference

Sine wave generation using WaveGen and PWM (SPWM)

However, yor description of the specs is rather vague. I believe that you want to control the current, not voltage, and have to decide whether you want to control a per-pulse curent or an average one (RMS -like)

 

0 Likes

Hello ,
hope you are doing good.
I decided to use SPWM for my project, and switching mosfet in sinewave pattern by using SPWM signal at gate. 
The following project
Sine wave generation using WaveGen and PWM (SPWM)
you shared is a bit difficult for me to understand , can you please guide me how can i change the pwm switching frequency in it? and Fout is the frequency of modulating signal i.e sinewave ,right? and how can i change amplitude of sine wave? and i am seeing SPWM at pin_150 , could you please guide me at which pin i can see the sinewave being generated by wave gen. so that i can have the picture of sine wave and its equivalent generated SPWM signals .
thanks 

0 Likes

The project goal is to produce a PWM-generated sine (SPWM) signal.  This is projects schematic:

WaveGen_PWM_02a_basic_A.png

The output sine frequency is defined by the WaveGen buffer length (32), PWM period (256) and DDS frequency (12.5 Hz):  Fout = Fdds x (256/32) = 12.5Hz x 8 = 100 Hz

By changing the DDS frequency, one can change the sine frequency:

 

double Fout = 100.0; // required sine output frequency (Hz)
double Fdds = Fout * ((double) WaveGen_1_NumSamples / 256.0 ); // (PWM_1_ReadPeriod = 255 for 8-bit)   
DDS_1_Start();
DDS_1_SetFrequency(Fdds);

 

The PWM switching frequency and output sine frequency are linked by a number of sine points per period (here is 32) and can't be changed during run-time. Here the PWM clock is:

Clk_PWM = Fdds * 256 * 256 = (Fout * 32 / 256) * 256 * 256 = Fout * 32 * 256  

The amplitude of the sine wave is set by generating the WaveGen RAM Buffer waveform using API:

 

// Fill Buffer with 1 period of Sine wave
WaveGen_1_CreateSineWave_C(128, 0);  // sine centered at 128u

 

where 128 - is the sine amplitude, it can vary in the [0  to 128] range.

The WaveGen keeps sine values in RAM and only send hem to the PWM compare register on request of the PWM. You can't see it, as it is virtual. To observe the sine output just add a RC to filter PWM out

tabishmisbah
Employee
Employee
First like given 5 replies posted 25 sign-ins

thanks  

0 Likes