Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:07:08+00:00 2026-05-28T00:07:08+00:00

I can’t see any memory change in my .map file when I try to

  • 0

I can’t see any memory change in my .map file when I try to compare the two different codes.
Is there a “good practice” to follow here? Should I or shouldn’t I put the variables in the header?
As a note, I can have multiple PIDUpdate() functions, I allready have two (if that makes any difference).

First example without variables in the header -> main.c

static int16_t PIDUpdate(int16_t target, int16_t feedback) // Valve
{
static float pTerm, iTerm, dTerm;
static float PID;
int16_t CurrentError;
static float LastError, SumError;
uint16_t tick;
static uint16_t elapsed;
float Kp = 0.1, Ki = 0.1, Kd = 0.1;

Kp = (float) pGain/10000.0;
Ki = (float) iGain/10000.0;
Kd = (float) dGain/10000.0;

....
if(elapsed = tick - timestamp, elapsed < TRACKING_PERIOD)
    goto leave;

timestamp = tick;

CurrentError = target - feedback;

pTerm = Kp * CurrentError;

// Calculate the Integral State with appropriate Limiting
....
iTerm = Ki * SumError;

dTerm = Kd * (LastError - CurrentError);

LastError = CurrentError;

PID = pTerm + iTerm + dTerm;

control = PID;
....
    leave:
return (control);
      }

The other example with variabels in header instead -> main.h

typedef struct PID
{
// PID parameters
uint16_t Kp; // pGain
uint16_t Ki; // iGain
uint16_t Kd; // dGain

// PID calculations
float pTerm;
float iTerm;
float dTerm;
float PID;

// Extra variabels
int16_t CurrentError;

// PID Time
uint16_t tick;

   }pid_object;

   typedef static struct staticPID
   {    
// Extra variabels
int16_t control;
float LastError;
float SumError;

// PID Time
uint16_t elapsed;
uint16_t timestamp;

    }StaticPid_object;

Now the main.c code togheter with above .h-file

static int16_t PIDUpdate(int16_t target, int16_t feedback) // Valve
{
pid_object _PID_t;
StaticPid_object _StatPID_t;

_PID_t.Kp = (float) pGain/10000.0;
_PID_t.Ki = (float) iGain/10000.0;
_PID_t.Kd = (float) dGain/10000.0;

if(_StatPID_t.elapsed = _PID_t.tick - _StatPID_t.timestamp, _StatPID_t.elapsed < TRACKING_PERIOD)
    goto leave;

_StatPID_t.timestamp = _PID_t.tick;

_PID_t.CurrentError = target - feedback;

_PID_t.pTerm = _PID_t.Kp * _PID_t.CurrentError;

// Calculate the Integral State with appropriate Limiting
....

_PID_t.iTerm = _PID_t.Ki * _StatPID_t.SumError;

_PID_t.dTerm = _PID_t.Kd * (_StatPID_t.LastError - _PID_t.CurrentError);

_StatPID_t.LastError = _PID_t.CurrentError;

_PID_t.PID = _PID_t.pTerm + _PID_t.iTerm + _PID_t.dTerm;

_StatPID_t.control = 255-_PID_t.PID; // Make it work oposite to Heater

     leave:
return (_StatPID_t.control);
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:07:09+00:00Added an answer on May 28, 2026 at 12:07 am

    It doesn’t matter where your code is — in .h or in .c, but if you include the header defining static variable in multiple files, you’ll have different instance for each file. What matters here is if this is what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone recommend a good library for generating an audio file, such as mp3,
can any one tell me how can change this java code into objective c.is
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can you suggest some good MVC framework for perl -- one I am aware
Can i get the source code for a WAMP stack installer somewhere? Any help
Can somebody point me a good strategy for security crosscutting concern without AOP for
Can I convert a pdf to pcl file with ghostscript? I'm using Ghostscript 9.01
Can someone tell me the regex to see if something is surrounded in double
Can somebody point me to a resource that explains how to go about having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.