PDA

View Full Version : Logarithm in PBP



savnik
- 25th March 2007, 19:36
I have one voltage which vary logarithmical.
How change the code below to show voltage on LCD in logarithm.(not linearity)



loop:
ADCIN 0, adval ' Read channel 0 to adval (0-1023)

adval = (adval */ 500)>>2 ' equates to: (adval * 500)/1024

LCDOut $fe,1,"DC Volts= "
LCDOut DEC adval/100,".", DEC2 adval ' Display the decimal value
Pause 500 ' Wait .5 second

GoTo loop ' Do it forever

mackrackit
- 25th March 2007, 20:07
I searched the form for logarithm and found this,
http://www.picbasic.co.uk/forum/showthread.php?t=585&highlight=Logarithm

savnik
- 28th March 2007, 06:19
anyone to know to help me

Jerson
- 28th March 2007, 07:57
Build a table containing log values derived from a HLL running on a PC. Embed this table into your program. You could use maybe 10, maybe 50 points in the table and interpolate between them to get a log reading. This method is not precise but workable since I assume you only need to visualise the log reading on a display. For precise log values, you have to do it the hard way.

Jerson

Acetronics2
- 28th March 2007, 09:01
Hi, Savnik

Jerson is right ... the simplest Pic way is to build a retrieving table.

IN PbP that's called LOOKDOWN2 ... ( catches the closest values, sup and inf ... just think to use a clever index !!! )

Then just have to add a linear approx. between table values ...


Buuuuuut, My old brain tells me it is very easy to do it with 3or4 couples of linearising resistors and diodes ...

or to use a logarithmic AOP !!!

Last and simplest solution: The App Notes of ICL 7106 or 7136 show a logarithmic scale design ...

Which is closest to your requirements ??? ...

Alain

savnik
- 28th March 2007, 10:31
Hi, Savnik

Jerson is right ... the simplest Pic way is to build a retrieving table.

IN PbP that's called LOOKDOWN2 ... ( catches the closest values, sup and inf ... just think to use a clever index !!! )

Then just have to add a linear approx. between table values ...


Buuuuuut, My old brain tells me it is very easy to do it with 3or4 couples of linearising resistors and diodes ...

or to use a logarithmic AOP !!!

Last and simplest solution: The App Notes of ICL 7106 or 7136 show a logarithmic scale design ...

Which is closest to your requirements ??? ...

Alain
I have make a table.
I want to measure the volts at the input of pic , and show on LCD the power


POWER VOLT POWER VOLT
1 7,1 26 36,1
2 10,0 27 36,7
3 12,2 28 37,4
4 14,1 29 38,1
5 15,8 30 38,7
6 17,3 31 39,4
7 18,7 32 40,0
8 20,0 33 40,6
9 21,2 34 41,6
10 22,4 35 41,8
11 23,5 36 42,4
12 24,5 37 43,0
13 25,5 38 43,6
14 26,5 39 44,2
15 27,4 40 44,7
16 28,3 41 45,3
17 29,2 42 45,8
18 30,0 43 46,4
19 30,8 44 46,9
20 31,6 45 47,4
21 32,4 46 48,0
22 33,2 47 48,5
23 33,9 48 49,0
24 34,6 49 49,5
25 35,4 50 50,0

Acetronics2
- 28th March 2007, 10:56
May I suppose the number in the "Power" column has to be displayed ... or is it just your Index ???

In this case ... It would be much easier to use if the "Volts" were integers numbers and "Power" decimals ... I know: some more work for you !!!

Alain

See Also Here : http://curveexpert.webhop.net/

That Helps ... isn't it ???

Quadratic Fit: y=a+bx+cx^2 ( y: Power ; x :Voltage )
Coefficient Data:
a = 0.00076569488
b = -8.0880958e-005
c = 0.019999816

savnik
- 28th March 2007, 12:53
May I suppose the number in the "Power" column has to be displayed ... or is it just your Index ???

In this case ... It would be much easier to use if the "Volts" were integers numbers and "Power" decimals ... I know: some more work for you !!!

Alain

See Also Here : http://curveexpert.webhop.net/

That Helps ... isn't it ???
I display only the volts

Acetronics2
- 28th March 2007, 13:11
I display only the volts

read from previous posts :

<< I want to measure the volts at the input of pic , and show on LCD the power >>

Could you give me a decent explanation ???

Alain

savnik
- 28th March 2007, 14:36
read from previous posts :

<< I want to measure the volts at the input of pic , and show on LCD the power >>

Could you give me a decent explanation ???

Alain

I have a linear for FM and i want to measure the power.
From the power meter i take the indication which is in volt.This volt i want to show on LCD. But the power change in logarithm scale and this is my problem.

Acetronics2
- 28th March 2007, 16:42
This volt i want to show on LCD.

> Where's the problem, then, If you only want to display the voltage ???


But the power change in logarithm scale and this is my problem.

> This needs some USEFUL enlightments ... if you do not need to display the Power !!!

> Do you want to display Voltage in dBv ???

> Do you want to display Voltage in some BARGRAPH mode ??? ...

those ONLY could give any sense to your question !!!

Alain

savnik
- 28th March 2007, 16:55
This volt i want to show on LCD.

> Where's the problem, then, If you only want to display the voltage ???


But the power change in logarithm scale and this is my problem.

> This needs some USEFUL enlightments ... if you do not need to display the Power !!!

> Do you want to display Voltage in dBv ???

> Do you want to display Voltage in some BARGRAPH mode ??? ...

those ONLY could give any sense to your question !!!

Alain
My english is not so good.
I want the voltage which measure with the pic , to show on lcd in dBm or dBv or watt (the table which post in #6)

ronsimpson
- 28th March 2007, 21:54
Savnik,

You need to get a book on basic electronics. Voltage Current Power and Resistance.
Power = voltage * current
In your case you can not see the current so: Power = Voltage * Voltage /Resistance (Voltage squared)
To prove that look at your table. Voltage of 22.4 volts = 10 watts and Voltage of 44.7 volts = 40 watts. Voltage increases 2:1 and power increases 4:1. That proves there is a voltage squared * constant.

Voltage * Voltage/50 = Power

To convert to db is very hard or very simple depending on how you look at it. You can fight BIG math for weeks. When you understand db it is almost as simple as finding Power. I will not tell you how now. You need to think about it for a while.

RonS.

Pic_User
- 29th March 2007, 03:33
Hi Savnik,

If I read your problem correctly:


I have a linear for FM and i want to measure the power.
From the power meter i take the indication which is in volt. This volt I want to show on LCD. But the power change in logarithm scale and this is my problem.

My english is not so good.
I want the voltage which measure with the pic , to show on lcd in dBm or dBv or watt (the table which post in #6)
You have a RF amplifier that has an analog power meter. The power meter reads a voltage and displays the power on a Logarithmic scale. The input, to move the meter, is voltage. The scale painted on the meter face is logarithmical.

You need the PIC’s adc input to read the DC voltage running the meter and then using mathematics or a “look-up” table convert the voltage to the equivalent power in Watts. You have already calculated the table, posted in your previous post.

Is this close to the question? I am just trying to help with clarifying the question. Sorry I don’t have an answer for you.

-Adam-

savnik
- 29th March 2007, 05:00
Hi Savnik,

If I read your problem correctly:


You have a RF amplifier that has an analog power meter. The power meter reads a voltage and displays the power on a Logarithmic scale. The input, to move the meter, is voltage. The scale painted on the meter face is logarithmical.

You need the PIC’s adc input to read the DC voltage running the meter and then using mathematics or a “look-up” table convert the voltage to the equivalent power in Watts. You have already calculated the table, posted in your previous post.

Is this close to the question? I am just trying to help with clarifying the question. Sorry I don’t have an answer for you.

-Adam-
Yes, it is my question.

savnik
- 29th March 2007, 05:16
Savnik,

You need to get a book on basic electronics. Voltage Current Power and Resistance.
Power = voltage * current
In your case you can not see the current so: Power = Voltage * Voltage /Resistance (Voltage squared)
To prove that look at your table. Voltage of 22.4 volts = 10 watts and Voltage of 44.7 volts = 40 watts. Voltage increases 2:1 and power increases 4:1. That proves there is a voltage squared * constant.

Voltage * Voltage/50 = Power

To convert to db is very hard or very simple depending on how you look at it. You can fight BIG math for weeks. When you understand db it is almost as simple as finding Power. I will not tell you how now. You need to think about it for a while.

RonS.
I am a electronic for 30 years.
Thank you for your help. You give me some idea how to calculate.

mackrackit
- 29th March 2007, 10:06
Savnik,

Your problem has been bugging me, I like math puzzles, and the post by Pic_User did clear things up.

Now if I understand your table correctly, POWER column is the reading you want and the VOLT column is the value you now have. If this is correct, then keep reading, if not than ...

This is the formula:

Step #1:

D = (VOLTS / 10) * 0.2 'D' is a dummy variable

Step #2:

POWER = VOLTS * D

This give an answer within .1 of the value in the power column.

Hope this helps.

mackrackit
- 29th March 2007, 10:19
I look back and see that ronsimpson said the same thing.

Now you have two ways to do it. :)

ronsimpson
- 29th March 2007, 13:51
P=v*d, D=(v/10)*.2

P=v*((v/10)*.2)

P=v*v*.2/10

P=v*v/50

mackrackit
- 29th March 2007, 14:21
P=v*d, D=(v/10)*.2

P=v*((v/10)*.2)

P=v*v*.2/10

P=v*v/50
I was looking at a way to change one set of numbers into another. Did not pay attention to your post or think in electrical terms. Just MATH. NUMBERS DO NOT LIE. NOT OFTEN:)

ronsimpson
- 29th March 2007, 14:41
You must be an Engineer not a Lawyer or Statistician. On subject; I need to get back to taxes.
Fuzzy logic (fuzzy math)

mackrackit
- 29th March 2007, 17:19
You must be an Engineer not a Lawyer or Statistician. On subject; I need to get back to taxes.
Fuzzy logic (fuzzy math)

Just an old farm boy having fun.

savnik
- 30th March 2007, 05:47
I use this code to read the forwardpower


ADCIN 0, adval ' Read channel 0 to adval
dummy = adval * 5 * 10 ' Multiply to load internal registers with 32-bit value
value = Div32 1023 ' Divide 32-bit value by word and store in word
forwardpower = (value*value)/50


and this for reflected power


ADCIN 1, adval1 ' Read channel 0 to adval
dummy1 = adval1 * 5 * 10 ' Multiply to load internal registers with 32-bit value
value1 = Div32 1023 ' Divide 32-bit value by word and store in word
reflectedpower = (value1*value1)/50


and the type for SWR is:

..........1 + square root(reflectedpower/forwardpower)
SWR = --------------------------------------------
..........1 - square root(reflectedpower/forwardpower)

Any help how to show the SWR on LCD;

paul borgmeier
- 30th March 2007, 08:27
The largest ADVAL1 can be is 1023
The largest dummy can be is 1023 * 5 * 10 = 51150 (which is 16 bits or less)

Why do you do the * 5 * 10, why not * 50? and why *50?
You do not need DIV32 since you never exceed 16 bits with dummy

The same goes for ADVAL calcs

In final form, your
RP = (ADVAL1*50/1023)^2/50
FP = (ADVAL*50/1023)^2/50

If you plug these into your SWR equation and reduce, you get

SWR = (ADVAL1+ADVAL)/(ADVAL1-ADVAL), which should be easy to deal with

However, with all this noted, I do not think you are going to get what you want ... or will you? I haven't yet tried to follow this thread in any depth.

savnik
- 30th March 2007, 13:24
The largest ADVAL1 can be is 1023
The largest dummy can be is 1023 * 5 * 10 = 51150 (which is 16 bits or less)

Why do you do the * 5 * 10, why not * 50? and why *50?
You do not need DIV32 since you never exceed 16 bits with dummy

The same goes for ADVAL calcs

In final form, your
RP = (ADVAL1*50/1023)^2/50
FP = (ADVAL*50/1023)^2/50

If you plug these into your SWR equation and reduce, you get

SWR = (ADVAL1+ADVAL)/(ADVAL1-ADVAL), which should be easy to deal with

However, with all this noted, I do not think you are going to get what you want ... or will you? I haven't yet tried to follow this thread in any depth.
I use adval * 5 * 10 , because adval * 5 is to show on lcd
the volts from 0 to 5v and 10 is multiplier to show on lcd 0 to 50v