Working with Cosine


Closed Thread
Results 1 to 3 of 3
  1. #1
    Ed Cannady's Avatar
    Ed Cannady Guest

    Question Working with Cosine

    I would like to use the COS function to determine which part of a sine wave I am on. What I do not know is what the data is going to look like and how accurate the data will be. Thanks in advance for any and all help.

    Best, Ed

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i'll suggest you something else, take a few reading of your signal with the internal adc, store those data into array or internal EPROM and play with. Refering to a table will be much easier and much code efficient. BUT it's my own opinion, probably Melanie or somebody else have a better solution.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi,Ed

    You'll get -127 to +127 as a result ... so, look at the highest digit to see where you are on your sine ( ascending = 1, descending = 0 ).

    But do not forget to convert degrees as here:

    Result = COS ( X * 256 / 360 ) ... for X in degrees.
    Side = Result.7

    Looking also to SIN highest digit will show you the quarter where you are ...

    For accuracy ... 7 bits !!!

    Alain
    Last edited by Acetronics2; - 10th May 2005 at 13:31.

Similar Threads

  1. 16F877A with 20MHz XTAL not working?
    By ustredna in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 19th August 2011, 15:04
  2. Blink.Bas on 18f45k20 Newbie seeks working example.
    By DiscoEd in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 03:36
  3. Pic 16 F628A not working
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th March 2009, 12:26
  4. Wrong values with COSINE!
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 8th May 2006, 16:59
  5. Hserin not working...
    By robert0 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd August 2005, 12:25

Members who have read this thread : 1

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