Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] How to use PID controller to control PWM in dsPIC30f2010 to generate sinewave

Status
Not open for further replies.

Heram

Newbie level 3
Joined
Apr 3, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
30
I have generated sine wave using PWM. Now I want to control the output voltage using PID controller technique with less THD.
I tried in many ways but I am not getting proper output(the sine wave disturbed).
Would you please guide me ?

I have taken Kp=0.1 and Ki=0.1


Code C - [expand]
1
2
3
4
5
6
7
8
9
error = setPoint-Feedback_Value;
 
iError +=error;
 
outPut = (Kp*error) + (Ki * iError);  // PI value
 
percentage = ((outPut*100/setPoint)); //Error in percentage
 
PDC1 += ((PDC1*percentage)/100); // I have used a variable in place of PDC1 for calculation and in next step I added that to PDC1

 
Last edited by a moderator:

Hi,

I think the error is in line 7.

You must not divideby "Setpoint" but by "full scale value"

Klaus
 
  • Like
Reactions: Heram

    Heram

    Points: 2
    Helpful Answer Positive Rating
Hi,

please limit the value of iError.
decide on your own what max and what min values make sense.

Maybe in your case limit it to 0...1.

Klaus
 
  • Like
Reactions: Heram

    Heram

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top