Exponential Operator


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Posts
    7

    Default Exponential Operator

    Hello,
    Is there a math operator in PicBasic Pro for raising one number to the power of another?
    I can't seem to find one.

    I would expect it to be:

    a = 2^4 ' answer is 16
    or EXP()
    or POW()

    but none of these seem to be documented for PBP.
    Thanks
    -Andrew

  2. #2


    Did you find this post helpful? Yes | No

    Default Maths operators

    Microcontrollers have limited resources and generally are not efficient for floating point or exponential operations. PBP is an integer basic that makes good use of limited devices. You can get integer exponential functions by repeated multiplication and with the new LONG variables on PBPL you can probably get reasonable results by scaling but you will need to devise the functions yourself.

    Working with floating point (in Mikroelktronica or Proton+) or longs with PBPL will devour code space.

    What are you doing that needs exponentials? There may be an alternative solution.

    HTH
    Brian

  3. #3
    Join Date
    Oct 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Exponential Operator

    Thank you for confirming my fear.

    I'm using a PIC16F877 to control some MAX7219 LED display chips.
    I'm trying to access 6 different rows of LED's in succession.

    To light up an LED in a column you do this:
    row 1 = %0001
    row 2 = %0010
    row 3 = %0100
    row 4 = %1000
    etc.

    I just wanted to convert between #4 and %1000 with a single line of code.
    Ideally, I wanted to make it a part of the FOR statement in a loop.
    You can see below the code I ended up using instead of the invalid: STEP 2^Row

    PBP code fragment follows:
    ********************
    Row VAR BYTE
    Light1 VAR WORD
    Column VAR WORD

    FOR Row = 1 to 64 STEP Row*2-row
    Light1 = Column + Row
    LOW Load
    SHIFTOUT DOUT, CLK, 1,[Light1\16] 'send command to LED chip
    HIGH Load
    NEXT Row
    ****************

    -Andrew

  4. #4
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default Not sure but...

    Have you looked at the shift functions >> and << around page 32 in the PBP manual?
    row 1 = %0001
    row 2 = %0010
    row 3 = %0100
    row 4 = %1000
    If you want a byte or word to do the above thing this might work:

    X var Byte
    Y var Byte

    Y=1 'Now Y=%00000001
    For x=0 to 6 Step 1
    Y=Y << 1 'Shift Y left one time, Y=%00000010,Y=%00000100,Y=%00001000
    Next x

    This command is also usefull when combining nibbles and other stuff, shift happily left or right as you see fit.
    Last edited by sinoteq; - 26th October 2007 at 03:25.

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


    Did you find this post helpful? Yes | No

    Default

    >> I just wanted to convert between #4 and %1000 with a single line of code.

    B0 = DCD 3 ‘ Sets B0 to %00001000

    (see PBP manual for full details)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    Join Date
    Oct 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default What is PBPL?

    Thank you Sinoteq
    I checked that out.
    I think I can even do this:

    Y=1 'Now Y=%00000001
    x = 6
    Y=Y << x

    And thank you Paul,
    I'll look into DCD.

    By the way, what is PBPL?

    -Andrew

Similar Threads

  1. what is objective of this operator "*/" ?
    By iugmoh in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th April 2008, 02:43
  2. Exponential
    By civicgundam in forum General
    Replies: 8
    Last Post: - 3rd February 2008, 17:19
  3. '*/' operator
    By jblackann in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th January 2007, 20:00
  4. math operator LOG
    By Eyal in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd July 2004, 23:45
  5. Log and exponential
    By anj in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2004, 20:03

Members who have read this thread : 0

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