Shop OBEX P1 Docs P2 Docs Learn Events
INPUT: How To — Parallax Forums

INPUT: How To

Fry'n ICsFry'n ICs Posts: 11
edited 2007-04-21 20:25 in General Discussion
I'm new to the SX and I'm having trouble getting info into the SX.

I have the Professional Development board and have plugged a wire from one of the push buttons into RA.0. It is my understanding that the push button has a pull up resistor and goes low when pressed.

Here is my code:

DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
ID············· "SXB 1.50"

PROGRAM Start

Start:
· input RA.0
Main:
· watch RA.0
GOTO Main

When I click the debug button, the Watch window shows RA.0 as 0 (zero) regardless of whether or not a push the button.
I've tried other pins and other buttons, but I can't ever get the input pin to read 1. Am I using the INPUT function improperly? Or perhaps I am using the Watch function wrong? Please help [noparse]:)[/noparse]

Comments

  • JonnyMacJonnyMac Posts: 8,959
    edited 2007-04-17 05:19
    You need to add a breakpoint to your program; change your WATCH directive as follows, then add a break after it:

    \ WATCH RA.0, 1, ubin
    \ BREAK

    Start the program in Debug mode, then select Poll; the watch window should change to indicate any changes on RA.0. BTW, all pins default to input, so you don't even need that INPUT line in your program. Do it like this:

    Start:
      \ WATCH RA.0, 1, ubin
      \ BREAK
      GOTO Start
    

    Post Edited (JonnyMac) : 4/17/2007 5:24:38 AM GMT
  • Fry'n ICsFry'n ICs Posts: 11
    edited 2007-04-18 03:49
    I've entered the code you gave me... but when I click the debug button to run the program in debug mode, the poll button is grayed out (disabled). I tried re-installing the software, but that didn't work. Any suggestions as to how to get the poll button working?
  • JonnyMacJonnyMac Posts: 8,959
    edited 2007-04-18 04:20
    Make sure that you don't have a resonator or other clock source connected to your SX. Also, use the Debug button, not Debug Again.
  • Fry'n ICsFry'n ICs Posts: 11
    edited 2007-04-18 04:56
    Let me start by saying that I really appreciate your assistance. I have been driving myself crazy trying to figure this out tongue.gif I can confirm that there is no auxiliary resonator and I am using the Debug option (not the debug again). I have also tried a brand new SX chip in case in nuked the other one. All for not, for the Poll button is still disabled. [noparse]:([/noparse]
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-04-18 17:54
    Fry'n ICs,

    Can you confirm that you are using an SX-Key as the programmer and not an SX-Blitz which does not support debugging?

    Also, it has been my experience that I can not "Poll" (the button is disabled) when there is a BREAK command within the program.

    Finally, I have had some trouble before trying to WATCH a single bit. In some cases it worked but in other cases it did not work. RA.0 has been reported to work whereas RA.1 reportedly does not. See WATCHing a pin with SX/B (Without using a variable) and SX/B - Watched Bit not Showing Changes for more details.

    - Sparks
  • BeanBean Posts: 8,129
    edited 2007-04-18 17:58
    Bit position zero will work. All others usually don't. It's a problem with the IDE not SX/B.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"

    Benjamin Franklin
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 8,959
    edited 2007-04-18 18:18
    You need to have the BREAK in the code -- without it the Poll button is not visible. I just copied this [noparse][[/noparse]working] code from my editor; it works as expected: when a button connected to RA.0 is pressed the status change is noted.

    DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ            4_000_000
     
    PROGRAM Start
     
    Start:
      \ WATCH RA.0, 1, ubin
      \ BREAK
      GOTO Start
    
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-04-18 20:26
    I apologize for not being clear and perhaps even sounding contradictory in my previous statement about the [noparse][[/noparse]Poll] button being disabled. I was referring to being able to poll (as in press the [noparse][[/noparse]Poll] button to force an update) an already running program that includes a Break statement.


    There are at least two choices when using Watch and Break statements along with the [noparse][[/noparse]Poll] button.

    If you include a Break statement within your program you can only have data "polled" from the program at that location. It happens automatically whenever the Break statement is encountered. This is probably preferred for the use described in this thread.

    If you do not include a Break statement you can then press the [noparse][[/noparse]Poll] button (enabled once the program is running) at any time to capture a snapshot of what the SX was seeing and doing at that particular moment.

    So with a Break statement you can poll automatically but only from one program location whereas without a Break statement you can poll data from any part of the program but only when you press the button.


    I hope this clarifies what I may have made confusing.


    - Sparks
  • Fry'n ICsFry'n ICs Posts: 11
    edited 2007-04-20 04:03
    I have tried your code and suggestions, but I still cannot get the poll button to become active. I hooked up an LED to rb.0 to watch the state of pin ra.0 and I noticed something else that seems odd to me aswell. I am under the impression that if I set rb.0 to an output and then say HIGH RB.0 that the pin will go high. I thought the was pretty much the same thing as saying RB.0 = 1. Likewise I should be able to use RB.0 = 0 and LOW RB.0 interchangably, right?

    Consider this code:

    output rb.0
    input ra.0

    Start:

    if ra.0 = 0 then
    rb.0 = 1
    else
    rb.0 = 0
    endif
    GOTO Start

    Compared to this code:

    output rb.0
    input ra.0

    Start:

    if ra.0 = 0 then
    HIGH rb.0
    else
    LOW rb.0
    endif
    GOTO Start

    When I hook an LED up to RB.0 and press the button on ra.0, the led blinks as expected with the bottom code... but nothing happens at all when I press the button using the top code. Is this what you guys would expect? Thanx for your continued support. I'll figure this thing out sooner or later [noparse];)[/noparse]
  • BeanBean Posts: 8,129
    edited 2007-04-20 13:04
    Fry,
    Any code before "Start:" will never get executed. So your "OUTPUT RB.0" and "INPUT RB.0" never get executed.

    HIGH and LOW will force the pin to be an output. "RB.0 = 1" and "RB.0 = 0" do not, they simply set the output latch. So if the pin is an input, you won't see anything on your led.

    The best way to handle this is to DEFINE the pin as an output. As in:

    LEDS PIN RB.0 OUTPUT

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"

    Benjamin Franklin
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Fry'n ICsFry'n ICs Posts: 11
    edited 2007-04-21 20:25
    Thanx Bean! The DEFINE trick you taught me seems to have solved my most recent problem. I still can't get the stupid debugger to poll (I even tried hooking everything up to a different computer)... but I guess I'll just use a logic probe to see what's going on [noparse]:([/noparse] Thank-you to everyone again for all of your help! This probably won't be the last time I come crying to you [noparse];)[/noparse]
Sign In or Register to comment.