EmbeddedRelated.com
Forums

Optimize pow() function

Started by pozz September 22, 2016
Il 22/09/2016 17:01, Tim Wescott ha scritto:
 > [...]
> Assuming you can't do that, the first thing that I'd suggest is to use > interpolation or a curve fit to a number of measured points. > Interpolation is easy -- just store a number of calibration points and > then use linear, quadratic, or cubic interpolation between them. Even > cubic interpolation should be quicker than using pow. Alternately, fit a > function y = A + B * x + C * x^2 + D * x^3 to your calibration points, > and store A, B, C & D in memory.
Yes, this is a lighter calculation for the MCU, but the calibration would be much more difficult to the operator. Please, take a look at my answer to Don Y for additional details on my system: I have a digital trimmer.
On 9/22/2016 5:10 PM, pozz wrote:
> Il 22/09/2016 16:17, Don Y ha scritto: >> On 9/22/2016 6:36 AM, pozz wrote: >>> I have to convert voltage measure (Volt) into power (Watt). As you >>> know, the >>> physics says I need to square the voltage measure. >>> >>> I have to calibrate the mathematical law and I have two points: >>> 0W -> 0V >>> <nominal power> -> <voltage at nominal power> >>> >>> That could be enough, but we noticed a different relation between volt >>> and watt >>> at intermediate points. I, as the software engineer, have to try to >>> compensate >>> differences from the theory, without increasing complexity during >>> calibration. >>> >>> My idea is to calibrate the exponent: it is normally 2.00, but I can >>> calibrate >>> from 1.00 to 3.00. >>> In this way, the two old calibration points are the same as before. >>> So the >>> exponent (the third calibration measure) can be changed at last. >>> >>> The problem is pow() function with double arguments takes a lot of >>> time to >>> finish. Do you suggest a mathematical method to reduce its complexity? >>> >>> >>> uint16_t power_nominal = 1500; // In Watt >>> uint16_t volt_nominal; // Volt measured at nominal power >>> signed uint8_t exp_corr = -100 to +100; >>> double exp = 2.00 + exp_corr; >>> >>> uint16_t volt = adc_convert(...); // Actual volt measure >>> double alpha = (double)power_nominal / pow((double)volt_nominal, exp); >>> uint32_t watt = alpha * pow((double)volt, exp); >>> >>> >>> alpha can be pre-calculated, because power_nominal, volt_nominal and >>> exp are >>> constant (after calibration). The last instruction is the problem. >> >> No, the "problem" lies in your transducer/measurement error. >> The definition of a "watt" (power) doesn't change just because your >> observations of that APPARENT relationship (V ~ W) "has issues". >> >> Perhaps your load's characteristics are changing as a function >> of operating point. Or, nonlinearities in your measurement system. >> Or, ... >> >> Ask yourself WHY the exponent needs to be changed. I suggest you >> don't have an accurate model of your load and its excitation. >> Until you do, how will you know that this is the CORRECT means of >> compensating your model to agree with your observations? > > > I know the problem is in the poor quality of the transducer, but I'm > only in charge of the software and the hardware engineer can't fix it > (often the software solves hardware issues). > > So I need a more complex law. The quadratic law (one parameter) can be > calibrated with a single measure (nominal value). The generic power law > (exponent not exactly equals to 2, two parameters) needs two calibration > measures and has a nice feature: it's very simple to calibrate in two > steps. > > The input section has an hardware calibration, a simple digital trimmer. > So the first step is to calculate the power from the measured voltage > with the following formula: > P = Pn / (Vn ^ 2) * (V ^ 2) > where Pn is the nominal power and Vn is the voltage needed at nominal > power. The user increase/decrease the trimmer pot until the correct > power is displayed. > > Second step. Change the power to another value (half of nominal power, > for example). If the transducer works as in theory, the measured power > is correct. Otherwise the user increase/decrease the exponent until the > power displayed is correct. The power is calculated as: > P = Pn / (Vn ^ exp) * (V ^ exp) > > After the second step, we are sure the first calibration point is yet > valid, because that formula is correct when V=Vn, even if exp isn't 2. > > > If I use the linear law P=AV^2+BV, I think the two calibration steps > aren't indipendent: the operator should execute two measures, the system > should save the two couples (P,V) and only after that calculate A and B > coefficients. > > > It seems to me the exponentiation law is simpler during calibration.
I don't know that complicating your power calculation is the right way to go. Even if you do, why do you thing adjusting the exponent is the right compensation? There are any number of other ways the values you are measuring could be out. Can you measure the *actual* voltage the transducer is measuring? How are you getting the power measurement to compare to your calculations? What is the device which is the load for this calculation? Rather than fudging the calculation, maybe it is simpler to figure out how the measurement is out and correct that before you perform the power calculation. -- Rick C
Den torsdag den 22. september 2016 kl. 23.32.03 UTC+2 skrev rickman:
> On 9/22/2016 5:10 PM, pozz wrote: > > Il 22/09/2016 16:17, Don Y ha scritto: > >> On 9/22/2016 6:36 AM, pozz wrote: > >>> I have to convert voltage measure (Volt) into power (Watt). As you > >>> know, the > >>> physics says I need to square the voltage measure. > >>> > >>> I have to calibrate the mathematical law and I have two points: > >>> 0W -> 0V > >>> <nominal power> -> <voltage at nominal power> > >>> > >>> That could be enough, but we noticed a different relation between volt > >>> and watt > >>> at intermediate points. I, as the software engineer, have to try to > >>> compensate > >>> differences from the theory, without increasing complexity during > >>> calibration. > >>> > >>> My idea is to calibrate the exponent: it is normally 2.00, but I can > >>> calibrate > >>> from 1.00 to 3.00. > >>> In this way, the two old calibration points are the same as before. > >>> So the > >>> exponent (the third calibration measure) can be changed at last. > >>> > >>> The problem is pow() function with double arguments takes a lot of > >>> time to > >>> finish. Do you suggest a mathematical method to reduce its complexity? > >>> > >>> > >>> uint16_t power_nominal = 1500; // In Watt > >>> uint16_t volt_nominal; // Volt measured at nominal power > >>> signed uint8_t exp_corr = -100 to +100; > >>> double exp = 2.00 + exp_corr; > >>> > >>> uint16_t volt = adc_convert(...); // Actual volt measure > >>> double alpha = (double)power_nominal / pow((double)volt_nominal, exp); > >>> uint32_t watt = alpha * pow((double)volt, exp); > >>> > >>> > >>> alpha can be pre-calculated, because power_nominal, volt_nominal and > >>> exp are > >>> constant (after calibration). The last instruction is the problem. > >> > >> No, the "problem" lies in your transducer/measurement error. > >> The definition of a "watt" (power) doesn't change just because your > >> observations of that APPARENT relationship (V ~ W) "has issues". > >> > >> Perhaps your load's characteristics are changing as a function > >> of operating point. Or, nonlinearities in your measurement system. > >> Or, ... > >> > >> Ask yourself WHY the exponent needs to be changed. I suggest you > >> don't have an accurate model of your load and its excitation. > >> Until you do, how will you know that this is the CORRECT means of > >> compensating your model to agree with your observations? > > > > > > I know the problem is in the poor quality of the transducer, but I'm > > only in charge of the software and the hardware engineer can't fix it > > (often the software solves hardware issues). > > > > So I need a more complex law. The quadratic law (one parameter) can be > > calibrated with a single measure (nominal value). The generic power law > > (exponent not exactly equals to 2, two parameters) needs two calibration > > measures and has a nice feature: it's very simple to calibrate in two > > steps. > > > > The input section has an hardware calibration, a simple digital trimmer. > > So the first step is to calculate the power from the measured voltage > > with the following formula: > > P = Pn / (Vn ^ 2) * (V ^ 2) > > where Pn is the nominal power and Vn is the voltage needed at nominal > > power. The user increase/decrease the trimmer pot until the correct > > power is displayed. > > > > Second step. Change the power to another value (half of nominal power, > > for example). If the transducer works as in theory, the measured power > > is correct. Otherwise the user increase/decrease the exponent until the > > power displayed is correct. The power is calculated as: > > P = Pn / (Vn ^ exp) * (V ^ exp) > > > > After the second step, we are sure the first calibration point is yet > > valid, because that formula is correct when V=Vn, even if exp isn't 2. > > > > > > If I use the linear law P=AV^2+BV, I think the two calibration steps > > aren't indipendent: the operator should execute two measures, the system > > should save the two couples (P,V) and only after that calculate A and B > > coefficients. > > > > > > It seems to me the exponentiation law is simpler during calibration. > > I don't know that complicating your power calculation is the right way > to go. Even if you do, why do you thing adjusting the exponent is the > right compensation? There are any number of other ways the values you > are measuring could be out. > > Can you measure the *actual* voltage the transducer is measuring? How > are you getting the power measurement to compare to your calculations? > What is the device which is the load for this calculation? > > Rather than fudging the calculation, maybe it is simpler to figure out > how the measurement is out and correct that before you perform the power > calculation. >
yeh, the voltage measurement being out is going to have a different impact than a changing load resistance
On 9/22/2016 5:10 PM, pozz wrote:
> Il 22/09/2016 16:17, Don Y ha scritto: >> On 9/22/2016 6:36 AM, pozz wrote: >>> I have to convert voltage measure (Volt) into power (Watt). As you >>> know, the >>> physics says I need to square the voltage measure. >>> >>> I have to calibrate the mathematical law and I have two points: >>> 0W -> 0V >>> <nominal power> -> <voltage at nominal power> >>> >>> That could be enough, but we noticed a different relation between volt >>> and watt >>> at intermediate points. I, as the software engineer, have to try to >>> compensate >>> differences from the theory, without increasing complexity during >>> calibration. >>> >>> My idea is to calibrate the exponent: it is normally 2.00, but I can >>> calibrate >>> from 1.00 to 3.00. >>> In this way, the two old calibration points are the same as before. >>> So the >>> exponent (the third calibration measure) can be changed at last. >>> >>> The problem is pow() function with double arguments takes a lot of >>> time to >>> finish. Do you suggest a mathematical method to reduce its complexity? >>> >>> >>> uint16_t power_nominal = 1500; // In Watt >>> uint16_t volt_nominal; // Volt measured at nominal power >>> signed uint8_t exp_corr = -100 to +100; >>> double exp = 2.00 + exp_corr; >>> >>> uint16_t volt = adc_convert(...); // Actual volt measure >>> double alpha = (double)power_nominal / pow((double)volt_nominal, exp); >>> uint32_t watt = alpha * pow((double)volt, exp); >>> >>> >>> alpha can be pre-calculated, because power_nominal, volt_nominal and >>> exp are >>> constant (after calibration). The last instruction is the problem. >> >> No, the "problem" lies in your transducer/measurement error. >> The definition of a "watt" (power) doesn't change just because your >> observations of that APPARENT relationship (V ~ W) "has issues". >> >> Perhaps your load's characteristics are changing as a function >> of operating point. Or, nonlinearities in your measurement system. >> Or, ... >> >> Ask yourself WHY the exponent needs to be changed. I suggest you >> don't have an accurate model of your load and its excitation. >> Until you do, how will you know that this is the CORRECT means of >> compensating your model to agree with your observations? > > > I know the problem is in the poor quality of the transducer, but I'm > only in charge of the software and the hardware engineer can't fix it > (often the software solves hardware issues). > > So I need a more complex law. The quadratic law (one parameter) can be > calibrated with a single measure (nominal value). The generic power law > (exponent not exactly equals to 2, two parameters) needs two calibration > measures and has a nice feature: it's very simple to calibrate in two > steps. > > The input section has an hardware calibration, a simple digital trimmer. > So the first step is to calculate the power from the measured voltage > with the following formula: > P = Pn / (Vn ^ 2) * (V ^ 2) > where Pn is the nominal power and Vn is the voltage needed at nominal > power. The user increase/decrease the trimmer pot until the correct > power is displayed. > > Second step. Change the power to another value (half of nominal power, > for example). If the transducer works as in theory, the measured power > is correct. Otherwise the user increase/decrease the exponent until the > power displayed is correct. The power is calculated as: > P = Pn / (Vn ^ exp) * (V ^ exp) > > After the second step, we are sure the first calibration point is yet > valid, because that formula is correct when V=Vn, even if exp isn't 2.
I think your equation is not written in a clear way. I think what you mean is this... P = Pn * (V ^ exp) / (Vn ^ exp) Now the equation makes sense to me. But that still doesn't mean it will give close to correct values anywhere other than the calibration points. Have you considered... P = Pn * (V / Vn) ^ exp Then there are an infinite set of other corrections you could use. The question is which ones are more accurate? Have you looked at a range of data to see what the correction curve needs to be? -- Rick C
On 9/22/2016 2:10 PM, pozz wrote:

> > No, the "problem" lies in your transducer/measurement error. > > The definition of a "watt" (power) doesn't change just because your > > observations of that APPARENT relationship (V ~ W) "has issues". > > > > Perhaps your load's characteristics are changing as a function > > of operating point. Or, nonlinearities in your measurement system. > > Or, ... > > > > Ask yourself WHY the exponent needs to be changed. I suggest you > > don't have an accurate model of your load and its excitation. > > Until you do, how will you know that this is the CORRECT means of > > compensating your model to agree with your observations? > > I know the problem is in the poor quality of the transducer, but I'm only in > charge of the software and the hardware engineer can't fix it (often the > software solves hardware issues). > > So I need a more complex law. The quadratic law (one parameter) can be > calibrated with a single measure (nominal value). The generic power law > (exponent not exactly equals to 2, two parameters) needs two calibration > measures and has a nice feature: it's very simple to calibrate in two steps.
Backup. You're calibrating because, presumably, you need *some* degree of accuracy. How (formally) has that been specified? Percent of reading? Percent of range? etc. This tells you how "good" your model of the load must represent the ACTUAL load, as viewed from the standpoint of your *single* measurement device. So far, you appear to only be considering fitting a curve to two points: - 0V (= 0 power!) - Vmax (= some particular power) Yet, you seem to care about the values between 0 and Vmax. How *much* do you care about them? If you are only operating at the 0 & Vmax points on the curve, then you don't need to fit an equation; just store: (0V, 0W) and (Vmax, Pmax) [Obviously, this is not the case!]
> The input section has an hardware calibration, a simple digital trimmer. > So the first step is to calculate the power from the measured voltage with the > following formula: > P = Pn / (Vn ^ 2) * (V ^ 2) > where Pn is the nominal power and Vn is the voltage needed at nominal power.
But, you aren't *controlling* any of these things (?) rather, just *sensing* them (i.e., someone tells you "this is a load of X" while you examine a sensed parameter -- voltage -- to correlate with that declaration).
> The user increase/decrease the trimmer pot until the correct power is displayed.
What is your *load*? If purely resistive, does it have a temperature coefficient? (e.g., if you left it operating at Pmax, would you see changes) In operation, do you expect the load to be "static"? Or, time varying? Does the load's impedance change based on how *it* is driven? etc.
> Second step. Change the power to another value (half of nominal power, for > example). If the transducer works as in theory, the measured power is correct. > Otherwise the user increase/decrease the exponent until the power displayed is > correct. The power is calculated as: > P = Pn / (Vn ^ exp) * (V ^ exp) > > After the second step, we are sure the first calibration point is yet valid, > because that formula is correct when V=Vn, even if exp isn't 2. > > If I use the linear law P=AV^2+BV, I think the two calibration steps aren't > indipendent: the operator should execute two measures, the system should save > the two couples (P,V) and only after that calculate A and B coefficients. > > It seems to me the exponentiation law is simpler during calibration.
Your concern should be that of how *accurate* the proposed calibration will be, in the context of the specifications governing that accuracy. Unless you know how your load behaves, how can you begin to analyze how well your model (equation) will fit its observed behavior? Someone (customer) will apply your device and complain that the accuracy AT THEIR PARTICULAR OPERATING POINT sucks. Regardless of how accurate it is at "0" and "Pmax" (and P/2). Understand the load, first. This gives you an idea of what *style* of model you should be using. Then, design the calibration procedure to exploit that model as appropriate. E.g., if you have a linear relationship, you know you just need to address offset and span. Higher order models can require more tweaking ESPECIALLY IF THE MODEL IS JUST AN APPROXIMATION to the actual behavior. You need to know where the errors are likely to lie -- both in the circuit's performance AND the model's idea of how it "should" be behaving. Lastly, do yourself (your company) a BIG favor and let the device calibrate itself (esp at run-time, if possible) *or* have a jig that automates the process at Final Test -- it will pay for itself overnight! [E.g., connect device to harness/fixture; invoke magic incantation to start calibration procedure; device TELLS fixture to apply LOAD1; device measures V1; device tells fixture to apply LOAD2; device measures V2; lather, rinse, repeat; device figures out coefficients to fit model to observations as good as possible (using some criteria for "good") and stores calibration parameters -- OR, sounds alarm indicating calibration not possible (FAIL)]
On 9/22/2016 2:12 PM, pozz wrote:
> Il 22/09/2016 16:17, Don Y ha scritto:> [...] > > Until you do, how will you know that this is the CORRECT means of > > compensating your model to agree with your observations? > > I don't need the CORRECT means, but only a sufficiently good means of > compensanting a not ideal system.
But you don't know what that "system" looks like! Until you do, you can't come up with a model that you can authoritatively will represent its behavior at all operating points. Here's a simple model: P(i) = x(i) Associate a value of x with a given value of P. Repeat for as many values of P as you want to track, accurately. The question to then ask is how can I accurately ESTIMATE the actual value of P based on my current observed value of x? If you happen to have a tuple that associates a P value with that particular x value, then you are in luck! ASSUMING THE CALIBRATION DOESN'T DRIFT/ALTER with time, temperature, "wear and tear", etc. Otherwise, you'll have to interpolate by walking the curve defined by the model BETWEEN the two closest calibration points to your current operating point. (you're hoping an exponential is the right shape) How can you decide that you have "a sufficiently good means of compensanting [sic]" if you don't really know how the load behaves in the real world?
On Thu, 22 Sep 2016 23:15:51 +0200, pozz wrote:

> Il 22/09/2016 17:01, Tim Wescott ha scritto: > > [...] >> Assuming you can't do that, the first thing that I'd suggest is to use >> interpolation or a curve fit to a number of measured points. >> Interpolation is easy -- just store a number of calibration points and >> then use linear, quadratic, or cubic interpolation between them. Even >> cubic interpolation should be quicker than using pow. Alternately, fit >> a function y = A + B * x + C * x^2 + D * x^3 to your calibration >> points, and store A, B, C & D in memory. > > Yes, this is a lighter calculation for the MCU, but the calibration > would be much more difficult to the operator. > > Please, take a look at my answer to Don Y for additional details on my > system: I have a digital trimmer.
Assuming that you could go offline for a moment right after calibration, you could choose to have the operator do whatever calibration action you want externally, then compute the values of your coefficients from those results. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com I'm looking for work -- see my website!
Il giorno gioved&igrave; 22 settembre 2016 15:36:12 UTC+2, pozz ha scritto:

> uint16_t power_nominal = 1500; // In Watt > uint16_t volt_nominal; // Volt measured at nominal power > signed uint8_t exp_corr = -100 to +100; > double exp = 2.00 + exp_corr; > > uint16_t volt = adc_convert(...); // Actual volt measure > double alpha = (double)power_nominal / pow((double)volt_nominal, exp); > uint32_t watt = alpha * pow((double)volt, exp);
start using integer math instead of float. Bye Jack
Il 22/09/2016 23:31, rickman ha scritto:
> On 9/22/2016 5:10 PM, pozz wrote: >> Il 22/09/2016 16:17, Don Y ha scritto: >>> On 9/22/2016 6:36 AM, pozz wrote: >>>> I have to convert voltage measure (Volt) into power (Watt). As you >>>> know, the >>>> physics says I need to square the voltage measure. >>>> >>>> I have to calibrate the mathematical law and I have two points: >>>> 0W -> 0V >>>> <nominal power> -> <voltage at nominal power> >>>> >>>> That could be enough, but we noticed a different relation between volt >>>> and watt >>>> at intermediate points. I, as the software engineer, have to try to >>>> compensate >>>> differences from the theory, without increasing complexity during >>>> calibration. >>>> >>>> My idea is to calibrate the exponent: it is normally 2.00, but I can >>>> calibrate >>>> from 1.00 to 3.00. >>>> In this way, the two old calibration points are the same as before. >>>> So the >>>> exponent (the third calibration measure) can be changed at last. >>>> >>>> The problem is pow() function with double arguments takes a lot of >>>> time to >>>> finish. Do you suggest a mathematical method to reduce its complexity? >>>> >>>> >>>> uint16_t power_nominal = 1500; // In Watt >>>> uint16_t volt_nominal; // Volt measured at nominal power >>>> signed uint8_t exp_corr = -100 to +100; >>>> double exp = 2.00 + exp_corr; >>>> >>>> uint16_t volt = adc_convert(...); // Actual volt measure >>>> double alpha = (double)power_nominal / pow((double)volt_nominal, exp); >>>> uint32_t watt = alpha * pow((double)volt, exp); >>>> >>>> >>>> alpha can be pre-calculated, because power_nominal, volt_nominal and >>>> exp are >>>> constant (after calibration). The last instruction is the problem. >>> >>> No, the "problem" lies in your transducer/measurement error. >>> The definition of a "watt" (power) doesn't change just because your >>> observations of that APPARENT relationship (V ~ W) "has issues". >>> >>> Perhaps your load's characteristics are changing as a function >>> of operating point. Or, nonlinearities in your measurement system. >>> Or, ... >>> >>> Ask yourself WHY the exponent needs to be changed. I suggest you >>> don't have an accurate model of your load and its excitation. >>> Until you do, how will you know that this is the CORRECT means of >>> compensating your model to agree with your observations? >> >> >> I know the problem is in the poor quality of the transducer, but I'm >> only in charge of the software and the hardware engineer can't fix it >> (often the software solves hardware issues). >> >> So I need a more complex law. The quadratic law (one parameter) can be >> calibrated with a single measure (nominal value). The generic power law >> (exponent not exactly equals to 2, two parameters) needs two calibration >> measures and has a nice feature: it's very simple to calibrate in two >> steps. >> >> The input section has an hardware calibration, a simple digital trimmer. >> So the first step is to calculate the power from the measured voltage >> with the following formula: >> P = Pn / (Vn ^ 2) * (V ^ 2) >> where Pn is the nominal power and Vn is the voltage needed at nominal >> power. The user increase/decrease the trimmer pot until the correct >> power is displayed. >> >> Second step. Change the power to another value (half of nominal power, >> for example). If the transducer works as in theory, the measured power >> is correct. Otherwise the user increase/decrease the exponent until the >> power displayed is correct. The power is calculated as: >> P = Pn / (Vn ^ exp) * (V ^ exp) >> >> After the second step, we are sure the first calibration point is yet >> valid, because that formula is correct when V=Vn, even if exp isn't 2. >> >> >> If I use the linear law P=AV^2+BV, I think the two calibration steps >> aren't indipendent: the operator should execute two measures, the system >> should save the two couples (P,V) and only after that calculate A and B >> coefficients. >> >> >> It seems to me the exponentiation law is simpler during calibration. > > I don't know that complicating your power calculation is the right way > to go. Even if you do, why do you thing adjusting the exponent is the > right compensation? There are any number of other ways the values you > are measuring could be out.
I know exponentiation could be not the optimum compensation, but I don't need it. The transducer is similar to the theoric model (square law), but it differs from it a little. I need only a mathematical trick to change slightly the shape of the square curve... and keeping simple the calibration of this new shape. I found changing exponent is good in my application, because I'm sure it is exact at three points (0, Pn/2, Pn) and good at other points. I don't need high accuracy in the reading.
> Can you measure the *actual* voltage the transducer is measuring?
Yes.
> How > are you getting the power measurement to compare to your calculations?
Power meter.
> What is the device which is the load for this calculation?
The load is an RF amplifier.
> Rather than fudging the calculation, maybe it is simpler to figure out > how the measurement is out and correct that before you perform the power > calculation.
The measure on the field is similar to the theory (square law). Unfortunately it isn't exactly a square law (don't ask why, I don't know), so I'm finding a mathematical trick to change *a little* the shape of the square law.
Il 22/09/2016 23:44, rickman ha scritto:
> On 9/22/2016 5:10 PM, pozz wrote: >> Il 22/09/2016 16:17, Don Y ha scritto: >>> On 9/22/2016 6:36 AM, pozz wrote: >>>> I have to convert voltage measure (Volt) into power (Watt). As you >>>> know, the >>>> physics says I need to square the voltage measure. >>>> >>>> I have to calibrate the mathematical law and I have two points: >>>> 0W -> 0V >>>> <nominal power> -> <voltage at nominal power> >>>> >>>> That could be enough, but we noticed a different relation between volt >>>> and watt >>>> at intermediate points. I, as the software engineer, have to try to >>>> compensate >>>> differences from the theory, without increasing complexity during >>>> calibration. >>>> >>>> My idea is to calibrate the exponent: it is normally 2.00, but I can >>>> calibrate >>>> from 1.00 to 3.00. >>>> In this way, the two old calibration points are the same as before. >>>> So the >>>> exponent (the third calibration measure) can be changed at last. >>>> >>>> The problem is pow() function with double arguments takes a lot of >>>> time to >>>> finish. Do you suggest a mathematical method to reduce its complexity? >>>> >>>> >>>> uint16_t power_nominal = 1500; // In Watt >>>> uint16_t volt_nominal; // Volt measured at nominal power >>>> signed uint8_t exp_corr = -100 to +100; >>>> double exp = 2.00 + exp_corr; >>>> >>>> uint16_t volt = adc_convert(...); // Actual volt measure >>>> double alpha = (double)power_nominal / pow((double)volt_nominal, exp); >>>> uint32_t watt = alpha * pow((double)volt, exp); >>>> >>>> >>>> alpha can be pre-calculated, because power_nominal, volt_nominal and >>>> exp are >>>> constant (after calibration). The last instruction is the problem. >>> >>> No, the "problem" lies in your transducer/measurement error. >>> The definition of a "watt" (power) doesn't change just because your >>> observations of that APPARENT relationship (V ~ W) "has issues". >>> >>> Perhaps your load's characteristics are changing as a function >>> of operating point. Or, nonlinearities in your measurement system. >>> Or, ... >>> >>> Ask yourself WHY the exponent needs to be changed. I suggest you >>> don't have an accurate model of your load and its excitation. >>> Until you do, how will you know that this is the CORRECT means of >>> compensating your model to agree with your observations? >> >> >> I know the problem is in the poor quality of the transducer, but I'm >> only in charge of the software and the hardware engineer can't fix it >> (often the software solves hardware issues). >> >> So I need a more complex law. The quadratic law (one parameter) can be >> calibrated with a single measure (nominal value). The generic power law >> (exponent not exactly equals to 2, two parameters) needs two calibration >> measures and has a nice feature: it's very simple to calibrate in two >> steps. >> >> The input section has an hardware calibration, a simple digital trimmer. >> So the first step is to calculate the power from the measured voltage >> with the following formula: >> P = Pn / (Vn ^ 2) * (V ^ 2) >> where Pn is the nominal power and Vn is the voltage needed at nominal >> power. The user increase/decrease the trimmer pot until the correct >> power is displayed. >> >> Second step. Change the power to another value (half of nominal power, >> for example). If the transducer works as in theory, the measured power >> is correct. Otherwise the user increase/decrease the exponent until the >> power displayed is correct. The power is calculated as: >> P = Pn / (Vn ^ exp) * (V ^ exp) >> >> After the second step, we are sure the first calibration point is yet >> valid, because that formula is correct when V=Vn, even if exp isn't 2. > > I think your equation is not written in a clear way. I think what you > mean is this... > > P = Pn * (V ^ exp) / (Vn ^ exp)
IMHO, they are identical mathematical expressions.
> Now the equation makes sense to me. But that still doesn't mean it will > give close to correct values anywhere other than the calibration points.
Yes, I have tried and this mathematical law could be ok for my application.
> Have you considered... > > P = Pn * (V / Vn) ^ exp
Again IMHO, this is identical to the above expressions.
> Then there are an infinite set of other corrections you could use. The > question is which ones are more accurate?
I don't need to increase accuracy. I only need a little compensation of the square law. The calibration process of the mathematical model should be simple.
> Have you looked at a range of data to see what the correction curve > needs to be?
Yes, and it is somewhat a square law. In some cases, I need to change the shape of the square law a little.