Shop OBEX P1 Docs P2 Docs Learn Events
push switch input — Parallax Forums

push switch input

kingnebkingneb Posts: 65
edited 2005-10-12 06:01 in General Discussion
How do you read the status of a push switch on ra.0·and index a count variable when it goes high.· I want to decrement the count variable when·a push switch is on ra.1·is pushed.· I also want the microcontroller to ignore the push switches that are held down (only recognizes a seemingly·instantanious push).· Actually the push switch equivilents·are bits on the pc's parallel port.· That is why the "held down" thing is critical.· If that bit remains hi, the byte variable with increase to 255 at the rate of gazillion times, lol.· i would like·SX/B code please.

Thanks·smile.gif

Post Edited (kingneb) : 10/12/2005 2:45:19 AM GMT

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-12 03:35
    This (partial listing) should get you started:

    Main:
    · IF RA.0 = 1 THEN
    ····INC count
    ··· DO
    ····· WAIT_MS 25
    ··· LOOP UNTIL RA.0 = 0
    · ENDIF

    · IF RA.1 = 1 THEN
    ····DEC count
    ··· DO
    ····· WAIT_MS 25
    ··· LOOP UNTIL RA.1 = 0
    · ENDIF

    I put a 25 ms debounce delay in to prevent very fast bounce from causing false triggering.· WAIT_MS is the label to a subroutine that holds the PAUSE instruction (so that PAUSE is only compiled once).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • kingnebkingneb Posts: 65
    edited 2005-10-12 03:50
    Should I put pull up resistors on both of the inputs?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-12 03:53
    Since you're looking for a transition from 0-to-1, you'll want pull-downs to keep them low until a valid signal comes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-12 04:24
    Nope, that program won't even compile. Do you have hardware to test on? If not, use the simulator attached to SX/B to troubleshoot your code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • kingnebkingneb Posts: 65
    edited 2005-10-12 04:35
    How come when I start the program I get a series of error messages saying the simulator does not exist? I have been dealing with it for months. How can I fix it?
  • kingnebkingneb Posts: 65
    edited 2005-10-12 04:51
    This is what I have been doing, reading parallel data off the port with this program (see attached).· It works, it just is inflexable because I am working with two PWM chips and a chip with eight inputs and eight outputs.· To save space I·will use the control bits of the parallel port for the increment and decrement of both PWM chips (SC18's with the attached program running, modified with the increment and decrement).
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-12 04:57
    Well, there's the tried-and-true method of downloading the latest version of the software.· You don't say what you version you have, but the simulator has not been part of the installation "for months."· You can get it here:

    http://www.parallax.com/sx/downloads.asp

    Still, you don't need the simulator running to see that you've got a tremendous number of errors.· SX/B may be easy to use, but it has to be treated as seriously as assembly language.· Sloppy programming habits tolerated by other versions of BASIC will bite you in SX/B.

    Obvious problems:
    · - "count" is an SX/B keyword (so it can't be used as a variable name)
    · - "hi" and "lo" are not keywords
    · - "wait_ms" is not defined or coded
    · - "wait_us" is not a keyword, and not defined and coded as a subroutine
    · - You have math that would exceed eight bits

    I think you get my point.· You didn't spell it out, but you seem to want to PWM the RB.0 port based on the value of the counter.· I've attached a program that does what I think you want it to do.· It compiles and runs in the simulator just fine (I'm in a hotel right now, so I have no hardware to actually run the program on).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-12 04:59
    Our posts crossed -- have a look at my program and see if you can modify it for your needs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • kingnebkingneb Posts: 65
    edited 2005-10-12 05:56
    That program PWM's from zero to 255. I am doing ten speeds, so the counter has to increment about 255 / 10. Probably a better way of doing it. What is the __PARAMCNT variable used for?

    Does __PARAM1 and 2 mean the first and second parameter?

    Does WAIT_US SUB 1, 2 mean declare a sub routine that works with two parameters?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-12 06:01
    The help file (hint, hint) covers all these topics; you should spend some time going through it.

    1. __PARAMCNT is set to the number of parameters you pass to a subroutine; this can be used by the subroutine as I did in the delay routines

    2. Yes, __PARAM1..__PARAM4 are variables that carry your parameters, and are also used as working variables for keywords like PAUSE, etc.

    3. When subroutines that take parameters are delcared, you can specifiy a minum and maximum number of parameters allowed -- this helps the compiler flag self-created syntax errors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.