Fixed-point math with trig functions in SPIN

Warning message

The Propeller Object Exchange system is decommissioned and replaced with a GitHub repository to house the same existing and future Propeller objects. As of 12/5/2019, this site is read-only. You can continue to browse and download objects from here for a limited time; however, please begin using the Parallax Propeller repository for future reference.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Request group membership
By: created: 2013-04-05 | updated: 2013-04-05


The PST application shows the first Fixed-point arithmetic library object on OBEX. The "SPIN_TrigPack" object is a complete Fixed-point package with the basic trigonometric functions for robot and navigation projects. You can do ATAN2 without enlisting extra COGs to run a full Floating-point library for that function. This small object has string conversion utilities to make Fixed-point math easy in your SPIN language based applications.
The object contains the first True Random Generator with the Propeller microcontroller written in SPIN code only. This TRNG will repeat its sequence only after the end of Times. Nobody knows why does it work. Maybe, you will be the first to find out.
Original File Upload
Package icon SPIN_TrigPack_Demo_-_Archive__Date_2011.10.17__Time_11.11.zip36.4 KB


[originally posted by Anonymous on 2011-09-23 16:28:57] Found a bug in the sin calc. At exactly 90 and 270 degrees. I changed the fundamental sin calc as follows: CASE (iA & %1_1000_0000_0000) %0_0000_0000_0000: '1st quadrant [0, 90] RETURN WORD[_BASE_SINTABLE][iA & $7FF] %0_1000_0000_0000: '2nd quadrant [90, 180] if (iA & $7FF) RETURN WORD[_BASE_SINTABLE][-iA & $7FF] else RETURN WORD[_BASE_SINTABLE][$7FF] %1_0000_0000_0000: '3rd quadrant [180, 270] RETURN -WORD[_BASE_SINTABLE][iA & $7FF] %1_1000_0000_0000: '4th quadrant [270, 380] if (iA & $7FF) RETURN -WORD[_BASE_SINTABLE][-iA & $7FF] else RETURN -WORD[_BASE_SINTABLE][$7FF]