Shop OBEX P1 Docs P2 Docs Learn Events
Edge Detection — Parallax Forums

Edge Detection

hainguyen51hainguyen51 Posts: 6
edited 2008-10-24 16:52 in General Discussion
Hi,

I need to detect an edge of a signal (+ or -). I have tried to use the example in the manual but it doesn't seem to work. Anyone knows how please let me know. In the main program, I would like to set rc.0 "high" when a positive edge is detected.

Thanks
Hai

start
··MOV·M,#$0F····;Set up MODE register.
··MOV·!RB, #$FF···;Set $00 make RB all Inputs.
··MOV·!RC, #$00···;Set $00 make RC all Outputs.
··MOV·M,#$0E····;Set up MODE for PULL-UP configuration.
··MOV·!RB, #$00···;Set $00 make RB all inputs' Pullup.
··MOV·!RC, #$00···;Set $00 make RC all Outputs' Pullup.
;
··MOV·M,#$0A
··MOV·!RB, #$00···;Set $00 make +slope·detect at RB pins.
;
main
··MOV·M,#$09
··MOV·!RB,#$00
· JMP·main

Comments

  • BeanBean Posts: 8,129
    edited 2008-10-24 14:58
    When you "read" the WKPND_B register (MODE $09), the bits get put into the W register (actually the register and W values are swapped).

    So I'd try something like:

    start
    · MOV M,#$0F ;Set up MODE register.
    · MOV !RB, #$FF ;Set $00 make RB all Inputs.
    · MOV !RC, #$00 ;Set $00 make RC all Outputs.
    · MOV M,#$0E ;Set up MODE for PULL-UP configuration.
    · MOV !RB, #$00 ;Set $00 make RB all inputs' Pullup.
    · MOV !RC, #$00 ;Set $00 make RC all Outputs' Pullup.
    ;
    · MOV M,#$0A
    · MOV !RB, #$00 ;Set $00 make +slope detect at RB pins.
    ;
    · MOV M,#$09· ; Prepare to·use WKPND_B register
    · MOV W,#$00· ; Assume all bits off initially
    · MOV !RB,W····; Zero all edge detection bits
    · NOP·········· ·· ; Might be needed ???
    ;
    main
    · MOV !RB,W ; This will put the register bits in W
    · TEST W···· ; Is W zero ?
    · SZ··········· ; Yes, then no edges detected, so skip SETB
    · SETB RC.0· ; Edge detected so set RC.0
    · JMP main


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 10/24/2008 3:05:13 PM GMT
  • hainguyen51hainguyen51 Posts: 6
    edited 2008-10-24 16:52
    Hi Bean,

    I tried the codes you suggest. What I expect to see is as soon as I send a + slope rb.0 for example, I should see a permanent "hi" signal on rc.0. The reality is I just saw a short hi pulse then rc.0 turns "lo" right away. Please advise.

    Thanks
    Hai



    start
    · MOV M,#$0F ;Set up MODE register.
    · MOV !RB, #$FF ;Set $00 make RB all Inputs.
    · MOV !RC, #$00 ;Set $00 make RC all Outputs.
    · MOV M,#$0E ;Set up MODE for PULL-UP configuration.
    · MOV !RB, #$00 ;Set $00 make RB all inputs' Pullup.
    · MOV !RC, #$00 ;Set $00 make RC all Outputs' Pullup.
    ;
    · MOV M,#$0A
    · MOV !RB, #$00 ;Set $00 make +slope detect at RB pins.
    ;
    · MOV M,#$09· ; Prepare to·use WKPND_B register
    · MOV W,#$00· ; Assume all bits off initially
    · MOV !RB,W····; Zero all edge detection bits
    · NOP·········· ·· ; Might be needed ???
    ;
    main
    · MOV !RB,W ; This will put the register bits in W
    · TEST W···· ; Is W zero ?
    · SZ··········· ; Yes, then no edges detected, so skip SETB
    · SETB RC.0· ; Edge detected so set RC.0
    · JMP main


    Bean
Sign In or Register to comment.