Shop OBEX P1 Docs P2 Docs Learn Events
newbie to interrupts... — Parallax Forums

newbie to interrupts...

johnny_bjohnny_b Posts: 28
edited 2005-03-08 23:47 in General Discussion
Hi guys,

I just moved some simple projects from stamp to sx. This is the first time I am attempting to use interrupts.
For the trial, I used a serial (custom) 2x16 LCD, with some text displaying, and I wanted to use 3 buttons
connected to 3 interrupt ports, each one lighting·a LED when pressed, LED off when depressed, continuously
and realtime, independently from the scrolling text. Simple and have no meaning, I know rolleyes.gif , but just for
trying them... Anyway, it did not work. So where did I go wrong? (.sxb attached)
Please help!!!confused.gif

br, Johnny

(ps. sorry for custom LCD commands...)

Comments

  • johnny_bjohnny_b Posts: 28
    edited 2005-03-08 09:04
    (the LCD message part works fine!) roll.gif
  • johnny_bjohnny_b Posts: 28
    edited 2005-03-08 12:29
    OK, here's a modified version, still a bit unstable...
  • kb2hapkb2hap Posts: 218
    edited 2005-03-08 12:48
    I could be wrong but at 4 mips unless your just playing I don't think you need an ISR to see a couple of buttons. also be careful of the bounce on the buttons.
    let me look at it alittle more.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    DTQ
  • johnny_bjohnny_b Posts: 28
    edited 2005-03-08 13:07
    of course... wink.gif this is a trial. I do not care about leds+buttons... just to see how it works for real!
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-03-08 14:44
    Actually, the code looks good from a casual perusal.

    1. Yes, you need to take care of de-bounce. Switches 'bounce' on-off-on-off for a few milliseconds when activated. The symptom you should see with your current code is when you press the button the led's flicker for a bit, then stabilize randomly on or off.

    2. I don't know what you are using for a voltage source for your buttons -- you can't just connect them between the SX pin an +5, you also need a 'pull-down' resistor to give you a 'hard' zero. See the "Button" command in the BS2 PBasic manual for a suggested circuit.
  • johnny_bjohnny_b Posts: 28
    edited 2005-03-08 20:49
    yes, I have a 10k pulldown, the button shorts to +5v, and has a series 220Ohm.
    you're right, this is the symptom, it flickers randomly. what's more interesting, that sometimes a different led is also activated...????? (trial2.sxb)
    the tricky part in this design that some pins on port B are not interrupts, and I do not really know, how to separate them from each other?
    and what are these
    WKPND_B = %00000000
    WKED_B = %11111111
    WKEN_B = %00011111
    lines mean at all? do I set their values bit-by-bit, or what? the values in the code were obtained by trying several possible combinations wink.gif
    please explain it to me like to a 6 year old wink.gif

    johnny
  • NateNate Posts: 154
    edited 2005-03-08 23:47
    johnny_b

    1) The SX has programmable internal pullup resistors. (MODE $0E)

    2) The random action on some inputs when activating other inputs is usually due to the lack of pullups (or pulldowns)

    3) When you enable interrupts, using the MODE $0B, you define what inputs will be interrupt enabled.· (eg. MOV !rb, #%11111110 enables interrupt only on rb.0 )

    4) See SX-Key Development System Manual Section 10.
Sign In or Register to comment.