Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

having a basic stamp read pulses

Status
Not open for further replies.

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
 
What is the frequency you are using?...... I am guessing its changing, but what are the MAX and MIN of that frequency?

I think you are running into problems with the size of your variables.... try making them WORD size. If you are using a 280Hz frequency your pulses witdth would be of 1.78msec in 500msec you are going to have 280 pulses, that is well above the BYTE size for your variables, so they will rollover back to zeroand probably would end up with something like 25 pulses instead of the 280.

Ivancho
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top