View Full Version : Maths Querry
chrisshortys
- 9th March 2010, 21:02
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!
lugo.p
- 9th March 2010, 23:16
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
Charles Linquis
- 10th March 2010, 00:26
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
aratti
- 10th March 2010, 04:44
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/showthread.php?t=10528&highlight=angle
Al.
rsocor01
- 10th March 2010, 13:53
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
ScaleRobotics
- 10th March 2010, 15:56
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/showthread.php?t=10528&highlight=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/en/AppNotes/91040a.pdf )
By the way, version 2.60 is a very nice upgrade, and worth every penny.
chrisshortys
- 24th September 2011, 16:44
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/showthread.php?t=10528&highlight=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!
chrisshortys
- 24th September 2011, 17:15
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!
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.