Maths Querry

1. ## 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. 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

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

4. 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)

Al.
Last edited by aratti; - 10th March 2010 at 06:17.

5. 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.

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. Originally Posted by rsocor01
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. ## Re: Maths Querry

Originally Posted by aratti
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)

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)

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

8. ## 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)

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.

#### Posting Permissions

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