12F683 Maths and code genius reqd.


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: 12F683 Maths and code genius reqd.

    How can I simulate/enter this formula in a spreadsheet?
    I want to experiment with the values for the the calculation.
    The special 2's complement maths is making my head explode.
    Thanks

    ADCIN 1, Temp 'Temp = a number between 0-255
    RegenPot = (Temp ** 20480) - 40

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 12F683 Maths and code genius reqd.

    Hi,
    Try something like:
    Code:
    =TRUNC((A4*20480/65536)-40)
    Where A4 is the cell in which you put your TEMP value. Now, MS insists on changing the names of the functions depending on what language you're running but I think TRUNC is what you want, as long as you're running an English version of Excel - which I'm not.....here it's called AVKORTA....

    This will give you a result of -39 when TEMP is 0 and 39 when TEMP is 255 and it truncates the result (instead of rounding it) just like it will when run on the PIC.

    We could get it display as a real two's complement number but I'll have to dwell on that for a moment - if needed. In the meantime:
    253 = -3
    254 = -2
    255 = -1
    0 = 0
    1 = 1
    2 = 2
    3 = 3

    And so on.....

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: 12F683 Maths and code genius reqd.

    How can i modify the formula to get +/- 20 or +/- 10

    AssistPot = (AssistPot ** 20480) - 40
    RegenPot = (RegenPot ** 20480) - 40

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 12F683 Maths and code genius reqd.

    Hi,
    +/- 20: Change 20480 to 10240 (1/2 of 20480) and subtract 20 instead of 40.
    +/- 10: Change 20480 to 5120 (1/4 of 20480) and subtract 10 instead of 40.

    Just think of the ** operator as multiplying by units of 1/65536.

    /Henrik.

Similar Threads

  1. please help with 12f683 pwm code
    By haidar in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd May 2013, 21:25
  2. Problem converting 12F683 code to 12F1840
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th March 2013, 01:55
  3. Maths help please
    By Tina10 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th June 2012, 16:45
  4. Maths again...
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st September 2010, 22:51
  5. Comparator Help reqd
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th September 2005, 03:39

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