Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

A place to discuss any problems, issues or questions surrounding the E-blocks BTEC Unit 6 course.

Moderator: Benj

User avatar
The G
Posts: 16
Joined: Tue Jan 09, 2018 12:41 pm
Location: Suffolk
Has thanked: 24 times
Been thanked: 8 times
Contact:

BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program without using macro

Postby The G » Tue Jan 16, 2018 12:48 pm

Hi,

Until there is a dedicated BTEC section, I'll start off the topics with BTEC Course so that it's easy to find and move later if necessary...

I am not a skilled programmer so please go easy on me! I am working through the exercises in your guide: http://www.matrixtsl.com/resources/file ... course.pdf

As per Exercise 9 Program 1 Part 2 - When reading inputs from the keypad, how do you do this without using the macros?
These users thanked the author The G for the post:
Benj (Tue Jan 16, 2018 1:56 pm)
Rating: 5.88%
 
...
G

User avatar
Benj
Matrix Staff
Posts: 12905
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3681 times
Been thanked: 3532 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Key

Postby Benj » Tue Jan 16, 2018 2:01 pm

Hi G,

If I am reading this correctly you are asking how the component macros work to sample the keypad.

The keypad macros basically do a scan of the keypad pins by performing the following.

We set one of the column pins high and the rest are driven low. We then read the input values of the row pins checking for a logic high which would indicate a switch press on that column. We then repeat this for the rest of the columns.

If we get a logic high back then we use a look up table to translate the switch index ((column * numrows) + row) into the corresponding ASCII value.
These users thanked the author Benj for the post:
The G (Wed Jan 17, 2018 5:01 pm)
Rating: 5.88%
 

User avatar
The G
Posts: 16
Joined: Tue Jan 09, 2018 12:41 pm
Location: Suffolk
Has thanked: 24 times
Been thanked: 8 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Key

Postby The G » Wed Jan 17, 2018 5:01 pm

Benj wrote:Hi G,

If I am reading this correctly you are asking how the component macros work to sample the keypad.

The keypad macros basically do a scan of the keypad pins by performing the following.

We set one of the column pins high and the rest are driven low. We then read the input values of the row pins checking for a logic high which would indicate a switch press on that column. We then repeat this for the rest of the columns.

If we get a logic high back then we use a look up table to translate the switch index ((column * numrows) + row) into the corresponding ASCII value.


Ah thanks, ok I think I understand the theory behind it from your explanation, so how would that be entered into the input box for example, if I want to only read the "5" button in order to assign it a different character, without the use of a macro. Essentially using the keypad just as a set of generic buttons.
...
G

User avatar
Benj
Matrix Staff
Posts: 12905
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3681 times
Been thanked: 3532 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

Postby Benj » Thu Jan 18, 2018 4:24 pm

Hi G,

You can't read all the buttons directly without doing the scanning technique. So you can't simply use an input icon to read the state of a specific button. However you can pair the input with an output and this should work for polling a single button or column of buttons.

If you just wanted to scan button 5 as per your example then you would have to output a 1 to column 1 (port bit 1) and a 0 to columns 0 and 2 (port bits 0 and 2). You can then use an input icon to check state of row 1 (port bit 5).

output 0b00000010 with mask 0b00000111
input with mask 0b00100000

Hope this helps and makes sense.
These users thanked the author Benj for the post (total 2):
The G (Thu Jan 18, 2018 4:54 pm) • jgu1 (Mon Feb 05, 2018 4:57 am)
Rating: 11.76%
 

User avatar
The G
Posts: 16
Joined: Tue Jan 09, 2018 12:41 pm
Location: Suffolk
Has thanked: 24 times
Been thanked: 8 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

Postby The G » Thu Jan 18, 2018 4:58 pm

Thanks, I'll try that!
...
G

User avatar
The G
Posts: 16
Joined: Tue Jan 09, 2018 12:41 pm
Location: Suffolk
Has thanked: 24 times
Been thanked: 8 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

Postby The G » Wed Jan 24, 2018 4:07 pm

I've tried my best to solve this, but it is outside of my ability! :shock: :oops:
I don't know if the person who wrote the course guide is on the forum, but could you please provide an answer program for this task on page 26 - Exercise 9 as per the highlights line on the image attached. Thanks!
Program without Macro.JPG
Program without Macro.JPG (76.29 KiB) Viewed 935 times
...
G

User avatar
Steve
Matrix Staff
Posts: 2998
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 67 times
Been thanked: 301 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

Postby Steve » Thu Jan 25, 2018 11:12 am

To solve this you will need to refer to the datasheet:
http://www.matrixtsl.com/resources/files/datasheets/EB014-30-1.pdf

The switches are arranged in a 4x3 matrix - 4 rows and 3 columns. The basic procedure to detect the key pressed is as follows:

  • output '1' to column pin 1 and '0' to column pins 2 and 3
  • read each row pin in turn
  • if the input is '1', then you know the switch at that column and row intersection is pressed
  • if no keys in that column are pressed, repeat the procedure for the other columns

So if you get a logic high ('1') when reading row 2 when column 2 is activated, you know the key pressed is number 5.

I hope this will go part of the way in helping.

Regards,
Steve.
These users thanked the author Steve for the post (total 2):
The G (Thu Jan 25, 2018 2:29 pm) • jgu1 (Mon Feb 05, 2018 4:57 am)
Rating: 11.76%
 

User avatar
The G
Posts: 16
Joined: Tue Jan 09, 2018 12:41 pm
Location: Suffolk
Has thanked: 24 times
Been thanked: 8 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

Postby The G » Thu Jan 25, 2018 1:21 pm

Hi Steve,
Thanks, and yes I understand the theory completely.
I am finding this very frustrating as a first time teacher in this topic. It feels embarrassing at times actually.
Anyway, I have tried again and still cannot do this.
I have attached one of my 47 attempts (yes 47 I kid you not.)
Please assist :oops:
Keypad Signal 33.fcfx
(9.19 KiB) Downloaded 30 times
...
G

User avatar
LeighM
Matrix Staff
Posts: 1405
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 355 times
Been thanked: 511 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

Postby LeighM » Thu Jan 25, 2018 2:29 pm

Hi,
The row read needs to read different pins to the column write.
So I've changed the mask in the read icon.
Hope that helps
Attachments
Keypad Signal 33a.fcfx
(9.19 KiB) Downloaded 31 times
These users thanked the author LeighM for the post:
jgu1 (Mon Feb 05, 2018 4:57 am)
Rating: 5.88%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 7535
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2052 times
Been thanked: 2960 times
Contact:

Re: BTEC Course - Exercise 9 Program 1 Part 2 - Keypad program

Postby medelec35 » Fri Jan 26, 2018 11:33 am

Hi, I have created a routine which should work on hardware, well works perfect with Proteus Simulation:
Keyscan routine1.png
Keyscan routine1.png (68.31 KiB) Viewed 890 times


See if you can understand with whats going on just single stepping into code (F8) then watching the variable values change.

There maybe other better ways, but it's just what I thought of at the time.

Martin

Edit: Confirmed working on hardware.
Attachments
Keypad Signal 33b.fcfx
(22.5 KiB) Downloaded 29 times
Last edited by medelec35 on Mon Feb 05, 2018 8:42 am, edited 1 time in total.
Reason: Added an additional comment.
These users thanked the author medelec35 for the post (total 3):
LeighM (Fri Jan 26, 2018 11:39 am) • Benj (Fri Jan 26, 2018 1:04 pm) • jgu1 (Mon Feb 05, 2018 4:57 am)
Rating: 17.65%
 
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Martin