Shop OBEX P1 Docs P2 Docs Learn Events
Problem with MUXC instruction (I think) — Parallax Forums

Problem with MUXC instruction (I think)

WurlitzerWurlitzer Posts: 237
edited 2008-01-03 21:04 in Propeller 1
I have hit a wall on the code segment below. From another Cog, I have populated a large area of HUB Ram and the Cog in question reads a portion of that HUB Ram and places it in a table "OutputImageTable" using MOVD in a loop. This table is 48 Longs.

I have verified using Gear, that all the data in the "OutputImageTable" is correct. I have also used PropTerm to verify this data.

The code segment loops and takes 1 word at a time from the table and based upon a Bit pointer, should set/clear one of the output pins based on the MUXC instruction. This is the area that seems to fail.

The MUX_BitPointer· pointer serves 2 functions. First it is used in an "AND" with the table word and if the single bit in MUX_BitPointer and a corresponding bit in the table word are both set, I believe that the "C" flag should be set as this would be an ODD number of bits [noparse][[/noparse]1]. I then use that "C" flag in the MUXC instuction to set/clear the proper output pin but what sounds good on paper does not work so my logic must be flawed.

If I can get the output bits set/cleared (they never get set) then the ClockSet and ClockClear calls will clock that data into 16 external shift registers.

The intent of the loop is to evaluate a given bit position on each of 16 table longs, set the output pin then repeat this 32 times until all the bits have been sent to the output pins.

I would appreciated if one of the group could spot my dumb mistake.

PlaceDataToOutput
              mov tmpOutImage, #0
              mov MUX_BitPointer, #1            
              mov BitCounter, #0
              
           
NextSetOfBits
              mov RankCntr, #0                     'Clear Rank counter
              mov tbl_Output_Ptr,#OutputImageTable  'Should move the first address of OutputImageTable to tbl pointer
              add BitCounter, #1
              mov MUX_BitPointer, #1
               
ReadTableRank_W1        'This routine reads the 1st word of each rank, shift all 32 bits to the outa register
              call #ClockClear              
              movs  ModifySrcAddr,tbl_Output_Ptr 'Change Source address for instruction @ label ModifySrcAddr            
              add  tbl_Output_Ptr,#3            'Get 1st of 3 words for each rank (3 words/rank)
              
ModifySrcAddr mov tmp1, 0_0            'Pull data from table and place in tmp1. Source address is fed by MOVS above
              and tmp1,MUX_BitPointer wc     'C flag should be set if odd number of bits in result
              muxc  outa, MUX_BitPointer      'Whatever bit is set in MUX_BitPointer will be set/cleared based on C flag
              add RankCntr, #1
              
              cmp RankCntr, #MAX_CHROMATIC_RANKS  wc, wz, nr
              if_b jmp #ReadTableRank_W1       'IF < than max number of ranks get next word from table
              shl MUX_BitPointer, #1           'Check next bit position in every rank
              
              call #ClockSet                   '16 output bits have been set clock them to external Shift Register
              cmp BitCounter, #32 wc,wz, nr       'have all bits been set
              if_nz jmp #NextSetOfBits
        jmp #MainLoop 'REMOVE

Comments

  • AleAle Posts: 2,363
    edited 2008-01-03 18:24
    So... tmp1 may have 0 or 2 or anything but the bit 0 set, where do you set tmp1 ?
  • WurlitzerWurlitzer Posts: 237
    edited 2008-01-03 18:53
    Tmp1 is set via a MOVD pointing to the line @ ModifySrcAddr and yes Tmp1 may have 1 or more bits set. I verified via Gear that Tmp1 was being populated by the data from the table.

    Thanks for look at this.
  • AleAle Posts: 2,363
    edited 2008-01-03 19:07
    movd only overwrites bits 18..9, it does not touch bit 0. MOVS may be more useful.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-03 19:34
    Maybe... But there is more:

    When being unable to see the wood because of all the trees, I generally remove what is not relevant (the comments!!! If wrong they might terribly block you!
    Second I start obtimizing, i.e. "transforming" the program. This is what came out:
    PlaceDataToOutput
    
                  mov  MUX_BitPointer, #1         
    NextSetOfBits
                  mov  RankCntr,       #MAX_CHROMATIC_RANKS
                  MOVD ModifyDestAddr, #OutputImageTable
    
                  mov  MUX_BitPointer, #1   <---- The CULPRIT!!!!! REMOVE THIS LINE
        
    ReadTableRank_W1             
    ModifyDestAddr              
                  and  0-0,  MUX_BitPointer wc, NR    
                  muxc outa, MUX_BitPointer      
                 
                  add  ModifyDestAddr, threeForDest
                  DJNZ RankCntr,       #ReadTableRank_W1       
                  shl  MUX_BitPointer, #1 WZ     
                  IF_NZ JMP #NextSetOfBits
    
  • WurlitzerWurlitzer Posts: 237
    edited 2008-01-03 19:35
    The Table is populated using MOVD and that works fine according to Gear. It seems Tmp1 does retrieve the correct value again using Gear as I can look at what index is being pointed to by MOVS and the value in Tmp1 is what I expect. No matter how many bits are set in Tmp1, I do not set a single output pin.

    Again, thanks for looking at this.
  • WurlitzerWurlitzer Posts: 237
    edited 2008-01-03 21:04
    deSilva, that looks like the problem but I'll have to verify when I get home. I like your code better that's for sure. I tend to comment like crazy when I get hung up as when I try to describe what is going on sometimes the light bulb fires. The last 4 hours it has been a dim bulb.

    Thanks for looking at this and I'll post the results.
Sign In or Register to comment.