IF statements seem to interfere with pulse reads
Ogborne
Posts: 3
The following program gives different values for the four times when the If statements are enabled. Seem that only the first two tiem are read in this case.
Any ideas anybody?
Using a remote control that is set to control a Sony TV (Not the one supplied by parallax.
' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word (4)
remotecode VAR Byte
index VAR Nib
DO
remotecode=0
DO
RCTIME 9,1,time(0)
LOOP UNTIL time(0) > 1000
PULSIN 9, 0, time(0)
'IF time(0) >600 THEN remotecode.BIT0=1
PULSIN 9, 0, time(1)
'IF time(1) >600 THEN remotecode.BIT1=1
PULSIN 9, 0, time(2)
' IF time(2) >600 THEN remotecode.BIT2=1
PULSIN 9, 0, time(3)
' IF time(3) >600 THEN remotecode.BIT3=1
IF (remotecode < 10) THEN remotecode=remotecode+1
IF (remotecode =10) THEN remotecode=0
FOR index = 0 TO 3
DEBUG CRSRXY, 0, 4 + index , "time(", DEC index, ")",
CRSRXY, 9, 4 + index , DEC time(index)
NEXT
PAUSE 500
LOOP
Any ideas anybody?
Using a remote control that is set to control a Sony TV (Not the one supplied by parallax.
' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word (4)
remotecode VAR Byte
index VAR Nib
DO
remotecode=0
DO
RCTIME 9,1,time(0)
LOOP UNTIL time(0) > 1000
PULSIN 9, 0, time(0)
'IF time(0) >600 THEN remotecode.BIT0=1
PULSIN 9, 0, time(1)
'IF time(1) >600 THEN remotecode.BIT1=1
PULSIN 9, 0, time(2)
' IF time(2) >600 THEN remotecode.BIT2=1
PULSIN 9, 0, time(3)
' IF time(3) >600 THEN remotecode.BIT3=1
IF (remotecode < 10) THEN remotecode=remotecode+1
IF (remotecode =10) THEN remotecode=0
FOR index = 0 TO 3
DEBUG CRSRXY, 0, 4 + index , "time(", DEC index, ")",
CRSRXY, 9, 4 + index , DEC time(index)
NEXT
PAUSE 500
LOOP
Comments
I was going to add code tags for readability. But I can't edit your post. If you could put [noparse] at the end[/noparse] for me that will help us read your code.
Paul
EDIT: Perhaps if I was a Moderator.
Welcome to the forum!
Try doing all of your PULSINs before doing any of the IFs. In your current program, the IFs are probably taking enough time to execute that a subsequent PULSIN doesn't get started in time to catch the next pulse.
Ditto doggiedoc's suggestion regarding your code formatting:
-Phil