Logarithm in PBP


Closed Thread
Results 1 to 25 of 25
  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default Logarithm in PBP

    I have one voltage which vary logarithmical.
    How change the code below to show voltage on LCD in logarithm.(not linearity)

    Code:
    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

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I searched the form for logarithm and found this,
    http://www.picbasic.co.uk/forum/show...ight=Logarithm
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    anyone to know to help me

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    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
    Code:
    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

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question

    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
    Last edited by Acetronics2; - 28th March 2007 at 13:05.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    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

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question ???????????????????????????????????

    Quote Originally Posted by savnik View Post
    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    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.

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question What do you really want to do ???

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    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)
    Last edited by savnik; - 28th March 2007 at 16:58.

  13. #13
    Join Date
    Oct 2005
    Location
    Loveland CO USA
    Posts
    83


    Did you find this post helpful? Yes | No

    Smile voltage to power simple math

    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.

  14. #14
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile

    Hi Savnik,

    If I read your problem correctly:

    Quote Originally Posted by savnik View Post
    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-
    Ohm it's not just a good idea... it's the LAW !

  15. #15
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Pic_User View Post
    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.

  16. #16
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ronsimpson View Post
    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.

  17. #17
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  18. #18
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I look back and see that ronsimpson said the same thing.

    Now you have two ways to do it.
    Dave
    Always wear safety glasses while programming.

  19. #19
    Join Date
    Oct 2005
    Location
    Loveland CO USA
    Posts
    83


    Did you find this post helpful? Yes | No

    Thumbs up Power=power

    P=v*d, D=(v/10)*.2

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

    P=v*v*.2/10

    P=v*v/50

  20. #20
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ronsimpson View Post
    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
    Dave
    Always wear safety glasses while programming.

  21. #21
    Join Date
    Oct 2005
    Location
    Loveland CO USA
    Posts
    83


    Did you find this post helpful? Yes | No

    Question Numbers Do Not Lie.

    You must be an Engineer not a Lawyer or Statistician. On subject; I need to get back to taxes.
    Fuzzy logic (fuzzy math)

  22. #22
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ronsimpson View Post
    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.
    Dave
    Always wear safety glasses while programming.

  23. #23
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    I use this code to read the forwardpower
    Code:
        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
    Code:
        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;
    Last edited by savnik; - 30th March 2007 at 05:50.

  24. #24
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile Fuzzy Math Approach?

    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.
    Last edited by paul borgmeier; - 30th March 2007 at 08:46. Reason: reduced equation further
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  25. #25
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier View Post
    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

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. Extensions to PBP variables
    By John_Mac in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd October 2009, 05:21
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. PBP / XP Crash
    By pondindustrial in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th November 2005, 03:16

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts