Shop OBEX P1 Docs P2 Docs Learn Events
Question about if I can put a small job post up? — Parallax Forums

Question about if I can put a small job post up?

krazyideaskrazyideas Posts: 119
edited 2012-07-26 21:55 in Propeller 1
I have The IdxQuadDecoder by Luke Hays from the object exchange that I need a modification to.

I want too learn assembly, and am going to, but I am just too busy right now and need this to polish off a project for my Dad before I take off to school in 3 or 4 weeks

My to do list is too big and my time too short. The best part of that to do list is careing for my thrid little boy that my wife gave birth to on Sunday :) I love my life :)

Anyway I just wanted to know if it is alright to put up the program and a detailed explaniation of what changes I want and Ask if it would be worth 50 to 100 bucks to someone to make the changes for me.

Thanks

Comments

  • MacTuxLinMacTuxLin Posts: 821
    edited 2012-07-26 21:21
    Hi & congratulation to your 3rd child!

    Yeap, monetary rewards are always a welcome gesture of appreciation & I'm pretty sure there are members ready to help you.


    Cheers
    Kenichi
  • krazyideaskrazyideas Posts: 119
    edited 2012-07-26 21:37
    Ok So here is the Program. What I need is stated below the program in a PUB block
    Thanks
    VAR
      byte  cog
    
    PUB start(pin, varaddr)                                 ' Start a cog monitoring the encoder.
      stop 
      epin1 := pin
      result := cog := cognew(@quad, varaddr) + 1          
    
    {{
      Parameters:
        pin                         first pin of the encoder input
        varaddr                     address of the hub variable to accumulate to
    
      Returns:
        1 + number of cog it got started in
        0 if no cogs available.
    
      Note: You can preset the value of the accumulation variable before calling start.
      
      Example usage:
        variable := 25
        quad.start(12, @variable)
    }}
    
    PUB stop                                                ' Stop monitoring the encoder.
      if cog
        cogstop(cog~ - 1)
    
    DAT
                            ORG
                            
    quad                    mov     IndexMask, #%100        'Mask for Index Pulse ***
                            shl     IndexMask, epin1        'Shift to proper pin  ***
                                          
                            rdlong  accum, par              ' get initial value of accumulator
                            mov     quadmask, #%11          ' initialize encoder mask
                            shl     quadmask, epin1         ' bitshift it to encoder pins
                                     
    firstread               mov     oldstate, ina           ' read encoder for the first time
                            and     oldstate, quadmask      ' call this the "old state"
                            shr     oldstate, epin1         ' bitshift it into the LSBs
                            
    backtostart                                     
                            mov     turnpos, oldstate       ' PURE VOODOO MAGIC
                            rev     turnpos, #30            ' do some funky bit math
                            xor     turnpos, #%10           ' new state will match one of these
                                                            ' whichever it matches = turn direction                        
                            mov     turnneg, oldstate
                            rev     turnneg, #30
                            xor     turnneg, #%01           
                            
    getnewstate             mov     newstate, ina           ' read encoder
                            mov     MarkIndex, newstate     ' Get unmasked index pin ***
                            and     MarkIndex, IndexMask  wz  ' Mask pins other than index ***
                  if_z     jmp     #over                   ' Skip accum 0 if index is 0***
                            mov     accum, #0
    over                    and     newstate, quadmask      ' mask it against the encoder mask
                            shr     newstate, epin1         ' shift it into the LSBs
                                                            
                            cmp     turnpos, newstate       wz     ' see if it moved cw
                  if_z      jmp     #turnedpos
    
                            cmp     turnneg, newstate       wz     ' see if it moved ccw
                  if_z      jmp     #turnedneg
                            
                            jmp     #getnewstate            ' falls through, start over
    
    turnedneg               add     accum, #%1
                            wrlong  accum, par
                            jmp     #updatestates           ' exit
    
    turnedpos               sub     accum, #%1
                            wrlong  accum, par
                            jmp     #updatestates           ' exit
    
    updatestates            mov     oldstate, newstate      ' mov newstate overwrite oldstate
                            jmp     #backtostart
                            
                         
    
    epin1   long  12
    
    accum         res 1
    quadmask      res 1
    oldstate      res 1
    turnpos       res 1
    turnneg       res 1
    newstate      res 1
    time          res 1
    IndexMask     res 1
    MarkIndex     res 1
    
                            FIT
    
    



    I need ONE of these OPTIONS incorporated into the assembly program above

    {Question What is the max RPM of this program if there are 2880 encoder ticks per rotation?
    5000 RPM is the Max I will ever likely spin the encoder.

    So 5000 / 60 = 83.3 RPS
    83 * 2880 = 239040 Encoder Ticks Per Second (or updates per second)
    That is as far as I know how to take the Math}

    'What I need

    "OPTION 1, OR OPTION 2"

    "OPTION 1"

    If pin 16 goes high
    Then set accumulator to 0.
    Then wait for index to trigger
    Then Store cnt value in varuable M1
    Then wait for index to trigger again
    Then Store cnt value in varuable M2
    Then Subtract M1 from M2 and store value in M1
    Then Divide M1 by encoder ticks per rotation (2880) store Value in M1

    Then Wait for index to trigger
    Then add 1 to accumulator
    Then enter an endless loop (not really needed but mabe make the loop end if pin 16 goes low. Then Wait for index to trigger then enter normal encoder loop)

    Endless loop is

    waitcnt M1 (waitcnt M1 Must take in overhead (synchronized delay timing) like you do in spin useing "waitcnt (time += 50_000)")
    then add 1 to accumlulator
    if accumulator == encoder ticks per rotation plus 1 (2880 + 1)
    Then accumulator == 1


    "OPTION 2" (The better option if it won't slow the program down below 5000 RPM )

    Just before TurnedPos Jumps to Updatestates set up somekind of double varuable where you store cnt value in one varuable then
    on the next pass through store the cnt value in the other varuble.
    How that is best done I don't know. Mabe dependant on if the accumulator value is even or odd, I don't know, needs to be fast though

    if you can do the above
    Then when PIN 16 goes high set the accumulator to 0
    Then Subtract the two varuables to find the number of system clock ticks there are between accumulation updates, store value in a varubale called wait

    Then Wait for index to trigger
    Then add 1 to accumulator
    Then enter an endless loop (not really needed but mabe make the loop end if pin 16 goes low. Then Wait for index to trigger then enter normal encoder loop, Do this only if it is easy)

    Endless loop is

    waitcnt wait (waitcnt wait Must take in overhead (synchronized delay timing) like you do in spin useing "waitcnt (time += 50_000)")
    then add 1 to accumlulator
    if accumulator == encoder ticks per rotation plus 1 (2880 + 1)
    Then accumulator := 1


    "OPTION 3"
    Some other idea that I have not thought of that would do the same thing.
    When Pin 16 goes High keep acculation rate to the accumulator going at the same rate as when PIN 16 goes high, Makeing sure
    to keep the proper referance to the index. (When the index is trggered the accumulators value is 2880 or 0 easyer if it is 2880)
    So start counting up from 0 when the index is triggered. Then entering the endless loop as above.
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-07-26 21:38
    Change [noparse][code/] to [/code][/noparse] to make your post easier to read.
  • krazyideaskrazyideas Posts: 119
    edited 2012-07-26 21:41
    Why isn't my code showing up in it's nice little box little it use to? I just put [code] before the code and [code/] after the code right?????
  • krazyideaskrazyideas Posts: 119
    edited 2012-07-26 21:55
    Ok I got it looking better.
    Thanks
Sign In or Register to comment.