Round the clock


Closed Thread
Results 1 to 28 of 28

Thread: Round the clock

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    There's no deadband but it's easy enough to add that after the actual calculation, before you decide to move or not
    Code:
    IF ABS Distance > Deadband THEN 
       ' Make the move
    ELSE
      ' Sit tight
    ENDIF
    /Henrik.

  2. #2
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Thanks H, C

  3. #3
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Quote Originally Posted by HenrikOlsson View Post
    There's no deadband but it's easy enough to add that after the actual calculation, before you decide to move or not
    Code:
    IF ABS Distance > Deadband THEN 
       ' Make the move
    ELSE
      ' Sit tight
    ENDIF
    /Henrik.
    Hi Henrik
    Does this also work for 'IF ABS Distance > Deadband THEN' and 'IF ABS Distance < Deadband THEN' at the change from 11 to 0 and 0 to 11?
    C.

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


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Have you tried it?

    Using your numbers with 3580 ticks around the circle:

    If you're moving from 0 to 11 distance is +11.
    If you're moving from 11 to 0 distance is -11.
    In both cases the ABSolute value of distance is 11. If you have deadband set to 1 then you'll move because distance is larger than deadband.

    If you're moving from 11 to 12 distance is +1.
    If you're moving from 12 to 11 distance is -1.
    In both cases the ABSolute value of distance is 1. If you have deadband set to 1 then you won't move because distance is not larger than deadband.

    /Henrik.

  5. #5
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Quote Originally Posted by HenrikOlsson View Post
    Have you tried it?

    Using your numbers with 3580 ticks around the circle:

    If you're moving from 0 to 11 distance is +11.
    If you're moving from 11 to 0 distance is -11.
    In both cases the ABSolute value of distance is 11. If you have deadband set to 1 then you'll move because distance is larger than deadband.

    If you're moving from 11 to 12 distance is +1.
    If you're moving from 12 to 11 distance is -1.
    In both cases the ABSolute value of distance is 1. If you have deadband set to 1 then you won't move because distance is not larger than deadband.

    /Henrik.
    Hi Henrik,

    My system is actually 0 to 3581, so 3582 ticks/circle. I used the 0 to 11 clock face to simplify my question, so actually 11 to 0 is similar to 3283 to 0.

    This is an interesting solution, if I can use it. At the moment I'm trying to unravel a pile if spaghetti with my existing program.

    I have to convert it for use with the Oshonsoft system, while learning about ABS, and the ????????.15 variable. I'm not sure if Oshonsoft supports ABS, but I assume it can be got round in some way.

    I'll let you know once I get it running, thanks.

    C.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    PBP doesn't have signed 16-bit (WORD) variables so the distance.15 is simply a way to determine if the value is negative. The equivalent code, if you have signed variables, would be:
    Code:
        Distance = Target - Position
    
        IF Distance > 1790 THEN
           Distance = Distance - 3580
        Endif
    
        IF Distance < -1790 THEN
           Distance = Distance + 3580
        ENDIF
    /Henrik.

  7. #7
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Hi Henrik,

    As mentioned my system has 3582 tick/rev, so is the 3580 in the last post correct?

    I don't think Oshonsoft supports negative values, but I'll check.

    Thanks, C.

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Oh come on, think or at least do some trial and error your self now! ;-)

    The ABS and Distance.15 is some "trickery" to make it work with PBP but the "clean" formulas shuld work fine with pen and paper. Try it out, make it work with the 12 hour clock example you actually asked for first. Then try wth the larger numbers, I'm sure you'll be able to figure out what needs tweaking for any number of ticks around the circle.

    You were interested in the logic. This, I think, is one way of doing it but I'm sure there are others. As for how to actually implement it on Oshonshoft you're on your own or at least in the hands of someone else.

    /Henrik.

Similar Threads

  1. DT_INT Vs ASM - Round 1
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 27th January 2013, 22:33
  2. How to round number using integer only
    By Yvesmazzon in forum Code Examples
    Replies: 2
    Last Post: - 6th March 2011, 14:37
  3. external clock / internal clock
    By grounded in forum General
    Replies: 4
    Last Post: - 31st May 2008, 18:44
  4. Clock
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st February 2008, 03:23
  5. Round Dial, Electronic Combination Lock
    By Pic_User in forum Off Topic
    Replies: 5
    Last Post: - 6th July 2006, 14:34

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