Maths Querry


Closed Thread
Results 1 to 8 of 8

Thread: Maths Querry

  1. #1
    Join Date
    Oct 2008
    Posts
    51

    Default Maths Querry

    Hi everone ive just been looking through the manual and trying to figure out a way to do an equation but i cant see anyway to do it within pbp!

    The problem im having is i need to use inverse sin ( sin-1) for the following equation:

    sin-1 ((v-v0)/(v1-v0))

    Also another quick question. When the ADCIN command is used if a 1v input is on the pin what would the value read in be in the code?

    One last one when using servos im using the SEROUT command what is the value which you place in the serout? is it ms of the high signal eg high for 150mS?

    Sorry for all the questions!
    Cheers chris!

  2. #2
    Join Date
    Feb 2010
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Do things in parts

    1.- v-v0 = x
    2.- v1-v0 = x1
    3.- x/x1 = x2
    4.- sin-1(x2)

    that'll be your answer. Since i'm a beginner i dunno how to do sin-1, the only thing i can tell you that

    y = sin (x)

    x = arcsin (y)

    and yes,
    x = arcsin (sin (x))

    but out of there nothing to say

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I don't understand your question about the servo - but

    RE: ADC -

    The value returned by the ADC will be (Vin/Vref) * ( ( 2^n)-1) Where N = the number of bits of your ADC.

    And example: If you are using 5V for Vref and Vin = 1V and you are using a 10 bit ADC, then the count will be 205
    Charles Linquist

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    The problem im having is i need to use inverse sin ( sin-1) for the following equation:
    Inverse sin is not possible with PBP but inverse tan yes (I am sure to have seen an example (ATN2) given by Darell sometime ago).

    In this case you can just manipulate a bit your equation to obtain the tangent, since:

    SIN = PERP./HYP. (where: (v-v0) = PERP. and (v1-v0) = HYP.)

    TAN= PERP./BASE (where: (v-v0) = PERP. and SQR((v1-v0)^2 - (v-v0) ^2) = BASE)

    so:

    ATN2 ((v-v0)/SQR((v1-v0)^2 - (v-v0) ^2))

    should give you your angle (I don't remember if in degrees or in radiants)

    Edited: See also this link:http://www.picbasic.co.uk/forum/show...ighlight=angle

    Al.
    Last edited by aratti; - 10th March 2010 at 06:17.
    All progress began with an idea

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default

    chrisshortys,

    You can get the angle with the formula provided by aratti. However, you are going to need PBP version 6.0 for that. If you don't have v6.0, then depending on the accuracy that you want you can use a LOOKUP table.

    About your second questions, do a search in this forum for ADCIN and you will find several treads that will answer your question.

    ATN2 ((v-v0)/SQR((v1-v0)^2 - (v-v0) ^2))

    should give you your angle (I don't remember if in degrees or in radiants)
    aratti,

    I believe the angle is given in binary radians, 0 to 255, that would be the equivalent to 0 to 360 degrees.

    Robert

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rsocor01 View Post
    chrisshortys,

    You can get the angle with the formula provided by aratti. However, you are going to need PBP version 6.0 for that. If you don't have v6.0, then depending on the accuracy that you want you can use a LOOKUP table.
    Robert
    You could use a lookup table. But if you need more accuracy, you could use the Arrati's formula, and the cordic linked in his response http://www.picbasic.co.uk/forum/show...ighlight=angle, and either v2.60 in pbpl mode, or use a 16 or 32 bit square root function located here: http://www.picbasic.co.uk/forum/showpost.php?p=73685 (which is pretty much microchips TB040 located here http://ww1.microchip.com/downloads/e...tes/91040a.pdf )

    By the way, version 2.60 is a very nice upgrade, and worth every penny.
    Last edited by ScaleRobotics; - 10th March 2010 at 16:58.

  7. #7
    Join Date
    Oct 2008
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: Maths Querry

    Quote Originally Posted by aratti View Post
    Inverse sin is not possible with PBP but inverse tan yes (I am sure to have seen an example (ATN2) given by Darell sometime ago).

    In this case you can just manipulate a bit your equation to obtain the tangent, since:

    SIN = PERP./HYP. (where: (v-v0) = PERP. and (v1-v0) = HYP.)

    TAN= PERP./BASE (where: (v-v0) = PERP. and SQR((v1-v0)^2 - (v-v0) ^2) = BASE)

    so:

    ATN2 ((v-v0)/SQR((v1-v0)^2 - (v-v0) ^2))

    should give you your angle (I don't remember if in degrees or in radiants)

    Edited: See also this link:http://www.picbasic.co.uk/forum/show...ighlight=angle

    Al.
    So over a year and a half has passed and suddenly i am back in the same position i was in before. Due to personal reasons i had to drop out of the college course i was doing and now i am back on it again... so ive picked up the demo of the new PBP and am finally about to try this out!

    The first thing i notice is an issue with the equation "ATN2 ((v-v0)/SQR((v1-v0)^2 - (v-v0) ^2))"
    As far as i can find ATN2 does not exist in the manual and throws back errors in the compiler! After looking into this I believe you meant to use just ATN? the second question i would have if this is correct would be the positioning of the ATN command. As i cannot get to my practical equipment until later this week would you be able to read this and see if i am on the correct road please:

    Perp = v - v0
    Base = SQR((v1-v0)^2 - (v-v0) ^2) = BASE)
    Rad = Perp/Base

    Any guidance would be greatly appreciated! It can be hard to get the brain to start going over all these things again!

  8. #8
    Join Date
    Oct 2008
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: Maths Querry

    Sorry I messed up the last bit there, my suggested code should of in fact read:

    Perp = v - v0
    Base = SQR((v1-v0)^2 - (v-v0) ^2)
    Rad = Perp ATN Base

    Also I believe the following to be true to convert Binary Radians to Degrees: multiply radians by 180/pi or 57.3. Could anyone confirm this?

    Thanks!
    Last edited by chrisshortys; - 24th September 2011 at 18:23.

Similar Threads

  1. Simple Maths Going Wrong
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 43
    Last Post: - 27th May 2010, 10:01
  2. ADCIN > HPWM but with min/max limits - i failed maths
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th November 2009, 03:02
  3. Maths - Summing small numbers with decimals
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd March 2008, 20:21
  4. dec number to show on lcd (maths)
    By savnik in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 20:18
  5. Averaging & 16 maths
    By paul.mcallister in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2005, 19:17

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