divide


Closed Thread
Results 1 to 7 of 7

Thread: divide

  1. #1
    Join Date
    May 2012
    Posts
    20

    Talking divide

    hi,i got x as my freq.x changes betwwen 1 and 65535.using pbp how do i divide 1,x to get the freq
    and show the dec result on my lcd?
    thx.

  2. #2
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: divide

    Maybe you can do something like this . . .
    First, find out when x increments by 1, what is increment in frequency (call this the step size)
    Second, find out what is the frequency when x = 1 (call this the minimum frequency).
    Then to find actual frequency from x you can do some math like below:
    actual frequency = minimum frequency + (x * step size)
    Now you can print the actual frequency on the lcd using LCDOUT (assuming you are using a HD44780 based LCD display).

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: divide

    Assuming:
    1) You can use LONG variables
    2) You are looking for the time of each period
    Code:
    Freq VAR LONG  ' Length of time for each period
    
    SELECT CASE x
       CASE = 1
          LCDOUT "001.000 Sec"
       CASE <=1000
          Freq = 1000000/ x
          LCDOUT DEC3 Freq/1000,".",DEC3 Freq," mSec"  
       CASE ELSE
          Freq = 1000000000/ x
          LCDOUT DEC3 Freq/1000,".",DEC3 Freq," uSec" 
    END SELECT

  4. #4
    Join Date
    May 2012
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Re: divide

    hi,x is my frequency and it increments by 1.x changes betwwen 1 and 65535.i want to divide 1,x to get the period and show the period on lcd.i cant use long var.
    what should i do?
    thx
    Last edited by daydream; - 11th May 2012 at 06:28.

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: divide

    Simple answer:
    Because PBP uses integer math, you won't get any meaningful value from 1/x.

    You will need to think in terms of integers and scale your values appropriately.

    The other alternatives is to try the floating point routines found here: http://melabs.com/resources/fp.htm

  6. #6
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: divide

    First of all, use longs because you will need the bit space. Next decide your units that will result in an integer to display. For this example, lets choose ms. Since there are 1000 ms in a second, to get period as whole ms, instead of dividing 1 by x (Hz), divide 1000 by x(Hz) which is the same as (1/x)*1000.
    Obviously, if you want units of us then it's 1,000,000/x. You can see why longs are required.

  7. #7
    Join Date
    May 2012
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Re: divide

    hi steveB,i used the floating point routines and it works,so thanks.

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