• AVR Freaks

Hot!Sine and Cosine functions

Author
Steve311
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2012/07/18 20:05:45
  • Location: 0
  • Status: offline
2018/12/09 20:16:40 (permalink)
0

Sine and Cosine functions

Hello all, looking for advice on the smallest pic u that can compute sin/cosine functions. Hoping for a 3x3mm package. Thanks!
#1

5 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Sine and Cosine functions 2018/12/09 20:20:52 (permalink)
    4.5 (2)
    Any PIC can do it, but it depends how fast you need it done, and to what precision.

    Nearly there...
    #2
    mlp
    boots too small
    • Total Posts : 749
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Sine and Cosine functions 2018/12/09 20:32:55 (permalink)
    4.5 (2)
    No 8-bit PIC (I can't speak for the 16-bit or larger products - it's way too long since I worked with them) has hardware support for non-integer mathematical operations, so any such support must be provided by software which will occupy space in Flash, and will take extra (usually significant) time to compute.
     
    XC8 will generate code for any MCU in the 8-bit range, and supports all of the trigonometric functions described by the C language standard in both 24-bit and 32-bit floating point. The 10F200 comes in an SOT23, if I recall correctly.
     
    So the question you gotta ask yourself is: how much other stuff do you want it to do, around the sin/cos calculations? That will determine how small a chip you can use.
     

    Mark (this opinion available for hire)
    #3
    PStechPaul
    Super Member
    • Total Posts : 2258
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: Sine and Cosine functions 2018/12/09 22:42:15 (permalink)
    5 (1)
    The PIC12(L)F1822 comes in a 3x3 mm DFN package. It has 2k words program memory, 256 bytes EEPROM and 128 bytes data SRAM. The PIC12(L)F1840 also comes in that package, with 4k flash and 256 bytes SRAM. Newer 8 pin devices may have even more.
     
    Depending on the accuracy and speed needed for SIN and COS functions, they could be implemented in a look-up table, perhaps using cubic spline interpolation.

     
    #4
    Howard Long
    Super Member
    • Total Posts : 672
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: Sine and Cosine functions 2018/12/10 04:29:04 (permalink)
    5 (1)
    Some further comments...
     
    o Switch both double and float to 24 bit, the program and data space requirements are a lot less
    o You may well find need the PRO compiler with the -Os option, it makes a lot of difference
    o Using the simple code below, these are the code sizes I managed to achieve:
     
    o 12F1840, xc8 v2.00, C90 24 bit float, 24 bit double, -O0 code 2104 words, data 96 bytes
    o 12F1840, xc8 v2.00, C90 24 bit float, 24 bit double, -O1 code 1869 words, data 96 bytes
    o 12F1840, xc8 v2.00, C90 24 bit float, 24 bit double, -O2 code 1701 words, data 96 bytes
    o 12F1840, xc8 v2.00, C90 24 bit float, 24 bit double, -O3 code 1388 words, data 90 bytes
    o 12F1840, xc8 v2.00, C90 24 bit float, 24 bit double, -Os code 1341 words, data 90 bytes
     
    o 12F1840, xc8 v2.00, C90 24 bit float, 32 bit double, -O0 code INSUFFICIENT SPACE
    o 12F1840, xc8 v2.00, C90 24 bit float, 32 bit double, -O1 code 3720 words, data 146 bytes
    o 12F1840, xc8 v2.00, C90 24 bit float, 32 bit double, -O2 code 3321 words, data 146 bytes
    o 12F1840, xc8 v2.00, C90 24 bit float, 32 bit double, -O3 code 2788 words, data 138 bytes
    o 12F1840, xc8 v2.00, C90 24 bit float, 32 bit double, -Os code 2598 words, data 138 bytes
     
    o 12F1840, xc8 v2.00, C90 32 bit float, 32 bit double, -O0 code 3740 words, data 145 bytes
    o 12F1840, xc8 v2.00, C90 32 bit float, 32 bit double, -O1 code 3339 words, data 145 bytes
    o 12F1840, xc8 v2.00, C90 32 bit float, 32 bit double, -O2 code 2974 words, data 145 bytes
    o 12F1840, xc8 v2.00, C90 32 bit float, 32 bit double, -O3 code 2519 words, data 137 bytes
    o 12F1840, xc8 v2.00, C90 32 bit float, 32 bit double, -Os code 2329 words, data 137 bytes
     

    #include <xc.h>
    #include <math.h>
    void main(void)
    {
    volatile float f;
    volatile float fs;
    volatile float fc;

    for (f=0.0f;f<10.0f;f+=1.0f)
    {
    fs=sin(f);
    fc=cos(f);
    NOP();
    }
    return;
    }

     
    #5
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Sine and Cosine functions 2018/12/10 06:05:25 (permalink)
    4.5 (2)
    This is all just guesswork until the OP comes back and reveals what it is that has to be done by the PIC.
     

    Nearly there...
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5