In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Tracy Allen wrote: To be sure it would work, I modified the demo program to detect transisitons using a state machine dependent on current state, past state and operators, XOR, AND. That replaces the problematic wkpnd_b register to indicate which input caused the event. The program displays the contents of rb, wkpnd_b, and the state variables for all transistions, 0->1 transitions, and 1->0 transitions. WKEN_B is enabled to wake up on change, even though the contents of wkpnd_b are not useful. Andrew, I tried your suggestions. Moving the capture of wkpnd_b up before the port initializations did not make a difference. The wakeup on output pin rb4 was an artifact of trying out too many alternatives. As it stands now, it is using rb0-rb2 and rb7 as wakeup inputs. On rb pins initialized as outputs, wkpnd_b returns a zero for outputs iniitialized high, and a one for outputs initialized low. I did turn on the pullups in this version, but that did not make a difference. In my setup, there are external pullups and RC debounce. This should also work with external pulldowns (with internal pullups off). I see you're right about the interrupt, that it could clobber the serial code. Interrupts are not enabled in this program, but that would have to be taken care of if they were. If the program needs to test for transitions while the program is awake, it could run the state machine code in an ISR, or it could run that same code frequently enough in the main loop. In a program that stays awake, the wkpnd_b register works okay to detect transitions. It is problematic only after wakeup from SLEEP. Dan, I think the SX series have the same glitch as the PIC16C5x series, that all the outputs briefly become inputs when the chip wakes up from SLEEP. This gap is 18 milliseconds on the SX20 and SX28, and it can be reduced to as short as 0.15 millisecond on the SX48 and SX52. I'm puzzled by the issue of having to manually restore the outputs. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=106511#m108031 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)