Simple Maths Going Wrong


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default DT routine - Direction better than 8 bit?

    Hi Folks,

    Mainly for Darrel but happy to have input from all!

    DT's example of averaging the direction (thanks Darrel) makes use of ATN from an 8 bit direction (0-255 = 0-359 degrees) and works well when I use this method with PBPro 2.60.

    However this gives some inaccuracies and low resolution. I've acquired my direction with a 10 bit AD and converted down to 0-359 but no matter how I manipulate the numbers in DT's formula I get to about 270 deg's and then it rolls over with false values.

    Is there a way to achieve the above or am I stuck with coarse direction? I'd like to have 1 degree changes if possible not the jumps 8 bit has.

    Kind regards to all and thanks in advance,
    Bill

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    As you have no code posted I can only guess that your vaariable are byte and not word.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wjsmarine View Post
    ... makes use of ATN from an 8 bit direction (0-255 = 0-359 degrees) ...
    ... with a 10 bit AD and converted down to 0-359
    Shouldn't it be converted to 0-255 (representing 0-359)?

    ATN SIN and COS all use binary radians.
    <br>
    DT

  4. #4
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Better Direction resolution?

    Hi Darrel and Ioannis,

    Thanks for the help. I replied earlier but it didn't seem to make it, here goes again...

    Ioannis the first thing I did when trying changes was to move to Words for the variables so was surprised when the numbers didn't crunch.

    Darrel your code works well but gives 360/256 = 1.4 degree accuracy/resolution and I was hoping for better than this. I'm not strong at math so your comment about binary radians probably means I'm stuck with the original limits, which is probably okay for wind direction - but what do I do if I need greater accuracy for Tilt, etc?

    Any suggestions and help is appreciated, thanks guys.
    Bill

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


    Did you find this post helpful? Yes | No

    Default

    If you need more resolution, you'll need to pull out the Big Guns ...

    Cordic trig assembly code for PIC18f (scalerobotics)
    http://www.picbasic.co.uk/forum/showthread.php?t=10528
    <br>
    DT

Similar Threads

  1. Simple RF remote control code
    By Bruce in forum Code Examples
    Replies: 13
    Last Post: - 22nd January 2014, 10:45
  2. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 06:19
  3. Simple LCD code not working!...WHY?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th November 2009, 19:48
  4. what's wrong 16F877A simple code?
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th October 2009, 01:11
  5. Doing Simple Math - getting the wrong answer
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2005, 14:27

Members who have read this thread : 0

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