Cordic trig assembly code for PIC18f


Closed Thread
Results 1 to 40 of 55

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Nice work, but I am also challenged with maths.
    Will this allow me to do point rotation?

    Say I have an origin x=0 & y=0, and another point x=4, y=4.
    Can I find out the angle of the second coordinates where the first set is the origin,
    and then rotate the second point say 180 degrees around the origin ?
    Art.

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Uh-oh.. just including the line:
    include "trig-pic16.inc"
    causes this:

    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 213 : [235] Opcode Expected Instead of 'dt'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 216 : [235] Opcode Expected Instead of 'dt'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 219 : [235] Opcode Expected Instead of 'dt'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 222 : [235] Opcode Expected Instead of 'dt'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 237 : [226] Numeric Constant or Symbol Name Expected
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 239 : [226] Numeric Constant or Symbol Name Expected
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 269 : [235] Opcode Expected Instead of 'movfw'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 283 : [235] Opcode Expected Instead of 'movfw'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 301 : [235] Opcode Expected Instead of 'movfw'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 306 : [235] Opcode Expected Instead of 'movfw'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 316 : [235] Opcode Expected Instead of 'movfw'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 321 : [235] Opcode Expected Instead of 'movfw'
    Error C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 349 : [235] Opcode Expected Instead of 'movfw'
    Warn C:\PROGRA~1\MPLAB\PROJECT\SCROLL.ASM 934 : [102] Code Crosses Boundary @ 800h

    I'm using a 16F877 too.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Use MPASM for the assembler.
    <br>
    DT

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,
    I'm working on hardware now, but I'll try again as soon as possible.
    Any idea on my first question?

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Use MPASM for the assembler.
    <br>
    It seems that this line becomes offensive:
    Code:
    '@ DEVICE LVP_OFF,BOD_OFF,HS_OSC				'
    Which is how I set configuration.
    Art.
    Last edited by Art; - 29th January 2010 at 12:41.

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    You need to use a different syntax for MPASM.

    like this:
    Code:
    Example: To set the PIC for Internal Oscillator allowing use of the OSC pins as I/O...
    
    @ __config _INTRC_OSC_NOCLKOUT
    
    Only one config statement is allowed when using MPASM, so multiple definitions follow-on from each other each connected to it’s previous buddy with an &.
    
    Example: Typical Settings for a 16F628…
    
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _LVP_OFF & _CP_ALL & _DATA_CP_ON
    More (much more) here: http://www.picbasic.co.uk/forum/showthread.php?t=543

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Art View Post
    Nice work, but I am also challenged with maths.
    Will this allow me to do point rotation?

    Say I have an origin x=0 & y=0, and another point x=4, y=4.
    Can I find out the angle of the second coordinates where the first set is the origin,
    and then rotate the second point say 180 degrees around the origin ?
    Art.
    Hi Art,

    You can definitely find the angle in the first part of your question. As far as rotation, I have to think a little more. Should be possible though.

    Are you rotating one of your LED displays? If so, are we talking full rotation, or just 90, 180, 270 degrees?

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Ideally, to potentially be able to do full rotation of a pixel.
    Yes, I have a matrix LED display in mind
    I wouldn't care whether or not it is equally divided into 360 degrees.
    I already have made routines that make it easy to draw to the screen.

    I can do this in C on the Sony PSP like this
    Code:
    xx = 240;
    yy = 30;
    x = xx - 240;
    y = yy - 136;
    
    theta = rotation;
    thetab = 360 - theta;
    thetab = (3.141592 / 180) * theta;
    
    xnew = cos(thetab)*x - sin(thetab)*y;
    ynew = sin(thetab)*x + cos(thetab)*y;
    
    xnew = xnew + 240;
    ynew = ynew + 136;
    Where x-240, y-136 are coordinates for the centre of the screen,
    x-240,y-30 is the arbitrary point I want to rotate (the one given is a point directly above the centre of the screen),
    rotation is the real angle 0-359 (0 can also be 360).
    xnew and ynew are the new (rotated) coordinates.
    I don't know if this works with microcontrollers even if you do use a C compiler.

  9. #9
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Art View Post
    Ideally, to potentially be able to do full rotation of a pixel.
    Yes, I have a matrix LED display in mind
    I wouldn't care whether or not it is equally divided into 360 degrees.
    I already have made routines that make it easy to draw to the screen.

    I can do this in C on the Sony PSP like this
    Code:
    xx = 240;
    yy = 30;
    x = xx - 240;
    y = yy - 136;
    
    theta = rotation;
    thetab = 360 - theta;
    thetab = (3.141592 / 180) * theta;
    
    xnew = cos(thetab)*x - sin(thetab)*y;
    ynew = sin(thetab)*x + cos(thetab)*y;
    
    xnew = xnew + 240;
    ynew = ynew + 136;
    Where x-240, y-136 are coordinates for the centre of the screen,
    x-240,y-30 is the arbitrary point I want to rotate (the one given is a point directly above the centre of the screen),
    rotation is the real angle 0-359 (0 can also be 360).
    xnew and ynew are the new (rotated) coordinates.
    I don't know if this works with microcontrollers even if you do use a C compiler.
    Yes, it looks like you could use the same type of math. The cordic lets you compute sin and cos in a single operation. It is very quick with this type of thing, and can perform about 2000 of these per second.

    So you would just have to solve:



    as you have in your above equation. The PIC18 cordic is a little better, and I documented it more. But if you still want to do it with your PIC16, I am here to help.

    Wikipedia talks a little bit about rotation here: http://en.wikipedia.org/wiki/Rotation_%28mathematics%29
    Attached Images Attached Images  
    Last edited by ScaleRobotics; - 31st January 2010 at 05:20.

  10. #10
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    I'm not quite ready to do it yet, only because I'm in the middle of something else,
    but regarding the LED displays, I've got a blitter routine handling sprites now.
    It would be really nice to see if it could handle rotation of a sprite (pixel by pixel).

    Thanks for your offer to help, I'll surely take you up on it very soon

  11. #11
    Join Date
    Apr 2010
    Location
    Gavle, Sweden
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Cordic trig assembly code for PIC18f

    Hi !
    I'm trying to write a program to calculate sunrise and sunset. The pic is 18F2550 and I'm using long variables and PBPL. I've tried to use the TRIG.INC but it seems that I cant use it in PBPL, Error: DIV32. Is there a way to rewrite the program so that it will work with PBPL?
    I'm using Picbasic Pro 2.50 and MPASM 8.15.
    Bernt-Ove

  12. #12
    Join Date
    Apr 2010
    Location
    Gavle, Sweden
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Cordic trig assembly code for PIC18f

    The problem is solved. I found another version of trig.inc in post 13, and it works well for me. I have to put the word variables x,y into long variables before doing any calculations on them.

  13. #13
    Join Date
    Jul 2011
    Location
    Hawaii
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: Cordic trig assembly code for PIC18f

    Hi,

    I am using your TRIG.inc in a small program. The values appear correct from (ang) = 0 to 9000, 0 to 90.00 degrees. For values, 9000 < (ang) < 18000 ,the
    values for x and y appear to switch. As an example with an (ang) value of 8900 or 89.00 degrees I receive a value back x = 29995 and y = 525. This seems correct.
    For an (ang) value of 9100 or 91.00 degrees I receive back x = -523 and y = 29995. For 91.00 degrees I would expect x = 29995 and y = -523 ?

    - Martin

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. 4 Chanel Dmx512 ready assembly code to PBP ?
    By syscoder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st March 2007, 23:55
  5. Your Suggestions: Assembly code material?
    By dw_picbasic in forum General
    Replies: 1
    Last Post: - 2nd February 2007, 17:33

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts