Shop OBEX P1 Docs P2 Docs Learn Events
Inverting Smart Pin mode %01101 — Parallax Forums

Inverting Smart Pin mode %01101

JimFouch2JimFouch2 Posts: 26
edited 2021-01-04 22:01 in Propeller 2
Description from P2 Docs.... %01101 = Accumulate A-input positive edges with B-input supplying increment (B=1) or
decrement (B=0)


I'm looking at using this mode to keep track of the steps for a stepper motor controller.

Only issue is I don't see a way of inverting the logic for the B pin. Sometimes on an axes, I will want to invert the direction. I know the the simple way would just invert the sign on the reading of the smart pin, but that really only works if you start from zero.

When the device this is attached to hits it's home position, I normally load an offset into a counter. I then add whatever the hardware counter has detected. Without the ability to invert the B Pin logic, I think if I keep my offset separate from the SmartPin's output, I should be ok.


Comments

  • Are you doing a wrpin to set up the B pin?

    I remember OzProp telling me there are actually two ways to invert inputs in the WRpin config, I think you get a bit in the 'pin redirect' 4 bits, as well as a bit in the 'cio' field, and if you select both you're back to 'non inverted'. Fwiw

  • cgraceycgracey Posts: 14,153
    edited 2021-01-04 22:24
    In the WRPIN data, the top two nibbles select PINA and PINB inputs to the smart pins. The MSB of each nibble controls inversion. Is this what you need? This is from page 72 of the silicon documentation.
    D/# = %AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0
    
     %AAAA:  'A' input selector
                 0xxx = true (default)
                 1xxx = inverted
                 x000 = this pin's read state (default)
                 x001 = relative +1 pin's read state
                 x010 = relative +2 pin's read state
                 x011 = relative +3 pin's read state
                 x100 = this pin's OUT bit from cogs
                 x101 = relative -3 pin's read state
                 x110 = relative -2 pin's read state
                 x111 = relative -1 pin's read state
    
     %BBBB:  'B' input selector
                 0xxx = true (default)
                 1xxx = inverted
                 x000 = this pin's read state (default)
                 x001 = relative +1 pin's read state
                 x010 = relative +2 pin's read state
                 x011 = relative +3 pin's read state
                 x100 = this pin's OUT bit from cogs
                 x101 = relative -3 pin's read state
                 x110 = relative -2 pin's read state
                 x111 = relative -1 pin's read state
    
  • cgraceycgracey Posts: 14,153
    You can also control inversion via the low-level pin configuration, which takes bits 8..20 in the WRPIN data.

    In the logic mode %0000_CIOHHHLLL, the %I bit controls IN inversion.

    Pin_Modes.png
    1045 x 683 - 8K
  • Cluso99Cluso99 Posts: 18,069
    Can you flip the inversion without upsetting any count in progress?
  • evanhevanh Posts: 15,916
    Cluso99 wrote: »
    Can you flip the inversion without upsetting any count in progress?
    For that smarpin mode, counting occurs on the rising A input. As long as A is not rising at the same time then inverting B will be clean.

  • I guess I didn't read the docs close enough. Looks like this can be done easily.

    Thanks Chip.
  • cgracey wrote: »
    You can also control inversion via the low-level pin configuration, which takes bits 8..20 in the WRPIN data.

    In the logic mode %0000_CIOHHHLLL, the %I bit controls IN inversion.

    Every time when that table is referenced somewhere it should also be noted that nobody has to learn any of the bit patterns, theese days. There are predefined symbols that can be used to make everything much easier. See end of Spin2 documentation Chapter "Built-In Symbols for Smart Pins".


Sign In or Register to comment.