This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HET SHFT instruction when data field is all zeroes or ones

Hi,

From what I understand from the documentation of the SHFT instruction, it does nothing (except updating the Z flag) if the data field is all zeroes or ones : data field unchanged, selected register unchanged; is this correct?

So, if one wants to mirror an input pin on an output pin, 4 instructions are needed:

  1. one SHFT to get the level of the input, with data field neither all zeroes or ones
  2. one MOV32 to set the data field of the shift out instruction (4)
  3. one MOV32 to set the data field of the shift in instruction (1) so that it never becomes all zeroes or ones
  4. one SHFT to set the output

Or did I miss something and there is a simpler way to achieve the same result?

BTW, the description of SHFT [SPNU499B, chapter 20] could be improved : the execution description lists actions after an if/else that contains jumps in both branches, which would mean that these action are never performed.

Thanks and Best Regards,

Daniel Marmier

 

  • Daniel,You could do it in 3 instructions:
    - branch on input pin = high to set output high, else to set output low.
    - set output pin = high (using shft - set data to all 1's and use one of the modes that shifts in a '1')
    - set output pin = low (using shft - set data to all 0's and use one of the modes that shifts in a '0')
  • Hi Anthony,

    Thanks for the reply, but I understood from the SHFT doc that it does nothing when data is all 1's or 0's. Could you please clarify the behavior of the SHFT instruction, especially the actions that are listed after the update of the previous bit and the note at the end?

    Thanks and Best Regards,

    Daniel Marmier
  • Daniel,

    In this case, you would use the UNC shift condition, so the HET[0] pin really doesn't matter.
    Also I think while the older HET used the Prev. bit for an edge detect, my understanding is that the newer NHET/N2HET do the edge detect in hardware so the P bit is a bit is vestigal.

    I don't see where it says the shift won't occur for all 0's or all 1's. The shift is in an always executed set of operations at the end of the psuedo-code.

    The conditions that depend on P3:P2=00 (which are all of the shift modes that you might use in this case) have to do with how the Z flag is set, and how the interrupt request is generated - no the shift.

    The note at the end - if you mean 'The immediate data field evaluates all 0s or 1s..' Then what this means is that in the psuedocode where it says 'If ((Immediate Data Field == all 0’s ' this would mean that the test is performed here pre-shift.

    In other words, if your data field is 10000...000 and you are about to shift in a 0 to the LSB, during the current loop it still evaluates 'all 0's' as false because the data field starts out that way when instruction execution begins. Even though it ends the instruction with the data field all '0s' ... that won't be evaluated as true until the next time the instruction executes.
  • Hi Anthony,

    Yes, I use UNC. OK for the P bit, only mentioned it to help locate the descriptions of actions that follow in the manual.

    The shift really does not happen when data is all 0's or 1's (at least that is what my tests with the simulator show). This is documented in SPNU499B (TMS570LS31x/21x 16/32-Bit RISC Flash Microcontroller, Technical Reference Manual), §20.5.3.22, in the paragraph describing the execution of SHFT. This is the description which I would like to have clarified, because it has jumps in both branches of an if statement, but lists further actions past the end of the if, which makes it unclear when these actions are executed or not. This is a documentation quality issue, and I have seen another post from someone having trouble with that description, which is why I am asking for clarification.

    And yes, SHFT will work when data is not all 0's or 1's, but only the first or the first few times, because the data field will normally end up being all 0's or 1's. Which requires an update of the data field before or after each shift. So my example seems to need 4 instructions after all?

    Thanks and Best Regards,

    Daniel Marmier
  • Daniel,

    Maybe you can try this program - it works for me both in the simulator and on silicon.

    It uses "SHFT" in the UNC mode with all 0's and all 1's  (alternating each loop between the two) to toggle pin N2HETx[7].

    PIN_H1_OB       .equ    7   
    CNST_25B1       .equ    0x1FFFFFF
    CNST_25B0       .equ    0x0000000
    
    LOOP        DJZ  {cond_addr=H1_OUTB_LO, next=H1_OUTB_HI, data=1}
    H1_OUTB_HI  SHFT {smode=OR1, cond=UNC, pin=PIN_H1_OB, data=CNST_25B1, cond_addr=H1_OUTB_END, next=H1_OUTB_END}
    H1_OUTB_LO  SHFT {smode=OR0, cond=UNC, pin=PIN_H1_OB, data=CNST_25B0, cond_addr=RESET, next=RESET}
    RESET       MOV32 {type=IMTOREG&REM, reg=NONE, remote=LOOP, data=1, hr_data=0}
    H1_OUTB_END BR   {event=NOCOND, cond_addr=LOOP, next=LOOP}