Round the clock


Closed Thread
Results 1 to 28 of 28

Thread: Round the clock

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Quote Originally Posted by Amoque View Post
    I do not follow the conversation well enough to speak in context, but in doing a similar thing I found the solution to calculate direction and distance separately; then, once I'd accurately calculated these, dump off those variables to a routine that "swung the needle". I did not need to worry about "round" however as I was programming to mimic analog gauges.

    Last, to simulate MOD subtract the integer value from the single value - that decimal portion which remains...
    Hi A,

    Here's another explanation, again using the clock:

    1/ The HAND is at 3. Input FACE 5. HAND<FACE = cwise. HAND moves and counts. HAND=4. HAND<FACE=cwise. HAND moves and counts. HAND=5. HAND=FACE =BRAKE.

    2/ The HAND is at 12. Input FACE=1 HAND>FACE = ccwise NOT CORRECT.

    I want FACE to cover FACE+1 and FACE-1.

    3/ The HAND is at 12. Input FACE=1 Now FACE-1= -1.

    This is difficult for me to understand.

    I am also trying to understand the MOD suggestions. I will need to check the program to see if I can use MOD, as I get to understand it more.

    Thanks. C.

    C.
    Last edited by camerart; - 22nd January 2016 at 14:38.

  2. #2
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Is it the MODulus operation you're having problems with or its implementation?

    I had to get a pencil and paper out and do some modulus operations before my extremely thick skull was pierced enough to see how the modulus operator worked. Once understood it's pretty neat. Now if I could only get the */ thingy figured out.

  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 AvionicsMaster1 View Post
    Is it the MODulus operation you're having problems with or its implementation?

    I had to get a pencil and paper out and do some modulus operations before my extremely thick skull was pierced enough to see how the modulus operator worked. Once understood it's pretty neat. Now if I could only get the */ thingy figured out.
    Hi A,
    I've had quite a bit of MODulus explained to me since it cropped up a day or two ago, and I'm beggining to see the light. It does appear to be the right way to go.

    What problems are you having with * and /?

    C.

  4. #4
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Round the clock

    Hi,

    The program itself is fine at the 12 to 0 changeover, but with a DEADBAND, it complicates things.

    Ioannis suggested Modulus also using a 24Hr clock.

    After trying to get to know Modulus, for a while, I can only guess, that it won't correct my problem. The problem is a DEADBAND, so 'say' 3 with a DEADBAND of 1 would be 2 to 4. At o it will be -1 to 1. I don't get the impression that Modulus works with minus numbers.

    I experimented with the 24 hour clock, and as the clock goes round and round, eventually it will be 24 then 0 again, so a similar problem. I finally only use 24Hr for a small section around 12 or 0. then revert back to 12 hour, this works fine.

    Thanks for all suggestions, C.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    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

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

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

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