Edge Detection
hainguyen51
Posts: 6
Hi,
If anyone knows what's wrong with this code please let me know. I am sending o square signal of 1Hz into rb.0 and try to create a small pulse at rc.0 everytime the + slope comes along. I tried this and the output rc.0 is always = low. I am trying to figure out how the edge detection works first before I have a real application of delaying the signal at rb.0 appears at rc.0.
Thanks
Hai
device·SX28L,OSCHS3,TURBO,STACKX_OPTIONX ·
·id·'ECU103'
·reset·start···;Jump to reset_entry on reset.
·FREQ·50000000····;50MHz target frequency.
;
;Define inputs, outputs, and registers
;
··ORG·$00····;Program start at address 00h.
interrupt
··RETI
;
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 ???
· MOV·rc, #$00
;
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
·JMP·output
· JMP main
;
output
·SETB RC.0
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·CLRB·rc.0
· MOV W,#$00
·JMP main
·
If anyone knows what's wrong with this code please let me know. I am sending o square signal of 1Hz into rb.0 and try to create a small pulse at rc.0 everytime the + slope comes along. I tried this and the output rc.0 is always = low. I am trying to figure out how the edge detection works first before I have a real application of delaying the signal at rb.0 appears at rc.0.
Thanks
Hai
device·SX28L,OSCHS3,TURBO,STACKX_OPTIONX ·
·id·'ECU103'
·reset·start···;Jump to reset_entry on reset.
·FREQ·50000000····;50MHz target frequency.
;
;Define inputs, outputs, and registers
;
··ORG·$00····;Program start at address 00h.
interrupt
··RETI
;
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 ???
· MOV·rc, #$00
;
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
·JMP·output
· JMP main
;
output
·SETB RC.0
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·NOP
·CLRB·rc.0
· MOV W,#$00
·JMP main
·
Comments
You do realize that the pulse on RC.0 is going to be VERY small ?
Are you sure the RB.0 pin is going low from your 1hz signal ?
Do you have an oscilloscope ? If yes, then check the RB.0 and RC.0 pins with it.
P.S. I also tried the program I posted in your other thread (try to keep things in one thread it makes life easier) and that program worked fine too. RC.0 went high on the first pulse, then stayed high.
Are you using a development board ? Or just the SX on a breadboard ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter
www.iElectronicDesigns.com
·
Thanks
Hai
Would you please to take a look for me to find out why once in a while I have an extra pulse in between the right ones. Basically, I have 1 Hz signal to rb.0, as soon as the + edge arises, I delay 2t then I have a hi pulse of 1t then goes lo. I just want to shift 1Hz signal a delay of 2t.
Thanks
Hai
device SX28L,OSCHS3,TURBO,STACKX_OPTIONX
id 'ECU103'
reset start ;Jump to reset_entry on reset.
FREQ 50000000 ;50MHz target frequency.
;
;Define inputs, outputs, and registers
;
clock_select = RA.1
clock_pin = RB.0
mon_pin = RB.1
time1_en = RB.2
delay_count = $08
delay_count1 = $09
delay_count2 = $0A
time_count = $0B
loop_count = $0C
;
ORG $00 ;Program start at address 00h.
interrupt
RETI
;
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
;
MOV rc, #$00
MOV delay_count1,#10 ;Set delay_count1 for 3min. Sub-program.
MOV delay_count2,#10 ;Set delay_count2 for 3min. Sub-program.
;
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
JMP output
JMP main
;
output
start_delay1 MOV time_count,#40
count_loop1
CALL delay
DJNZ time_count,count_loop1
;
start_delay2 MOV time_count,#20
count_loop2 SETB rc.0
CALL delay
DJNZ time_count,count_loop2
CLRB rc.0
JMP main
;
delay ;Long delay loop.
delay1
delay2 NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DJNZ delay_count2, delay2
DJNZ delay_count1, delay1
MOV delay_count1,#10
MOV delay_count2,#10
RET
Please disregard the previous question. I already figured that out. All I did is to add MOV !RB, #$00 to clear the content of pending register during running delay, I no longer have an extra pulse any more. Now using this code, I can ship a signal from 0 all the way to the next pos. edge by changing time_count (at start_delay1, currently #40). Anyway, your first suggestion is very helpful.
Thanks
Hai