Round the clock


Closed Thread
Results 1 to 28 of 28

Thread: Round the clock

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Normally you won't count to 24 but up to 23:59. But I have missed the point of -/+1 here.

    Ioannis

  2. #2
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Quote Originally Posted by Ioannis View Post
    Normally you won't count to 24 but up to 23:59. But I have missed the point of -/+1 here.

    Ioannis
    Hi I,

    My actual system uses 0 to 3581 steps, but that's complicating things This is why I used the clock analogy. And yes, it is 0 to 23:59, but again this is complicating things, as there are 60 minutes/hour. So I'll use 0 to 11.

    The mechanics of my system: A motor moves the pointer to the incoming data, so if it is pointing to 3 and data says 4 then it moves cwise till it matches. The motor moves quickly, so as it comes towards 4 it needs to switch off the motor, before it matches, so I added a deadband, which gives data -1 and +1, where no power to the motor within this band. Now say the pointer is at 3 and data says 5 the pointer is moves cwise and switches the power off at 4. In this example, this looks coarse, but in reality, it is much finer.

    I hope this clarifies things.

    C.

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


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Hi,
    Try this:
    Code:
    Position    VAR WORD
    Target      VAR WORD
    Distance    VAR WORD
    
    Position = 1234
    
    Main:
        HSEROUT[13, "You're at position: ", DEC Position, 13]
        HSEROUT["Enter new target: ",13]
        HSERIN[DEC Target]
    
        ' Actual calculation starts here.
        ' When done the variable Distance contains the
        ' number of "ticks" to target in two's complement format.
        Distance = Target - Position
    
        IF Distance.15 = 0 THEN             ' Distance is positive
            If Distance > 1790 THEN
                Distance = Distance - 3580
            Endif
        ENDIF
    
        IF Distance.15 = 1 THEN              ' Distance is negative
            IF ABS Distance > 1790 THEN
                Distance = Distance + 3580
            ENDIF
        ENDIF
        ' End of calculation, result now in Distance.
    
    Done:
        IF Distance.15 = 1 THEN             ' Distance is negative
            HSEROUT["CCW "]
        ELSE
            HSEROUT["CW "]
        ENDIF
    
        HSEROUT[DEC ABS Distance, " ticks.", 13]
    
        Position = Target
    
    Goto Main
    /Henrik.

  4. #4
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Hi H,

    Thank you, I will try it and let you know what happens. I'm a bit slow understanding code though

    Will you annotate where the DEADBAND is in your code please?

    C.

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


    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.

  6. #6
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Thanks H, C

  7. #7
    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.

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


    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.

Similar Threads

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