Shop OBEX P1 Docs P2 Docs Learn Events
WKED Question — Parallax Forums

WKED Question

mullintpkmullintpk Posts: 5
edited 2010-08-31 10:40 in General Discussion
Hello,

Is this forum still active?

If so, can somebody direct this new programmer to information which will help me understand how to direct my SX28 to respond to falling edge input signals rather than both falling and rising edge signals?


My application is this: an external signal delivered from a function generator sends a signal to a configured input pin. The output of the SX delivers a fixed width pulse to external drive circuits. The purpose of this simple application is to allow for a manual sweep of frequency to external circuits while maintaining a fixed width pulse from the SX. I am using an external pull up resistor set-up, WKED, and WKPND mode configurations to set the pin stategy. I just can't get the SX to respond to falling edge only.

Can somebody help?

Thanks ... Patrick

Comments

  • ZootZoot Posts: 2,227
    edited 2010-08-28 21:42
    Setting the bit in WKED that corresponds to your input pin should set the interrupt trigger to be falling edge. Clearing the bit sets the trigger to be rising edge.

    The corresponding bit in WKEN must be set to 0 to enable interrupt triggering on that pin; setting the bit disables triggering.

    Your interrupt routine (when triggered) must swap/clear the values in WKPND to check for the edge.

    If it doesn't work, then either your circuit is bad or your code is bad. Have scoped the input pin to be sure the the falling edge is a logic 0?

    Posting your whole program would help to check for errors in the code.
  • mullintpkmullintpk Posts: 5
    edited 2010-08-29 13:52
    Hello Zoot,

    Thank you for your reply. I am attaching two documents:

    1) A PDF file illustrating the hardware setup used to deliver an external pulse train to the SX input pin. On the same PDF, I include a recreation of the scope trace for this operation of this circuit showing the input train of pulses, the behavior of the SX input pin, and the trace of the output pin.

    2) The program code

    I have tried two different ways to trigger the SX. The first program (not included) used an ISR to create the desired output. The second program (included as an attachment) polls for a WKPND flag and calls to a sub routine to initiate the desired output. Both programs result in the same output.

    Any help would be greatly appreciated.

    Thank you again ... Patrick
  • ZootZoot Posts: 2,227
    edited 2010-08-30 07:34
    I don't see why you keep initializing the edge interrupt (three times actually -- at the start of your program, in the main loop, and in the "pulse" subroutine). Once the edge interrupts are set up, all you need to do is check/clear WKPND and make decisions based on the results.
  • mullintpkmullintpk Posts: 5
    edited 2010-08-30 08:20
    Hi Zoot,

    The programming slop is an act of desperation. I have not been able to succesfully troubleshoot the problem and have been trying every option I can think of to eliminate the rising edge output of the SX. Which, speaking to the observation you mentioned, is exploring whether or not the WKED configuration is resetting itself as the flow moves to different parts of the program.

    Where on the debug menu is it possible to see the Mode register configuration bits displayed? I can see register RB, but where is !RB ?

    Can you, or anybody on the forum, comment about the hardware setup?

    Thanks for you help ...
  • ZootZoot Posts: 2,227
    edited 2010-08-30 08:39
    You only need to set up the edge interrupts ONCE.

    After that, when you check WKPND, remember that really you are SWAPPING W and WKPND (what was in WKPND will go into W, and what was in W will go into WKPND).

    Personally, if you are not using an ISR when the edge is triggered, I wouldn't use WKPND/WKEN at all -- I would just poll the pin.
  • mullintpkmullintpk Posts: 5
    edited 2010-08-30 12:15
    Hi Zoot,

    Thanks Zoot!

    I did think about polling the pin, but this method doesn't help discriminate between rising and falling edges without extra code, which I don't want to invent as the SX does this already through WKED.

    Let me ask the question in another way. Can situations occur where non-optimal signals into the input pin can cause the SX to fail to discriminate between rising and falling edges? Have you experienced something like this before? Are there characteristic signs that show up on scope traces that indicate that there may be a problem?

    My programming may be a little wet behind the ears, but my electronics are strong. Please feel free to use the big words or let me have it with both barrrels. I'll learn something either way.

    Take care ...
  • ZootZoot Posts: 2,227
    edited 2010-08-30 12:49
    You can poll a pin for an edge. It's done all the time. You just a need a bit flag for storing the "last" state.

    A pin could bounce back and forth between states, but when using WKED/WKPND/WKEN, only the first state change (of the appropriate edge) will be captured (until WKPND is cleared, of course).
    :again
    ; poll a pin for a falling edge on RB.0
    MOV W, RB  ;stash the pin state
    MOV tmp, W ; stash it
    JB tmp.0, :again ; it didn't fall yet, try again
    XOR W, stateVar ; stateVar is the "last" saved state of the pin(s)
    AND W, #1 ; isolate bit
    JZ :again ; if bit is unchanged, try again
      MOV stateVar, tmp ; otherwise, save the current state for the next time
    ; now do whatever you need to do when the pin changes
    ; code
    ; code
    JMP :again
    
  • mullintpkmullintpk Posts: 5
    edited 2010-08-31 10:40
    Thanks Zoot,

    I see the logic behind your suggestions. Wish I thought of that. I will be assembling and testing later tonight. I will let you know how it goes.

    Thanks Again ... Patrick
Sign In or Register to comment.