Correct use of write command?

jonphenry

New Member
IM trying to change 4 numbers in my eeprom on a 40x1. The app is to change a pin number. I save the numbers 1,2,3,4 initially using the EEPROM 90,(1,2,3,4) instruction then go into the main loop. When its time to change it, I use this:

write b3,90
write b4,91
write b5,92
write b6,93

The numbers Im trying to save to the eeprom are in b3-b6.
Is this correct use of the write command?
 

hippy

Technical Support
Staff member
The address of where to write should be on the left, the value to write on the right, so ...<code><pre><font size=2 face='Courier'>write 90,b3
write 91,b4
write 92,b5
write 93,b6 </font></pre></code>
 

jonphenry

New Member
Ahhh ok, looking at the explanation in manual 2 I see my mistake. I however went by the example. Is the example for WRITE in manual 2 wrong or am I reading it wrong?

write b0,b1 &#8216; write value into b1

That would say to me, value on left, location to be written on right.

Thanks Hippy, works like a champ now.

Also Hippy, could you check this out when you get a chance and give me your opinion on feasibility and efficiency.

http://www.lancer3.com/1wkpad.htm

Thanks

Edited by - Jon Henry on 03/08/2007 16:08:27
 

BeanieBots

Moderator
Jon Henry, your one-wire keypad looks like a sound concept. The proof will be in testing.
The ADC method (R,2R) for reading multiple push buttons has been around for decades but I see no reason why it can't be pushed the way you are going with it. It will probably start to get quite critical on resistor values though.
One thought that might be worth a try to reduce code and hence speed would be to look at how the tests are done.
At the moment you are testing to see if a value fits within a range. As the range increases by the same multiple each time, if you divide the reading by that multiple first, then it may well be possible to simply test for an absolute value.
Experiment with the divisor value.
eg b0=b0/70
if b0=1 then button 1
if b0=2 then button 2 etc. etc.

Please pursue it and let us know how it goes.
 

vk6bgn

New Member
Jon Henry,

The single wire keypad is a very interesting concept. I've always been interested in the DTMF tones that are produced when using a keypad. To put the frosting on the cake with your project, you need the tones, mate! Possibly using the PICAXE SOUND command? For example, I think when the number 1 is pressed, the output tone is the combination or sum of two tones, a 697Hz. and 1206 Hz. sine waves. (I think) Example again, pressing the number 8 uses a 852 Hz. and 1336 Hz. tones. (I think) If you're remotely interested in producing the tones, Google &quot;DTMF&quot; for the rest of the exact frequencies or have a look at Wikipedia as they have a nice little write up about DTMF tones.

DECODING

For someone (like me) who wishes to decode these tones with a DTMF decoder chip, I believe the tolerance for the sum of the two audible tones has to be pretty close. About 2 percent for a decode chip???

INDICATION ONLY

But, possibly someone may want a little more then the standard LED &quot;On&quot;, button pressed indication? How about an audible indication that a keypad button has been pressed? Nothing better then the (approximate) same tone you hear on your telephone when the number 1 or 8 is pressed! Thought that might be a nice compliment to your project? (just my thoughts)

Possibly using the PICAXE SOUND command can produce the appropriate tones? Or maybe SOUND might just get something close to the right freq? Maybe even the TUNE or the TUNE Wizard could help?

I've not investigated any of this, just my normal Saturday morning thoughts. I'll be watching more of this thread. Hope to read more.

Cheers,
&quot;The Addict&quot;


 
 

BCJKiwi

Senior Member
Did a bunch of analysis on the ADC keypad issue and read much theory in the forum on what the resistor values should be.

So I set up spreadsheets for 10, 12 and 16 key keypads and calculated the resulting voltages/ADC values/and difference between each ADC value for a whole host of standard resistor sizes and settled on an 'ideal' set.

The main issue that became evident very quickly is the question of how big a difference between values you really need to guarantee you have a clearly definable key.

With the 1 output 10 key keypad I can get better than a 22 difference, on the 12 key, it came down to 10.6 diff and required 2 outputs, with a 16 key keypad the difference comes down to 1.9 with 2 outputs so I also looked at a 'modular' approach of 1 output per 4 keys giving a diff of 50+ between each key - ie 4 keys 1 output, 8 keys 2 outputs etc.

If you can recommend a good place to park these files then let me know and I'll upload them then you can play with the values and see how they work for your application.

Does anyone have clear tested real world experience of a reliable minimum step size for reading discrete ADC values assuming a standard LM7805 supply?

How about it Technical - a file store for files pics etc as part of the forum?

BCJ


Edited by - BCJKiwi on 04/08/2007 05:36:09
 

jonphenry

New Member
BCJKiwi you can upload them to my site.
Go to www.lancer3.com then downloads. There you can upload anything you want to sendme. Ill get them and post them up.

And if anyone else has some files relating to Picaxe theyd like to be online, just upload them and Ill post them.


Ive also added to the site the schematics I intend to test for the keypad

Edited by - Jon Henry on 04/08/2007 05:02:08
 

BCJKiwi

Senior Member
OK JH,
Have uploaded a revised ADC Keypad DecodersB.zip to your site.
This is a single worksheet Excel SS showing 3 new reworked calculations;
a 10 key, a 12 key and a 16 key each only having SINGLE out !

Minimum differences between ADC values is;
25, 21, and, 15 respectively all using pretty easy to get E24 series resistor values.
If you want more accurate steps, then the theoretical best for a 16 key keypad is a 15.94 step in ADC values (255/16) and you could get closer to that if you can source higher accuracy Resistors as in the E48 series.

However I would think if you needed the difference between 15 and however much closer you could get to 15.94, then you'd be operating on a wing and a prayer.

If the 15 step - which in reality won't be so good depending on resistor tolerances and any other variations like contact resistance on the switches - is not good enough then you will need more outputs.

I have also not studied what happens if you press more than one key at a time - obviously the program will interpret that as some other single key press - don't know how you would test for that effectively. If you had much bigger steps (more wires) and carefully tuned the resistor values, in theory you could detect a multiple key press but that does not seem worth the effort but would depend on your application.

If you look at the way the calculations are done then you could just duplicate the 10 key unit, or reduce it to 2 blocks of 8 keys and tweak the resistor values.

Just start at the first input value and change it to another standard available value getting it as close as possible to the ideal step value (255 / no of keys) in the 'Diff' column and watching the accumulating error in the 'Accumulated target' column.

(have just uploaded a second of the same name with basic protection on the calculation cells)

Enjoy

BCJ

Edited by - BCJKiwi on 04/08/2007 07:45:11

Edited by - BCJKiwi on 04/08/2007 15:47:50
 

BCJKiwi

Senior Member
Just viewed your circuit which is the same as my calcs would use.

However I have just put your values into the SS and get a swing of ADC steps from 4.1 through to 34.4 around the ideal of 15. A higher divider resistor value gives you a more sensitive adjustment of the output values when playing with the series resistor values.

Looking at your application, it might be worth considering breaking the logic up into a 12 key and a 4 key so you have a really big ADC difference on the 4 key block which you could use for the Enter, Cancel, (Dis)Arm, ChangePin keys and then as discussed above, you could carefully select resistor values so you could detect multiple keys pressed simultaneously on the control keys and also separate out number keys from control keys.

Key debounce circuits could also be a way to manage multi-key presses by only accepting the first one pressed. You could also test for held/stuck keys as well by checking for 'no keys pressed' before accepting the next keypress.

Edited by - BCJKiwi on 04/08/2007 07:54:36
 

jonphenry

New Member
BCJ, you cant use my values in your spreadsheet. If youll notice, we use different wiring configurations to achieve our keypads.
With your config, you have the resistors gang on each other as you go to higher switches(IE 1 key uses 820, 2 key goes through 820 and 910, 3 key goes through 820,910, and 1100 as well as of course the dividing resistor).
My config has voltage going through only two resistors no matter which key is pressed.
When I plugged my numbers into your SS, I saw the big spans you saw. After some investigation, I noticed the differences in the wiring.
Now, either config should work perfectly fine .
The reason I went with my config is to hopefully fend off multiple key pressings being a factor.
Ill explain:Going by the diagrma you have bottom left of your SS, lets make those 5 switches key1- key5. If you press key 2 there will be 2200 ohms in the circuit. If you press key 4, there will be 5700 ohms of resistance in the circuit. Now, if we press key 2 and key 4 we get.....2200 ohms. The code will see a key 2 press and thats all. If you meant to press 4 but accidentally caught 2 also, your screwed because your software sees 2.

With my config, Im trying to handle multiple key pressings in the circuit design stage instead of making the code handle it. Pressing two keys simaltaneously in your config keeps the series circuit of less resistance. In my config, pressing two keys creates a series-parallel circuit. This series-parallel combo should yield a voltage different than assigned voltages for any single key. My code right now shows a range of 15 for each key. Some preliminary testing tells me I should be able to keep a roundabout 15 span between each key but make the key range itself 3.
Example
if b0&gt;=9 and b0&lt;=11 then b1=1
if b0&gt;=24 and b0&lt;=26 then b1=2
if b0&gt;=41 and b0&lt;=43 then b1=3

Hitting keys 1 and 2 would generate an ADC value of 33.558. The code would see this as nothing and move on.

If Im correct with my calcs I should be able to arrange the code this way. My hope is that multiple key pressings will generate voltages outside of these ranges thereby handling multiple pressings without code. im sure some combos of keys will fall into a valid range, but the resistances used could be adjusted slightly to move them to an invalid range them.

Im sure were a ways away from this thing being fully functional, but this kind of input and dialog is what will bring it to fruition. Thanks for the input and ideas, keep 'em coming. Who could use six xtra IO?

Edited by - Jon Henry on 04/08/2007 22:36:54

Edited by - Jon Henry on 04/08/2007 22:38:52
 

BCJKiwi

Senior Member
Well you are correct of course. This demonstrates a classic case of being driven down a path having started somewhere else.

My starting point was dealing with readily available keypads which mostly use a matrix arrangement in which you cannot get access to each discrete switch but must deal with a rows and columns approach.

I have a whole other set of calculations for those and adapted them to the Discrete switch style when I found I could not obtain the standard keypads with the legends I needed.

Will refine/add the sheets to give the calculators for discrete switches in serial and parallel, as well as for the matrix arrangement and post those to your site as well.

I do have a concern however that your calculation methodolgy to determine single key presses appears to rely on a very narrow range of ADC (just 1 either side of the theoretical value) to select the key.

Have you tested the consistency of this approach? Resistor tolerances, contact resistance etc will cause variations which I would have expected to vary the effective resistance (and therefore READADC value) from keypress to keypress and to vary over time as the keys get used and the contact charateristics change. I doubt the system will be reliable with such a narrow range but as yet I have seen no definitve results on this and I would very much like to see such results.


BCJ

Edited by - BCJKiwi on 04/08/2007 23:47:26
 

jonphenry

New Member
Thanks for the rework to accomodate both configs in the spreadsheet in advance.
According to my calcs, the range of three should be sufficient. Im sure there will be added circuit resistance, but I think it will be minimal.
I think the best approach here codewise is to stay away from cookiecutter code, meaning the actual numbers to use from keypad arent set in stone. The tightest range possible is key here. That being said, I think the best way to do a 1 wire keypad is to build the keypad you will use for your project. The KP always being the same(code is easy to change). Once your circuit(KP,micro,sensors,etc.) is complete, test each key and see what the ADC value is. Make that value your center of your range. Kind of like tuning the KP. My testing so far with individual keys always gives me the same value, sometimes its on edge and stays between two values. I haven yet seen one move more than 1 out. Not to say it wont, again my testing is preliminary and until its built none of us really know. but from what Ive seen thus far, it should work as advertised with a range of three with the possibility of going up to four. With some luck, the cookiecutter approach to the code may work also. It will all be in the testing. My parts will be here monday, I should have something solid monday night.

Edited by - Jon Henry on 05/08/2007 00:16:42
 

BCJKiwi

Senior Member
Are you using a standard keypad or discrete keys - I assume discrete keys in which case, what sort of switches are they?

Standard matrix keypads often specifiy key resistances in the range of 200ohms!

 
 

jonphenry

New Member
BCJ, Im using tactile switches. Im basically building the keypad. I dont think Ive mentioned it yet but this project is a sub-project of a bigger one. Im working on a breach alarm system. I have a few people with storage buildings on property away from their main properties and the phone lines. They want a way to know if someone has broken in. This system will monitor the doors and windows and send sms messages using a GSM module to pre-programmed numbers if there is a breach. As I was working on the control interface, I came across the ADC concept and decided to give it a whirl. If I can get this to working properly, I can use a 08 for the interface and a bigger picaxe for the brain.

Edited by - Jon Henry on 05/08/2007 03:45:49
 

BCJKiwi

Senior Member
ADC Keyboard Decoder Calculator

Jon, have uploaded a 3 sheet Excel workbook covering Matrix, and discrete button keypads in a range of sizes and configurations to your site at <A href='http://www.lancer3.com/dwnlds.htm' Target=_Blank>External Web Link</a>
These are calculators in which you can enter your options for resistor values.

Wiring diags included.

All are 1 output except an option on the Matrix which is 4 wire if you want big ranges in the ADC values.

The sample calculations included utilise relatively large value resistors from the E24 series to help overcome variations in resistor values and contact resistances and maintain accuracy in the ADC ranges for the use of READADC. Note:- most commonly available keypads are of the Matrix type and typically have contact resistances in the low hundreds of ohms so using higher value resistors overcomes these variations.

If using higher quality TACT type switches lower resistances could be safely used.

Thanks to Jon for hosting these files.

BCJKiwi

Edited by - BCJKiwi on 05/08/2007 05:49:21
 

sedeap

Senior Member
************
You have another thread of this same project
i reply on that
<A href='http://www.rev-ed.co.uk/picaxe/forum/topic.asp?topic_id=7571&amp;forum_id=31&amp;Topic_Title=One+input+keypad%3F&amp;forum_title=PICAXE+Forum&amp;M=False&amp;S=True' Target=_Blank>External Web Link</a>

************
 
Top