In SX Microcontrollers, SX/B Compiler and SX-Key Tool, rmayhew wrote: [3]I received an E-Mail indicating that the Cordic simulation didn't make sense and didn't seem to work.[/3]

[3]I renamed some of the variables to help to understand this subroutine[/3] [3][/3] [3] [/3] [3]XY_CIRCLE: is the start of the Cordic Algorithm. The quadrant is changed to Quadrant I but whatever the quadrant your in is flagged for restoration at the end of the subroutine.[/3] [3] [/3] [3]The idea is to dither the current angle ADDING AND SUBTRACTING the Cordic data, the data in this case is "(2 PI Radians) * 2 * 10,000" for an integer value of 62832 which is my circle. It data is calculated in a manor that it is done in powers of two which fits into binary shifts.[/3] [3] [/3] [3]Y = length of radius of the circle and X = 0[/3] [3] [/3] [3]Y and X then follow the Cordic angle as it dithers. The result is a skewed and WILL be normalized. Fortunately it is a linear skew which is known as a Cordic Gain and is corrected by multiplying X Y by ** 39797 or (39797/65536)=0.6072540283203125 (The SX/B Program makes it so easy!)[/3] [3] [/3] [3]Change in the program to allow reliable buffering at any InteruptCounter located @ &H13[/3] [3]In the simulator:[/3] [3] [/3] [3]First, Toggle Pin D0 on and then start the simulator, stop when activity is only Bank 12, now change memory location at Bank 13 to &H02.[/3] [3] [/3] [3]Second, set the controller to a new position of X = &H6000, Y = &H8000, Z = &H8000 by placing the following hex values into the received buffer starting at Bank 90; (5A), (00), (60), (00), (80), (00), (80), (00), (00), (00), (00), (00), (00), (5A) run the simulation then stop the only activity again is the InteruptCounter located @ Bank 12. The X = &H7000, Y = &H8000, Z = &H8000.[/3] [3] [/3] [3]Last is to start a circular move around X = &H8000, Y = &H8000 from PI radians to 0 radians clockwise. Z will also move linear to the completed arc. From the halted simulation place the following hex values into the received buffer starting at &H90 (4D), (00), (80), (00), (80), (70), (80), (00), (20), (B8), (7A), (B8), (7A), (4D), restart the simulator.[/3] [3] [/3] [3]The Cordic subroutine will become active and the buffer should start filling with consecutive moves. The Interrupt will begin loading the buffers into the linear move subroutines and the motor data will change. Bank 40 - 45 will show the current position.[/3] [3] [/3] [3]Again, the SerialIn is in the MAIN to avoid Interrupt waist, when the data packet is VALID, it will be handled during a normal scan of MAIN stripping the buffered data of the command. This is simply a modified SerialIn for an SX28. The Packets are 14 bytes down and 14 bytes returned in response. 14 bytes are also sent when the move is complete signal the computer to send the next move. At 38400, it's fast and stripped down there may not be a need for a Cordic Method.[/3] [3] [/3] [3]But.. A near project will involve sending a quadrature signal data for each of XYZ to servo amps to control position; Cordic will almost be a certain must. [/3] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=223702#m231267 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)