PDA

View Full Version : Maths help for the terminally dim please



retepsnikrep
- 14th December 2010, 16:36
I have some OEM hardware and code which produces a word variable containing a current value.
Lets say for this example it's 100 amps.

Now I have modified the hardware so that although 100amps is flowing the hardware only sees
75% of the current so the value in the variable is now 75. A 25% reduction

But what I want is for my gizmo to report the actual current by adding on the 25% to get back to 100amps

How can I do that with the word variable? Multiplication factor?

Adding on 25% to 75 does not give 100 of course so how can I do this?

The variable can be between 0 and 10,000.

aratti
- 14th December 2010, 16:55
multiply your value for 1.333.

Dammy var word

YourValue var word

NewValue var word


Dammy = yourValue * 1333
NewValue = DIV32 1000

NewValue will contain the 4/4 from the 3/4 given in yourValue.

or another way is

multiply yourvalue by 4 and divide by 3
Dummy = YourValue * 4000
NewValue = DIV32 3000

Cheers

Al.

retepsnikrep
- 14th December 2010, 17:29
Thanks very much. Easy when you know how.

retepsnikrep
- 14th December 2010, 18:50
And for a 16% reduction?

rmteo
- 14th December 2010, 18:57
And for a 16% reduction?
Multiply by 1.1905

retepsnikrep
- 14th December 2010, 19:09
Thanks. Sorted now.

aratti
- 14th December 2010, 19:39
In case you will need other percentages, here how to calculate the multiplier:


Multiplier = 1 +( % / (100-%) )

where % is your value.

Example:

1 + ( 16 / (100 - 16) = 1 + (16/84) = 1 + 0.19047619 = 1.19047619 rouded 1.1905

Cheers

Al.

retepsnikrep
- 16th December 2010, 23:05
Thanks for the formula as well. Now i know how to do it :)

retepsnikrep
- 4th July 2013, 15:46
Another maths question.

I have an adc connected to a HV supply via a non linear isolation circuit.

It produces the below 10bit ADC readings at the given input voltage.
That works fine but i want to create a formula from these data points to allow the adc to produce the actual voltage.
I don't want to use a lookup table if possible.
Accuracy to 1V is acceptable. There should be enough adc resolution to do that with the right formula.

225v = 356
200v = 380
175v = 412
150v = 450
125v = 495
100v = 561
75v = 644
50v = 753
25v = 903
10v = 1000
5v = 1020
0v = 1023

How to convert that data into some sort of forumla to produce the voltage from a given adc reading.
It's not linear.

Thanks

Acetronics2
- 6th July 2013, 17:58
3rd degree Polynomial Fit: y=a+bx+cx^2+dx^3...
Coefficient Data:
a = 7.84284692277E+002
b = -2.42579262304E+000
c = 2.77307340820E-003
d = -1.12332698305E-006

or

Heat Capacity Model: y=a+bx+c/x^2
Coefficient Data:
a = 8.77447057194E+001
b = -1.01937213402E-001
c = 2.18878991436E+007


or use a retrieve table plus 2nd order approx.


Accuracy to 1V is acceptable

did you notice 1v is ... 0.5% ???
surely not !!!

Alain

wdmagic
- 7th July 2013, 12:55
Alain, hes basically got a circuit for mesuring voltage using a voltage divider so that the voltage going into the ADC is a fraction of what is going into the voltage divider. I have near the same type of setup, I have a circuit measuring my AC wall voltage, I have to rectify it first using a bridge rectifier, and add a capacitor to that and then a load resistor to discharge the cap. that gets me about 170 VCD, I dont want to put that into a ADC channel but I can use a POT or 2 resistors to define the proportion of that voltage that I want to read and then do some math to make the PIC appear to read the higher voltage, the problem you have to watch out for is to set up the voltage divider so that your max reading is still lower than your max input (5 volts) since there could be voltage spikes that are well above what your wanting to read. a possible option is to use a zener diode 5.1v on the actual ADC pin to help voltage spikes, but this doesnt cover 100%. He alread said though that he is on a isolated circuit so that helps. my only question is why is it non linear? Im not sure of his circuit but he should be able to get a 95% or greater linear reading using a voltage divider, he could even use a multiturn pot to tune the voltage to his circuit (code math) if theres a minor discrepency. his accuracy is based on the Mathamatical voltage and his ADC resolution, at 10 bits his 5 Volt ADC is 5v/1024 there are huge amounts of sample code for voltmeters out there, but even if we use his voltage numbers and add a bit for possible voltage spikes, lets use 377Volts as the max (5 volts acutual) then we just do the math 377/1024, this is going to give approx a .3% accuracy, but its still going to be innacurate if his circuit is non linear. i would look at the circuit and try to figure out a way to make it virtually linear. otherwise its going to be very hard to get the math and reality to line up together.

Acetronics2
- 7th July 2013, 17:00
did you notice 1v is ... 0.5% ???
surely not !!!



what I mean is it will be impossible to get 1 v precision over the full measuring range ... due to the very poor resolution @ low and high voltage.

Alain

wdmagic
- 7th July 2013, 19:15
yes i see what you mean, sorry i meant that he would have no problem if he was using a voltage divider, and using most or all of the ADC voltage scale for the conversion. not sure what kind of circuit hes using for his input. but anything thats not linear is a pain in the (BEEP)