Another math problem for PBP


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125

    Question Another math problem for PBP

    I have two 24LC512 chips used in a memory array controlled by an 18F2525. I am trying to compute the %age 'full' the memory chips are together. I can do it in MS Excel, but not in PBP...

    Here is what I am trying to do.

    Chipselect = the chips - can be a '1' or a '2'. (Byte)
    Memperc = %age of memory used (byte)
    Address = current memory pointer (on either chip). Increments in 128 (Word)
    Addrsm = address/1000 (byte)

    When I want to compute memory %age, I use this:

    if chipselect = 1 then
    addrsm = address/1000
    memperc = (addrsm/2)/64 ' 0-50%
    else
    addrsm = address/1000
    memperc = (addrsm+64)/128 '50-100%
    endif


    IN EXCEL, this works fine - for example: lets say Address = 40832 and Chipselect = 2

    Addrsm = 40832/1000 - > gives 40.832
    Chipselect is = '2' so,
    memperc = 40.832+64 = 104.832, /128 = .819

    What I get is '0'.... I want 81.9% so I can display the memory.. REALLY I want to get a number like '819' so I can display using:

    LCDout $fe, L4, "Memory%",#memperc dig 2, #memperc dig 1, ".", dec1 memperc,

    Any PBP Math gurus out there?

    Excel file with how I want it to work is attached.
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Just SCALE everything up so there are NO decimals to get in the way.... for a start, why are you dividing by 1000? Lose it and save some bytes...

    Your example...

    Addrsm = 40832
    Chipselect is = 2

    memperc=Addrsm/128 (answer will be 319 - memperc is a WORD of course)
    If Chipselect=2 then memperc=memperc+500

    You don't need to deal with calculating all of 100% of memory, just calculate the lower 50% block or the upper 50% block, and in the case of the upper block just add 50% to get the final answer. Then to display...

    LCDOut "Memory="
    If memperc>999 then LCDOut #memperc DIG 3
    If memperc>99 then LCDOut #memperc DIG 2
    LCDOut #memperc DIG 1,".",#memperc DIG 0,"%"

    Your display should show "Memory=81.9%" with leading zeros surpressed.

  3. #3
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Thumbs up

    THANK YOU!!! I was too close to the flame to see the answer... Excellent! The only tweak I had was adding a "#" in front of the display digits...

    Tom

Similar Threads

  1. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 04:20
  2. Math problem with string result
    By Lotondo in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 15th November 2006, 10:06
  3. PicBasic Pro Math Problem??
    By Glen65 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th March 2006, 04:36
  4. Math Formula / Variable Problem! Help!
    By bwarp in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th February 2006, 07:59
  5. Math problem...with picbasic pro
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th October 2005, 19:28

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