Shop OBEX P1 Docs P2 Docs Learn Events
Address instead of contents — Parallax Forums

Address instead of contents

TappermanTapperman Posts: 319
edited 2014-07-01 06:08 in Propeller 1
3_Phase_Motor_v3c.spin
switch output on L1.png
Sin Table Generator for Motor Table.xls
_Set3Phase    rdlong    temp2,  ARG_0                   ' get X position in table
              mov       temp,  #Mtr_Table               ' get address of Mtr_Table
              add       temp,   temp2                   ' point at x entry
              mov       T_On__Ch + 10, temp             ' set OnTime from Table   <-- Bug
              wrlong    temp, ARG_0                     ' debug line
              mov       temp1, Max_Duty                 ' get max duty
              sub       temp1,  temp                    ' get difference
              mov       T_Off_Ch + 10, temp1            ' write the off time
              wrlong    temp1, ARG_1                    ' debug line



I get the address of the long in COG Ram (I think) instead of the contents of the table location.

Any ideas what I could be messing up on?

... Tim

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-09-03 12:48
    You need to get the table address into the instruction itself, since the Prop does not do indirect addressing, viz:
    _Set3Phase    rdlong    temp2,  ARG_0                   ' get X position in table
                  mov       temp,  #Mtr_Table               ' get address of Mtr_Table
                  add       temp,   temp2                   ' point at x entry
                  movd      wr_it, temp
                  mov       T_On__Ch + 10, temp             ' set OnTime from Table   <-- Bug
    wr_it         wrlong    0-0, ARG_0                      ' debug line
    

    BTW, there always needs to be at least one instruction between a statement that modifies another instruction and the instruction that it modifies.

    -Phil
  • TappermanTapperman Posts: 319
    edited 2012-09-03 16:24
    @Phil,

    Thanks ... that did the trick!

    [video=youtube_share;F5uWjCAjpfQ]

    ... Tim
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2012-09-04 11:45
    Nice job, Tim. Seeing other people's projects on the forums is getting me motivated to do something myself. Even seeing a motor turn around is pretty darned exciting!

    The wealth of experience around here really paves the way for others to quickly use the Propeller. Thanks Phil for the help, too.

    Ken Gracey
  • TappermanTapperman Posts: 319
    edited 2014-06-30 13:42
    I have a follow up question ... is this the correct way to load a table in COG ram?
    DAT
    
    Mtr_Drv_Asm   org
                  mov       src, par                        ' ram buffer add
                  mov       dst, MV_Tbl                     ' get cog targ add
                  mov       x_tmp, 12                       ' read 12 longs
    '-------------------------------------------------------------
    get_data      rdlong    dst, src
                  add       dst, #1                         ' adv target register
                  add       src, #4                         ' adv hub address
                  djnz      x_tmp, #get_data
    
                  nop       ' rest of code, table should be loaded?
    
                  
    ''-------------------------Defined variables---------------------------------
    MV_Tbl        Long      0,0,0,0,0,0,0,0,0,0,0,0
    x_tmp         Long      0
    src           Long      0
    dst           Long      0
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-06-30 13:55
    It's close, but not quite. The destination address can't be indirect through another register: it has to be in the instruction itself. Use this:
    Mtr_Drv_Asm   org
                  mov       src, par                        ' ram buffer add
                  [color=red]movd      get_data,#MX_Tbl[/color]
                  mov       x_tmp, [color=red]#[/color]12                      ' read 12 longs
    get_data      rdlong    [color=blue][b]0-0[/b][/color], src
                  [color=red]add       get_data,_512                   ' adv target address[/color]
                  add       src, #4                         ' adv hub address
                  djnz      x_tmp, #get_data
                  ...
    [color=red]_512          long      512[/color]
    

    -Phil
  • TappermanTapperman Posts: 319
    edited 2014-06-30 19:26
    @Phil,

    Thanks for responding so quick! If you don't mind ...I have a follow-up question:

    Ok, I have to adjust the destination add in the RDLONG instruction. But, why do you add 512 to the code pointer, and not add 1 to the DST address?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-06-30 19:35
    You can't just add one to the instruction's destination address; there's no opcode for that. To increment the destination address, which resides in bits 17..9 of the instruction, you have to add 512 to the instruction itself. (I've modified the above code coloring to accentuate that the instruction itself is modified, not just a register.)

    -Phil
  • TappermanTapperman Posts: 319
    edited 2014-07-01 05:32
    OK, now I get it.
    So the MOVD modifies the field bids 17..9 of any long (in COG ram). In this case it happens to be an instruction code.


    So you were actually combining two steps into one. And that’s what I did not see. Thank you for clearing that up for me.

    Had I coded it my way, I would have added one to the destination address, followed by another MOVD op-code.

    So by adding 512 to the op-code, do you also have the pipelining issue that exists for the MOVD op-code?
  • kuronekokuroneko Posts: 3,623
    edited 2014-07-01 06:08
    Tapperman wrote: »
    So by adding 512 to the op-code, do you also have the pipelining issue that exists for the MOVD op-code?
    It does exist here as well. But since there is another add and the djnz in between it all works out.
Sign In or Register to comment.