Shop OBEX P1 Docs P2 Docs Learn Events
Is this glitch free? — Parallax Forums

Is this glitch free?

Chad GeorgeChad George Posts: 138
edited 2009-02-12 18:08 in Propeller 1
I'm sure doing it this way is wrong because there is a short time between instructions where the output is invalid.

    tmp := (tc & $3F) << 1
    outa &= (tmp | %11111111_11111111_11111111_10000001) 
    outa |= tmp




Does anyone know if the following code updates pins simultaneously or will there still be a small glitch in the output?

outa[noparse][[/noparse]6..1] := tc

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2009-02-11 06:09
    Chad George said...
    I'm sure doing it this way is wrong because there is a short time between instructions where the output is invalid.

        tmp := (tc & $3F) << 1
        outa &= (tmp | %11111111_11111111_11111111_10000001) 
        outa |= tmp
    
    

    Yep, this will glitch because you are storing the result in outa.
    Chad George said...
    Does anyone know if the following code updates pins simultaneously or will there still be a small glitch in the output?

    outa[noparse][[/noparse]6..1] := tc
    

    I think it does. If it doesn't you could try something like this
        tmp := (tc & $3F) << 1 
        outa := tmp | (outa & (tmp | %11111111_11111111_11111111_10000001))
    
    
  • Chad GeorgeChad George Posts: 138
    edited 2009-02-11 15:07
    I'm really paranoid about assignments to outa being completely atomic so it doesn't ever affect what other cogs are doing.
    I don't know if you can read the value of outa ... do one or more operations with it then assign it back and be safe from unintended consequences.

    Thats why I'm a little concerned about doing it this way in SPIN...if it was assembly then I'd know exactly what was going to happen.

    I kinda figure the array index notation was designed for this scenario, but I wanted to make sure before relying on it. I am pretty certain it will not affect the status of other pins, but I don't know if it updates all pins in a single atomic action.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-11 15:28
    If you look at the Spin interpreter source kindly made available by Chip, you'll see that the special register writes like "outa[noparse][[/noparse] 6 .. 1 ]" are done atomically. A bitmask is created, the new value is shifted into place, combined with the existing contents of the register, then stored back into the register with a final MOV.
  • heaterheater Posts: 3,370
    edited 2009-02-11 15:47
    Don't forget that every COG has it's own outa register. The outputs of all COGs outa registers are ORed together to get the actual pin output.

    So there there is no problem with atomicity in reading/modifying/writing outa. It's yours no one else can get in between. Just don't go setting bits that are not yours.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Ken PetersonKen Peterson Posts: 806
    edited 2009-02-12 18:08
    I guess as an add-on statement, reading OUTA doesn't reflect the state of the pins, just the state of the OUTA register in that cog. If you want pin state, you need to read INA.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."

    - Bjarne Stroustrup
Sign In or Register to comment.