Sin
Syntax
Assignment Variable = Sin(pVariable)
Overview
Deduce the Sine of a floating point value
Parameter
pVariable can be a constant, variable or expression that requires the Sine extracted. The value expected and returned by Sin is in radians. Assignment Variable can be any valid variable type.
Example
Device = 18F26K40
' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600
' Set the Baud rate for HRsoutLn
Dim Floatin as Float
' Holds the value to Sin
Dim Floatout as Float
' Holds the result of the Sin
Floatin = 123.0
' Load the variable
Floatout = Sin(Floatin)
' Extract the Sin of the value
HRsoutLn Dec Floatout
' Display the result
Stop
Notes
With 12, and 14-bit core devices, Sin returns the 8-bit sine of a value, compatible with the BA- SIC Stamp syntax. The result is in two's complement form (i.e. -127 to 127). Sin starts with a value in binary radians, 0 to 255, instead of the customary 0 to 359 degrees.
However, with the extra functionality, and more linear memory offered by the 18F devices, full 32-bit floating point Sine is implemented.
Floating point trigonometry is extremely 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 = (Sin(MyVar1)) + MyVar2