Offset to variable howto ?


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    So why not ADD an offset of 120 (using your example)...

    That way zero will be in reality -120, 120 will be zero, and 240 is actually +120 ???

    This way you will never go below zero, because zero is your REAL reference point, and your offset value is actually your mechanical zero.

    Simple maths prior to displaying the figures will have it display whatever you want it to display.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    thank you melanie

    Well this is what i want to do and would show on the display:

    I read the Real position from the encoder as a 10bit word (0-1024) as the encoder is absolute
    i might want to add or substract an offset so that how the encoder mechanicly is fixed
    i still can correct it by the offset but need to keep 1024 as resolution for 1 revolution

    So i want to display or have new variables with:
    the position +/- it's offset but between 0 and 1024
    Conversion of the position +/- offset to 0 - 360 deg (keep the 10bit resolution)

    I dont see how I can do that

    Can you point me out ?

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RFsolution View Post
    thank you melanie

    Well this is what i want to do and would show on the display:

    I read the Real position from the encoder as a 10bit word (0-1024) as the encoder is absolute
    i might want to add or substract an offset so that how the encoder mechanicly is fixed
    i still can correct it by the offset but need to keep 1024 as resolution for 1 revolution

    So i want to display or have new variables with:
    the position +/- it's offset but between 0 and 1024
    Conversion of the position +/- offset to 0 - 360 deg (keep the 10bit resolution)

    I dont see how I can do that

    Can you point me out ?
    So, you add your offset...
    If it's above 360, subtract 360...
    If it's below 360 (i.e. negative, somewhere above 65000, if using words), add 360...
    Get the picture yet?

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Why not using an offset switch? when you press it, you jump to a reading routine put the value into a word variable that will be use as the offset. In this way the offset will never be greater then the true value.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Hi Melani and others

    Well the problem is as followed:

    The application which is reading the encoder via a serial port expects a 10bit value
    where 0 is 0 and 1024 is 1 resolution (or 360deg)
    So this application does the mathematics for conversion

    So the meaning of my offset value is to avoid that i have to move the encoder physicaly to its true zero point

    So i would like to keep the resolution of 1024 but shift it around (if i may call it shifting)
    in a way that i will keep a 10bit value

    I dont see how to do that
    maybe you might have some help

    Thanks in advance

    Walter



    Quote Originally Posted by Melanie View Post
    So why not ADD an offset of 120 (using your example)...

    That way zero will be in reality -120, 120 will be zero, and 240 is actually +120 ???

    This way you will never go below zero, because zero is your REAL reference point, and your offset value is actually your mechanical zero.

    Simple maths prior to displaying the figures will have it display whatever you want it to display.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Either we're not getting it (not likely) or you're not getting it (more likely)...
    If you're converted/offset value is out of range after the calculations, then put it back in range.
    Example...
    You had read 300 degrees, now you add an offset of 100 degrees, that gives you 400 degrees, well, that's no good, 'cause 400 degrees is out of range, but we both know 400 degrees is actually 40 degrees past 360 degrees, so subtract 360.
    Further example...
    You had 10 degrees, now you need to offset that by -50 degrees, which will give you -40 degrees, again, that's no good because -40 degrees isn't in the range of 0 to 359 degrees, so add 360 degrees to -40 will give you 320 degrees which is the answer you want.
    Yes, the examples above are in degrees. If 360 degrees = 1024 counts, then add or subtract 1024 counts from any answer that's out of range.
    If value => 1024 and value < 64512 then subtract 1024...
    If value => 64512, then add 1024...
    Question for you...Where did I get that value of 64512?

    Here's another thread talking all about this same sort of thing...
    http://www.picbasic.co.uk/forum/show...highlight=wind

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Hi Skimask

    Well i will give it a closer look today,

    Well I have to say that i'm not a programmer so please excuse me if i ask rather
    easy questions for your skills !!! hihi

    Well the answer for my question should be 16bit or 65536 - 1024 = 64512

    You see i'm learning !!!

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Hi skimask and others

    here is what i do:
    loop:
    Offset = 400 ' example add 400 as offset
    gosub read_position ' get the position: 10bit 0=0deg, 1024 =360deg
    gosub set_offset
    goto loop

    set_offset:
    position = position + offset
    if position => 1024 & position < 64512 then
    Position_cor = position - 1024
    endif
    if position => 64512 then
    position_cor = position + 1024
    endif
    return

    if i display the original position and the corrected position a get a strange result
    i will have a look at that

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Ok then...Let's have a look-see at the whole program...
    And it would really help if you'd explain strange result.
    Just saying the words 'strange result' could mean that your PIC just spit a banana out of pin 1. Who knows... Qualifies as a strange result though, dontcha think?
    I think I know what your root problem is...but I want to see the program first before I help you figure out what the deal is.

  10. #10


    Did you find this post helpful? Yes | No

    Default

    Ok played a bit following your help,

    and this code works, actually it was quit simple but did not found it =(

    Assuming that the given offset is positive but that's enough as you can go 360 degrees in total:


    loop:
    Offset = 400 ' example add 400 as offset
    gosub read_position ' get the position: 10bit 0=0deg, 1024 =360deg
    gosub set_offset
    goto loop

    set_offset:
    position_temp = position + offset
    if position_temp => 1024 then
    Position_cor = position_temp - 1024
    endif
    if position_temp <= 1024 then
    position_cor = position_temp
    endif

    Seems to work very well

    Thanks for your help,and nice to learn from others

    Walter

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. HSEROUT full 3 digit display of variable howto ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th October 2008, 13:53
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21

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