German1981
New Member
Hi,
I want to have the Basic stamp 2 read a pulse from a frequency generator and convert the value to RPM. I wrote the code but the stamp doesnt seem to be able to read the input from the frequency generator. I want to input the signal to pin 13, then convert it to rpm, then get bcd values from this. below is my code. Any help would be greatly appreciated.
'{$STAMP BS2}
RPM VAR Word 'Initialize variables
X1 VAR Byte
VAR1 VAR Byte
'----------------------------------------------------------
DIRS = %0000111111111111 'Set inputs and outputs
COUNT 13,500,VAR1 'Counts pin 13 FOR half a second for a high
X1 = 0 'AND stores this value in VAR1
RPM = 0
X1 = VAR1*2
RPM = 60*X1 ' Now we have RPM value
'----------------------------------------------------------
THOUS VAR Nib 'Thousands register
HUNDS VAR Nib 'Hundreds register
TENS VAR Nib 'Tens register
'---------------------------------------------------------
'BIN to BCD decoder
THOUS = (RPM/1000)
RPM = RPM - (1000*THOUS)
DEBUG DEC THOUS
HUNDS = (RPM/100)
RPM = RPM - (100* HUNDS)
DEBUG DEC HUNDS
TENS = (RPM/10)
RPM = RPM - (10*TENS)
DEBUG DEC TENS
'-----------------------------------------------------------
OUTA = THOUS
OUTB = HUNDS
OUTC = TENS ' MAKE SURE THE OUTPUT PINS ARE SPECIFIED CORRECTLY!
END
I want to have the Basic stamp 2 read a pulse from a frequency generator and convert the value to RPM. I wrote the code but the stamp doesnt seem to be able to read the input from the frequency generator. I want to input the signal to pin 13, then convert it to rpm, then get bcd values from this. below is my code. Any help would be greatly appreciated.
'{$STAMP BS2}
RPM VAR Word 'Initialize variables
X1 VAR Byte
VAR1 VAR Byte
'----------------------------------------------------------
DIRS = %0000111111111111 'Set inputs and outputs
COUNT 13,500,VAR1 'Counts pin 13 FOR half a second for a high
X1 = 0 'AND stores this value in VAR1
RPM = 0
X1 = VAR1*2
RPM = 60*X1 ' Now we have RPM value
'----------------------------------------------------------
THOUS VAR Nib 'Thousands register
HUNDS VAR Nib 'Hundreds register
TENS VAR Nib 'Tens register
'---------------------------------------------------------
'BIN to BCD decoder
THOUS = (RPM/1000)
RPM = RPM - (1000*THOUS)
DEBUG DEC THOUS
HUNDS = (RPM/100)
RPM = RPM - (100* HUNDS)
DEBUG DEC HUNDS
TENS = (RPM/10)
RPM = RPM - (10*TENS)
DEBUG DEC TENS
'-----------------------------------------------------------
OUTA = THOUS
OUTB = HUNDS
OUTC = TENS ' MAKE SURE THE OUTPUT PINS ARE SPECIFIED CORRECTLY!
END