Positron Compiler Documentation

Atan2

Positron16 · Revision 1.1.3.5 · PDF page 98

Assignment Variable = Atan2(yVariable, xVariable)

Deduce the arc tangent of 32-bit floating point y/x.

y Variable can be a constant, variable or expression that requires the arc tangent (Inverse Tangent) extracted. The value expected and returned by the floating point Atan2 is in radians. x Variable can be a constant, variable or expression that requires the arc tangent (Inverse Tangent) extracted. The value expected and returned by the floating point Atan2 is in radians. Assignment Variable can be any valid variable type.

Device = 24FJ64GA002           ' Select the device to compile for
Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz

Declare Hserial_Baud = 9600    ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1

Dim FloatIn1 as Float
Dim FloatIn2 as Float

Dim FloatOut as Float           ' Holds the result of Atan2

PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

FloatIn1 = 3
FloatIn2 = 3.4

FloatOut = Atan2(FloatIn1, FloatIn2) ' Extract the Atan2 of the values
HrsoutLn Dec FloatOut           ' Display the result on a serial terminal

FloatIng point trigonometry is rather memory hungry, so do not be surprised if a large chunk of the microcontroller’s code memory is used with a single operator. This also means that floating point trigonometry is comparatively slow to operate.

When implementing trigonometry, or other built in, functions within an expression, always wrap them in parenthesis, otherwise the parser may consider the extra operands as part of the trigonometry parameter and produce an incorrect result. For example:

MyAssignment = (Atan2(MyVar1, MyVar2)) + (Tan(MyVar3))
View original PDF page 98Open page in PDFOriginal PDF page 98