element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum How to convert PID output into meaningful result to feed into controller
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 7 replies
  • Subscribers 473 subscribers
  • Views 1152 views
  • Users 0 members are here
  • pid controller
Related

How to convert PID output into meaningful result to feed into controller

chrischristian14
chrischristian14 over 5 years ago

Hi, I am creating a pressure controller with PIC micro that is controlling the heating coil and a pocketbeagle that is running a PID loop. The PIC micro takes commands from pocketbeagle over UART.

PIC responds to 0 to 9, with 9 being heating coil switched off and 1 being full on.The PID loop outputs numbers up to 10000000, depending upon what is the difference between the measured pressure and the desired pressure, and I am really struggling to convert this PID output (0 to 10 million ) to a range of 0 to 9 and not killing the PID functionality - i.e. keeping it PID and not making it like a normal code. I managed to have a few range of loop, and each range is a PID loop on its own, but that is not an ideal solution. Below is the code I tried, int_diff is the (int) PID output. Can anyone pelase help ? I have a feeling I might be over complicating things but don't know how.

Just to explain, in below code, each range sends 0 to 9 numbers to PIC micro, so the problem arises when the difference between set pressure and measured pressure is low and it just need to go up by a little, but the output (int_diff) switches range and suddenly it goes to 0 (heating coil full on) and then on next measurement (after about a second) it goes to 9 (heating coil off), while it should be moving from 8 to 9. This kind of movement (0 to 9) causes overshoot, and the reverse is also true, causing very slow rise in temperature or undershoot.

I hope I am making sense. Thanks

if(0<int_diff && int_diff<99)
{
value = diff/10; //(gives 1 to 9)
closer =1;
}
#if 1
else if(99<int_diff && int_diff<999)
{


value = diff/100;
closer =1;
}




else if (999<int_diff && int_diff<9999)
{
value = diff/1000;
closer =1;
}
else if (9999<int_diff && int_diff<99999)
{
value = diff/10000;
closer =1;
}




else if (99999<int_diff && int_diff<999999)
{
value = diff/100000;
closer =1; 
}
else if (999999<int_diff && int_diff<9999999)
{
value = diff/1000000;
closer =1;
//value = 0;
}




if(closer==1)
{


if(value>=0)
{
value= 9-(int)value;
}
else if(value<0)
{
value=9;
}


}
else
{
value = 0;
}

  • Sign in to reply
  • Cancel

Top Replies

  • chrischristian14
    chrischristian14 over 5 years ago in reply to michaelkellett +3
    Thanks Michael, I am not new to this embedded stuff, I have about 10 years of experience in electronics and maintain an RTOS product as part of my full time work, what I am not good at is explaining things…
  • michaelkellett
    michaelkellett over 5 years ago +2
    Not making much sense ! This doesn't look like all your code ! You would do much better to have it all in one place either on the PIC or the Beagle. Steps of only 0 to 9 is quite possibly not fine enough…
  • michaelkellett
    michaelkellett over 5 years ago in reply to chrischristian14 +2
    I get the feeling you are new to all this embedded stuff. My first bit of advice is that you should never leave an unexplained observation to fester. You say that the triac turns on and then turns off…
Parents
  • michaelkellett
    michaelkellett over 5 years ago

    Not making much sense !

    This doesn't look like all your code !

     

    You would do much better to have it all in one place either on the PIC or the Beagle.

    Steps of only 0 to 9 is quite possibly not fine enough control for a PID to work correctly.

     

    Suppose you only need a power setting of 3.5 to get the correct pressure, the actual, setting will need to oscillate between 3 and 4, this can work but its not  PID.

     

    Also, the ONLY valid way to scale the output of the Beagle controller is by linearly scaling it, in your case multiplying by 9/1e7.

     

    No one ever uses a straight PID controller in real life, you always need extras like integral wind up limiting.

     

    If you describe the system in more detail and post the Beagle code it will be possible to help you (why do you need a Beagle and a PIC), how does the heater work ?

     

    I've got code for two controllers in mind, one I did for a heater which is linear and another for a fridge which is not.  But I'd need to know a lot more about you system before suggesting code.

     

    MK

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • michaelkellett
    michaelkellett over 5 years ago

    Not making much sense !

    This doesn't look like all your code !

     

    You would do much better to have it all in one place either on the PIC or the Beagle.

    Steps of only 0 to 9 is quite possibly not fine enough control for a PID to work correctly.

     

    Suppose you only need a power setting of 3.5 to get the correct pressure, the actual, setting will need to oscillate between 3 and 4, this can work but its not  PID.

     

    Also, the ONLY valid way to scale the output of the Beagle controller is by linearly scaling it, in your case multiplying by 9/1e7.

     

    No one ever uses a straight PID controller in real life, you always need extras like integral wind up limiting.

     

    If you describe the system in more detail and post the Beagle code it will be possible to help you (why do you need a Beagle and a PIC), how does the heater work ?

     

    I've got code for two controllers in mind, one I did for a heater which is linear and another for a fridge which is not.  But I'd need to know a lot more about you system before suggesting code.

     

    MK

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube