Recognising 4bit binary inputs.

NM87

New Member
Hello,
Im working on a project at the moment which involves four 4bit binary numbers to be recoginised.

Basically i have a process which can generate the binary equivalent of the 0-9.

Im using four inputs on an 18m2.

What I want to happen, is for an output to go high, if the numbers 6,0,1,3 (0110, 1010, 0001,0011 ) are entered in that exact sequence.
If for example if 0613 or 62013 is entered then go back to start, similiar to that of a pin code request on a moblie/cell phone.

So far I have been unsuccessfull in doing this correctly.
The code below shows the method I have been using, it has a flaw that once a number is recognised a loop occurs for a set period of time, meaning than the next number must recognised within about 2 seconds. Another fault is the output will activate as long as it received the reguired numbers within the loop, meaning that 6,0,4561,3 can be enter within the time limit and the output will go high.

Code:
symbol digit_A = %10000001
symbol digit_B = %10000010
symbol digit_C = %01000000
symbol digit_D = %11000000

main:

add1:
for b0 = 1 to 500
if pins=digit_A then goto add2 
next b0
goto main


add2:
for b1 = 1 to 500
if pins=digit_B then goto add3
next b1
goto main


add3:
for b2 = 1 to 500
if pins=digit_C then goto add4
next b2
goto main


add4:
for b3 = 1 to 500
if pins=digit_D then goto add5
next b3
goto main



add5:
for b4 = 1 to 5
high b.4
pause 1000
low b.4
pause 1000
next b4
goto main


My next plan is to load digits,A,B,C,D to the eeprom, and then create a progam which would scan and compare the actual input to that stored in memory.
If the numbers actually entered do not match A,B,C,D then go back to start.

Could this be done?

Would anybody have examples of code, where data is loaded to the eeprom and then read and a decision thereafter is made, as the PICAXE manual does not give much detail on an application like this.

Thanks for the help, and taking time to read.
Regards Nigel
 

nick12ab

Senior Member
The code below shows the method I have been using, it has a flaw that once a number is recognised a loop occurs for a set period of time, meaning than the next number must recognised within about 2 seconds.
I'm surprised that it works at all! There's no way that anything could happen until the code is matched as b0 can never hold a value of 500 and thus the loop will never exit unless the contained IF statement is true.


My next plan is to load digits,A,B,C,D to the eeprom, and then create a progam which would scan and compare the actual input to that stored in memory.
If the numbers actually entered do not match A,B,C,D then go back to start.

Could this be done?

Would anybody have examples of code, where data is loaded to the eeprom and then read and a decision thereafter is made, as the PICAXE manual does not give much detail on an application like this.
Here's a starter...
Code:
symbol digit1 = b1
symbol digit2 = b2
symbol digit3 = b3
symbol digit4 = b4

eeprom 0,(%10000001,%10000010,%01000000,%11000000)
	
	read 0,digit1
	read 1,digit2
	read 2,digit3
	read 3,digit4
I can't do any more for you now as I need to know more about your project in order to do so. What's the input device?
 

NM87

New Member
I'm surprised that it works at all! There's no way that anything could happen until the code is matched as b0 can never hold a value of 500 and thus the loop will never exit unless the contained IF statement is true.
Yeah, to be honest it was a shot in the dark, this is a new leaning curve for me, its a bit foreign at the moment but ill get there someday. I didnt know that b0 can never hold a value of 500.

The input device is a holtek 9170b DTMF decoder.

Thanks.
 

NM87

New Member
nick12ab

The code you just posted, what does it actually mean?, what is the process?

Thanks.
 

nick12ab

Senior Member
The code you just posted, what does it actually mean?, what is the process?
My code only stores your passcode in the built-in EEPROM on download and reads the code into variables when the program runs. This is the commented version:
Code:
symbol digit1 = b1						'b1 can now be referenced using friendly name 'digit1'
symbol digit2 = b2						'b2 can now be referenced using friendly name 'digit2'
symbol digit3 = b3						'b3 can now be referenced using friendly name 'digit3'
symbol digit4 = b4						'b4 can now be referenced using friendly name 'digit4'

									'Note: Symbol instructions take up no program memory and
									'do not affect code execution speed in any way since
									'the compiler converts them back before downloading
									'so don't be afraid to use them (using them is helpful)
									
eeprom 0,(%10000001,%10000010,%01000000,%11000000)	'Writes your code into EEPROM on download of the program
									'Note: eeprom isn't a command but an instruction for the
									'compiler so running it somewhere in your code won't
									'write the EEPROM at runtime - use the write command for that.


	read 0,digit1						'Read digit 1 of your code
	read 1,digit2						'Read digit 2 of your code
	read 2,digit3						'Read digit 3 of your code
	read 3,digit4						'Read digit 4 of your code
 

eclectic

Moderator
Yeah, to be honest it was a shot in the dark, this is a new leaning curve for me, its a bit foreign at the moment but ill get there someday. I didnt know that b0 can never hold a value of 500.

The input device is a holtek 9170b DTMF decoder.

Thanks.
Have a look at Manual 2 page 10

Variables - General

e
 

westaust55

Moderator
For the determination if the right/valid sequence of digits has been entered/received have a look at this older Rev Ed datasheet for a key lock: http://www.picaxe.com/docs/chi008.pdf
In particular have a look at the PICAXE 18X code on pages 11 and 12.

For the entry of the input data can you put the 4 bits onto 4 consecutive inputs on the same port.
if for example the 4 bits are on the 4 lowest pins of a port - say b.0, b.1, b.2 and b.3 in the correct order of binary powers
then tentatively you can read the port, mask off the unwanted bits and have the digit 0 to 9 using a line such as:

let b5 = pinsB AND $0F

The variable b5 will hold a value from 0 to 9

From your post 1, it seems the value for 0 is stored as 10 (%1010) so a quick test for 10 will resolve that.
 

techElder

Well-known member
The DTMF decoder that you reference has a DV output. That's the key to getting the individual digits into your program. When that pin goes "HIGH", then the decoder has presented valid bits for you to use.

In other words, Check the DV pin on the decoder in a loop. When that bit it is "HIGH" or "1", read the 4 pins that represent the digit you want. The rest is deciding where, how and how long.

Data valid output - When the chip receives a valid tone (DTMF) signal, the DV goes high; other- wise it remains low.
View attachment 9170v111.pdf
 
Top