Incorporating time stamp with RFID reader
pja
Posts: 1
I am incorporating a time stamp into the supplied program for reader RFIDs. I want the debug menu to display how long it took the reader to detect the RFID tag.
I tried this with a loop that lasted 1 ms and recorded how many milliseconds it took for the Reader to see the tag. This simple code was demonstrated in the manual that comes with the Basic Stamp microprocessor. Unfortunately I have not found the correct way to integrate the loop with the program. I tried putting the loop before the rest of the program and it doesn't work correctly. I have also tried putting the loop after the program and it does not record the time.
Any suggestions?
The loop program is simply
timecounter VAR Word
timecounter = 0
DO
PAUSE 1
timecounter = timecounter + 1
LOOP UNTIL (IN1 =0)
The RFID reader program is:
'
[noparse][[/noparse] I/O Definitions ]
Enable PIN 0 ' low = reader on
RX PIN 1 ' serial from reader
Spkr PIN 2 ' speaker output
Latch PIN 3 ' lock/latch control
'
[noparse][[/noparse] Constants ]
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
TMidi CON 12
T38K4 CON 6
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
TMidi CON 60
T38K4 CON 45
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
TMidi CON 108
T38K4 CON 84
#ENDSELECT
SevenBit CON $2000
Inverted CON $4000
Open CON $8000
Baud CON T2400
#SELECT $STAMP
#CASE BS2, BS2E
TmAdj CON $100 ' x 1.0 (time adjust)
FrAdj CON $100 ' x 1.0 (freq adjust)
#CASE BS2SX
TmAdj CON $280 ' x 2.5
FrAdj CON $066 ' x 0.4
#CASE BS2P
TmAdj CON $3C5 ' x 3.77
FrAdj CON $044 ' x 0.265
#CASE BS2PE
TmAdj CON $100 ' x 1.0
FrAdj CON $0AA ' x 0.665
#CASE BS2PX
TmAdj CON $607 ' x 6.03
FrAdj CON $2A ' x 0.166
#ENDSELECT
LastTag CON 3
#DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM?
'
[noparse][[/noparse] Variables ]
#IF __No_SPRAM #THEN
buf VAR Byte(10) ' RFID bytes buffer
#ELSE
chkChar VAR Byte ' character to test
#ENDIF
tagNum VAR Nib ' from EEPROM table
idx VAR Byte ' tag byte index
char VAR Byte ' character from table
'
[noparse][[/noparse] EEPROM Data ]
Tag1 DATA "0101A625F5" ' random number
Tag2 DATA "0F02A69268" ' Tag at hand 1
Tag3 DATA "0F02A693F1" ' Tag at hand 2
Name0 DATA "Unauthorized", CR, 0
Name1 DATA "Tag 1 (White Card)", CR, 0
Name2 DATA "Tag 2 ", CR, 0
Name3 DATA "Tag 3 ", CR, 0
'
[noparse][[/noparse] Initialization ]
Reset:
HIGH Enable ' turn of RFID reader
LOW Latch ' lock the door!
'
[noparse][[/noparse] Program Code ]
Main:
LOW Enable ' activate the reader
#IF __No_SPRAM #THEN
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait for hdr + ID
#ELSE
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
#ENDIF
HIGH Enable ' deactivate reader
Check_List:
FOR tagNum = 1 TO LastTag ' scan through known tags
FOR idx = 0 TO 9 ' scan bytes in tag
READ (tagNum - 1 * 10 + idx), char ' get tag data from table
#IF __No_SPRAM #THEN
IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table
#ELSE
GET idx, chkChar ' read char from SPRAM
IF (char <> chkChar) THEN Bad_Char ' compare to table
#ENDIF
NEXT
GOTO Tag_Found ' all bytes match!
Bad_Char: ' try next tag
NEXT
Bad_Tag:
tagNum = 0
GOSUB Show_Name ' print message
FREQOUT Spkr, 1000 */ TmAdj, 115 */ FrAdj ' groan
PAUSE 1000
GOTO Main
Tag_Found:
GOSUB Show_Name ' print name
HIGH Latch ' remove latch
FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj ' beep
LOW Latch ' restore latch
GOTO Main
END
'
[noparse][[/noparse] Subroutines ]
' Prints name associated with RFID tag
Show_Name:
DEBUG DEC tagNum, ": "
LOOKUP tagNum,
[noparse][[/noparse]Name0, Name1, Name2, Name3], idx ' point to first character
DO
READ idx, char ' read character from name
IF (char = 0) THEN EXIT ' if 0, we're done
DEBUG char ' otherwise print it
idx = idx + 1 ' point to next character
LOOP
RETURN
I tried this with a loop that lasted 1 ms and recorded how many milliseconds it took for the Reader to see the tag. This simple code was demonstrated in the manual that comes with the Basic Stamp microprocessor. Unfortunately I have not found the correct way to integrate the loop with the program. I tried putting the loop before the rest of the program and it doesn't work correctly. I have also tried putting the loop after the program and it does not record the time.
Any suggestions?
The loop program is simply
timecounter VAR Word
timecounter = 0
DO
PAUSE 1
timecounter = timecounter + 1
LOOP UNTIL (IN1 =0)
The RFID reader program is:
'
[noparse][[/noparse] I/O Definitions ]
Enable PIN 0 ' low = reader on
RX PIN 1 ' serial from reader
Spkr PIN 2 ' speaker output
Latch PIN 3 ' lock/latch control
'
[noparse][[/noparse] Constants ]
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
TMidi CON 12
T38K4 CON 6
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
TMidi CON 60
T38K4 CON 45
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
TMidi CON 108
T38K4 CON 84
#ENDSELECT
SevenBit CON $2000
Inverted CON $4000
Open CON $8000
Baud CON T2400
#SELECT $STAMP
#CASE BS2, BS2E
TmAdj CON $100 ' x 1.0 (time adjust)
FrAdj CON $100 ' x 1.0 (freq adjust)
#CASE BS2SX
TmAdj CON $280 ' x 2.5
FrAdj CON $066 ' x 0.4
#CASE BS2P
TmAdj CON $3C5 ' x 3.77
FrAdj CON $044 ' x 0.265
#CASE BS2PE
TmAdj CON $100 ' x 1.0
FrAdj CON $0AA ' x 0.665
#CASE BS2PX
TmAdj CON $607 ' x 6.03
FrAdj CON $2A ' x 0.166
#ENDSELECT
LastTag CON 3
#DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM?
'
[noparse][[/noparse] Variables ]
#IF __No_SPRAM #THEN
buf VAR Byte(10) ' RFID bytes buffer
#ELSE
chkChar VAR Byte ' character to test
#ENDIF
tagNum VAR Nib ' from EEPROM table
idx VAR Byte ' tag byte index
char VAR Byte ' character from table
'
[noparse][[/noparse] EEPROM Data ]
Tag1 DATA "0101A625F5" ' random number
Tag2 DATA "0F02A69268" ' Tag at hand 1
Tag3 DATA "0F02A693F1" ' Tag at hand 2
Name0 DATA "Unauthorized", CR, 0
Name1 DATA "Tag 1 (White Card)", CR, 0
Name2 DATA "Tag 2 ", CR, 0
Name3 DATA "Tag 3 ", CR, 0
'
[noparse][[/noparse] Initialization ]
Reset:
HIGH Enable ' turn of RFID reader
LOW Latch ' lock the door!
'
[noparse][[/noparse] Program Code ]
Main:
LOW Enable ' activate the reader
#IF __No_SPRAM #THEN
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait for hdr + ID
#ELSE
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
#ENDIF
HIGH Enable ' deactivate reader
Check_List:
FOR tagNum = 1 TO LastTag ' scan through known tags
FOR idx = 0 TO 9 ' scan bytes in tag
READ (tagNum - 1 * 10 + idx), char ' get tag data from table
#IF __No_SPRAM #THEN
IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table
#ELSE
GET idx, chkChar ' read char from SPRAM
IF (char <> chkChar) THEN Bad_Char ' compare to table
#ENDIF
NEXT
GOTO Tag_Found ' all bytes match!
Bad_Char: ' try next tag
NEXT
Bad_Tag:
tagNum = 0
GOSUB Show_Name ' print message
FREQOUT Spkr, 1000 */ TmAdj, 115 */ FrAdj ' groan
PAUSE 1000
GOTO Main
Tag_Found:
GOSUB Show_Name ' print name
HIGH Latch ' remove latch
FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj ' beep
LOW Latch ' restore latch
GOTO Main
END
'
[noparse][[/noparse] Subroutines ]
' Prints name associated with RFID tag
Show_Name:
DEBUG DEC tagNum, ": "
LOOKUP tagNum,
[noparse][[/noparse]Name0, Name1, Name2, Name3], idx ' point to first character
DO
READ idx, char ' read character from name
IF (char = 0) THEN EXIT ' if 0, we're done
DEBUG char ' otherwise print it
idx = idx + 1 ' point to next character
LOOP
RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen