Shop OBEX P1 Docs P2 Docs Learn Events
SX chip - Port B as input — Parallax Forums

SX chip - Port B as input

HubotHubot Posts: 11
edited 2011-09-15 22:34 in General Discussion
Hi,
I am using a SX 28 chip to supply voltage via the C port and read input via port B.
It is a simple program but still it fail to work properly.
The debug screen shows that port rb changes to values such as FF when I move values to rc.
Can this rb port value change due to changes on other ports or is my SX 28 defective ?
(The program does not do any writing to the rb port but simply waits on an input, using the jb command ).
Please suggest any possible reasons for this since I have tried almost everything possible.)
Thanks.

Comments

  • David BDavid B Posts: 591
    edited 2011-08-30 14:32
    Can you attach your code to this thread, and also, describe the hardware wiring?

    For example, are all 8 port C pins wired directly to the 8 port B pins? If so then you are correct - if port C is set OUT and port B is set IN, then whatever you write to port C should be read from port B.

    I seem to remember a discussion about that there may be a slight delay after writing to C before the data will be read from B, like one instruction clock or so, but I'm not sure about that.
  • HubotHubot Posts: 11
    edited 2011-08-30 14:46
    I do not have any wires connected to my SX tech at present and I still get the problem in debug mode. I also confirmed this by connecting a led to view the status of the port in question.
    My code looks like this:
    start_point
    mode $0F
    mov !rb #$11111111
    mov !rc #$00
    mov rc #00
    step1 mov rc, #$00000101
    check1 nop
    jnb rb.0, switch_open
    mov rc, #$00000010
    jmp check2
    switch_open nop
    jmp step1
    check2 nop
    sleep

    I reduced my program to these simple steps, so that port c changes if there is an input voltage at port b pin 1. However port b goes to a value of 11111111
    and pin 1 is always set to 1, with or without applied voltage.
    The entire program uses all 8 pins of port b as input, and all 8 pins of port c as output and is based on this concept, but I cannot go any further if I cannot even get this correct.
    I'm stuck and wondering if it could be my SX chip. Will greatly appreciate any assistance. Thanks again.
  • ZootZoot Posts: 2,227
    edited 2011-08-30 15:19
    You are setting Port B to INPUTS and Port C to OUTPUTS. As David B wrote, are the port C pins connected to the port B pins? If yes, then I would expect to see #%0000_0101 in Port B. If NOT, then it just depends on what you've connected to Pin RB.0

    If you hit the sleep, you can't trust your debug -- all pins go to inputs and if C pins are connected to B pins, they'd all be floating.
  • David BDavid B Posts: 591
    edited 2011-08-30 15:54
    Port C only sends its voltage to the metal pins. If you set port C as OUT then write $FF to port C, then you should measure a few volts on any port C pin. If you write 0 then you should measure about 0 volts.

    If you want to read that value from port B then you need to connect a wire from each port C pin to the same bit of the port B pin.

    It would be a good experiment to start by connecting just one bit of port C to port B, and see that bit change in the program.

    When you're experimenting, it would be good practice to use a resistor of about 1000 ohms instead of a wire so if you accidently set both ports OUT then not much current will flow. Since an IN port is so much higher impedance than 1000 ohms, the correct program should still work properly.
  • HubotHubot Posts: 11
    edited 2011-09-01 05:50
    Pin RB.0 is connected directly to the Tech board Vdd voltage out. No pins from port C are connected to any pins of port B.
    Is there a simple test I can do using the IF statement? I tried using the statement " if rb.0 = 0" but did not get the required result.
  • ZootZoot Posts: 2,227
    edited 2011-09-01 07:10
    Given your program, I would expect to see #$00000010 at RC (the result of the JNB RB.0 failing, because you've tied RB.0 high). However, your program then goes to "sleep" immediately, which sets all pins to inputs, so you won't see a stable value (and certainly not a high value) at any of your RC pins. Also you don't really want this: #$00000010. You want #%00000010 which indicates a BINARY number, not hex.

    Try something like this:
    start_point
    mode $0F
    mov !rb #%11111111 ' you had a hex indicator here, not binary
    mov !rc #$00
    
    mov rc, #%1111_1111  ' you had a hex indicator here, not binary
    
    check1:
    nop
    
    jnb rb.0, @pin_low
    
    pin_high:
    mov rc, #%0000_0000
    jmp @check1
    
    pin_low:
    mov rc, #%1111_1111
    jmp @check1
    
    

    In the above, I would expect all RC pins to go high if RB.0 is tied LOW, and all RC to go low if RB.0 is tied HIGH. The @ symbols on the jumps are to ensure page boundaries are crossed properly (in your short program, probably not needed, but I'm playing it safe).
  • HubotHubot Posts: 11
    edited 2011-09-02 10:46
    Thanks man. I am a bit closer to solving the problem but something is still terribly wrong and confusing.
    your programs works fine with all of RC set low. However if I change the bit configuration so that some of the pins are high and some are low I run into problems.
    In the code below:
    With RB,0 set low I get the one led on "0000_0010". However with RB.0 set high I get all 3 leds on "0000_0111", instead of just 2 "0000_0101".
    I am so close yet so far from a solution.

    start_point mode $0F mov !rb #%11111111 ' you had a hex indicator here, not binary mov !rc #$00 mov rc, #%0000_0000 ' you had a hex indicator here, not binary check1: nop jnb rb.0, @pin_low pin_high: mov rc, #%0000_0101 jmp @check1 pin_low: mov rc, #%1111_0010 jmp @check1
  • ZootZoot Posts: 2,227
    edited 2011-09-02 12:34
    Post your actual code.
  • HubotHubot Posts: 11
    edited 2011-09-03 12:46
    device SX28L, osc1mhz, turbo
    device turbo,
    reset start_point
    freq 50000000 ; 50 Mhz

    ;;;;;;;;;;;;; Definition Of Symbols
    count1 equ $08
    counter = 9
    mnum = $00
    port_ra =$00
    port_rb =$00
    port_rc =$00
    temp_reg =$00
    two = $00
    tre = $00
    fou = $00
    fiv = $00
    six = $00
    ffff = $16
    delay = $12
    work = $0c
    h = $00
    i = $00
    j = $00
    watch count1, 16, UDEC
    org 0

    start_point nop ; I tried each of the 2 modes below with no change
    ;mode $0D ; set trigger
    ;mov !rb, #%0000_0000
    ;mode $0C ; set direction mode
    ;mov !rb, #%0000_0000
    mode $0F ; set direction mode
    mov !rb, #%11111111 ; set as input
    mov !rc, #%00000000 ; set as output
    mov rc, #%00000000 ; set low

    step_1 nop
    mov rc, #%00000000

    check_1 nop
    jb rb.0, @switch_close ; pin rb.0 set high by sx Vdd port
    jnb rb.0, @switch_open ; connection removed from rb.0 (no voltage applied)
    nop
    switch_open mov rc, #%0000_0101 ; all 3 led connected rc.0,rc.1,rc.2 lights (should only be 0 & 2)
    jmp @check_1


    switch_close nop
    mov rc, #%0000_0010 ; only led connected to rc.1 lights as expected.
    jmp @check_1
  • ZootZoot Posts: 2,227
    edited 2011-09-04 07:43
    switch_open mov rc, #%0000_0101 ; all 3 led connected rc.0,rc.1,rc.2 lights (should only be 0 & 2)
    

    Seems like it should work as expected. Have you tried this with a different chip?
  • HubotHubot Posts: 11
    edited 2011-09-04 10:35
    Yes I did. I have a new SX28 chip which I purchased years ago. I replaced the chip with this new chip since I too believed maybe it was defective, but I got exactly the same result.
  • ZootZoot Posts: 2,227
    edited 2011-09-04 18:04
    Seems like it should work. I'll take a look again tomorrow when I'm not blurry from working all day :)
  • ZootZoot Posts: 2,227
    edited 2011-09-05 17:24
    I'll try this out over the next few days and see. I haven't run code through the compiler yet (been very busy).
  • HubotHubot Posts: 11
    edited 2011-09-06 22:10
    Ok thanks a lot.
  • HubotHubot Posts: 11
    edited 2011-09-15 22:12
    I am now using a basic stamp instead of the SX and I believe the problem was due to the circuit. Thanks for your advice.
  • ZootZoot Posts: 2,227
    edited 2011-09-15 22:34
    Glad it worked out. Sorry, haven't had a chance to get into the workshop at all in the last month.
Sign In or Register to comment.