Shop OBEX P1 Docs P2 Docs Learn Events
SX 48 - reading from reg vs from pin? — Parallax Forums

SX 48 - reading from reg vs from pin?

CounterRotatingPropsCounterRotatingProps Posts: 1,132
edited 2008-08-15 00:34 in General Discussion
Just finished reading the Ubicom "SX family"·doc available here.

For input, it mentions that the SX48 can be set to read from the registry associated with the Rx pin instead of directly reading·the pin itself.

Direct read is default (and is the way it works on all other SX devices?)·

Such a feature seems weird to me... or rather, I'm clueless smhair.gif as to when this feature would be·needed.

Waiting for the input to settle?
Reading back internally from your own output?


Any examples would be appreciated.

Thanks,
Howard in Florida

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buzz Whirr Click Repeat

Post Edited (CounterRotatingProps) : 8/3/2008 12:41:33 AM GMT

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-08-04 01:13
    Howard,

    I think this is referring to reflecting the difference between the actual state of a pin and what the state should be. The register will reflect the state the pin should be in, high or low. However, external circumstances may force the pin to a different state. For example, there might be a difference between the two if you set a pin to a high output state but externally it is directly shorted to ground. The register will show the pin is trying to drive high but because of the short to ground the pin may actually be in a low state.

    There are likely other examples but that circumstance comes to mind


    - Sparks
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2008-08-06 01:45
    Sparks,

    thanks for the reply. Hmmm... I had to switch my brain up to 75mHz before realizing that you've described exactly issue as the··Sx Users Manual download_button.gif·says on pg 144 (er, at least I think so...eyes.gif·... is this correct?) ·[noparse][[/noparse]my emphasis below]· Thanks, - H
    "When a write is performed to a bit position for a port that has been configured as an input, a write to the port data register is still performed, but it has no immediate effect on the pin. If later the pin is configured to operate as an output, it will reflect the value that has been written to the data register.

    For the SX48/52BD, a control bit called PORTRD in the T2CNT2 register determines how the device reads data from its I/O ports. Clear this bit to 0 to have the device read data directly from the port I/O pins (the default operating mode). Set this bit to 1 to have the device read data from the port data registers. Under normal conditions, it should not matter which method you use to read the port data.
    However, if a port pin is configured as an output and an external circuit forces the pin to the wrong value, the value read from the port will depend on the reading mode used.
    The SX18/20/28AC and SX18/20/28AC75 always reads data directly from the port I/O pin, like the default operating mode of the SX48/52BD.
    When you read from a bit position for a port in the default operating mode, you are actually reading the voltage level on the pin itself, not necessarily the bit value stored in the port data register. This is true whether the pin is configured to operate as an input or an output. Therefore, with the pin configured to operate as an input, the data register contents have no effect on the value that you read.
    With the pin configured to operate as an output, what you read generally matches what has been written to the register."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buzz Whirr Click Repeat
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-08-06 03:50
    That is what I was trying to convey. The manual says it in a more technically correct manner.

    I almost never give any thought to this. I doubt many others do either. But it might be useful to keep in mind in special cases.

    Do you ever want to see what state an output should be driving toward? (Something in your program would have already set this so you should already know this.) Do you ever want to see what state an input would try to be if it were suddenly set to an output? (Again, something in your program would have already set this so you should already know this!) If you answer no to these questions you can simply ignore the feature and always read the values seen at the pins.

    Basically, each port on the SX has a special register that holds the output values the port should drive toward for pins that are configured as outputs. The SX48/52BD provides a way to read these registers in place of the actual pin values. This has limited usefulness.

    If you think you might have a case where this feature may be useful to you, you can probably gain enough good advise on this forum to make certain it is a good idea. Most people will never have cause to make use of this feature.

    - Sparks
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2008-08-15 00:34
    Thanks Sparks,

    it's fun sometimes to try and understand these odd features... but then again, this reminds me of something in a Unix manual from years ago:
    "... if you are reading this, you probably have the social life of a cucumber!"

    - H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buzz Whirr Click Repeat
Sign In or Register to comment.