Matrix Keypad routine - Page 2


Closed Thread
Page 2 of 4 FirstFirst 1234 LastLast
Results 41 to 80 of 135
  1. #41
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    I didn't say not equipped - I said not as well equipped. And, I'm more so referring to something that's more so "hard coded" over calculations. When I say hard coded I'm talking about something that's direct as in (a = 100) Vs (a = b x 10 / 2) No prizes for guessing which is faster and uses less resource.
    If a is hard coded to equal 100, then I would guess b and c would be hard coded too. If I understand you correctly this is what the PIC a good for. If this was all I had to do I good do it on paper once and would not have to bother with all of this programing and such. In my world variables change.

    In you opinion, what should we all be using?
    Dave
    Always wear safety glasses while programming.

  2. #42
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    (b & c) are variables that will only be hard coded if assigned with a fixed value. In Discrete mathematics, if we were to say, a(x) means something - then this is effectively a predicate since the variable x can take on many different forms. On the other hand, if we say A = 100 and it's a "real number", it is said to be a proposition because there is obvious truth in it. Clearly 100 is a real number.

    In you opinion, what should we all be using?
    Short answer is, in my opinion - use whatever works best for you. Focus on your strengths and if it gets the job done, call it a day
    Last edited by T.Jackson; - 23rd May 2007 at 14:46.

  3. #43
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    (b & c) are variables that will only be hard coded if assigned with a fixed value. In Discrete mathematics, if we were to say, a(x) means something - then this is effectively a predicate since the variable x can take on many different forms. On the other hand, if we say A = 100 and it's a "real number", it is said to be a proposition because there is obvious truth in it. Clearly 100 is a real number.


    Short answer is, in my opinion - use whatever works best for you. Focus on your strengths and if it gets the job done, call it a day
    I was being sarcastic.
    Dave
    Always wear safety glasses while programming.

  4. #44
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    I think what I'm really trying to say here is that, if we want (a) to equal 100, and we can predict this value, then why use a formula? (It's unnecessary maths)

    Code:
    Public Function DrawLCD()
       '-----------------------------------------------------------------------------
       '// 2 Line 16 LCD_Chrs 5x7 matrix                                            '
       '-----------------------------------------------------------------------------
       Dim i As Long 'General working var for nested loops
       Dim j As Long '^
       Dim k As Long '^
       Dim f As Long '^
       Dim e As Long '^
       Dim h As Long '^
       
       '// Draw display matrix with all segs off    '
       For LCD_Row = 0 To 1                         '2 lines
           For LCD_Chrs = 0 To 15                   '16 chrs per line
               For f = 0 To 7                       'Matrix row
                   For k = 0 To 4                   'Matrix col
                       For j = 0 To Draw_Scale - 1  'Ea seg is (dscale x dscale) pixels
                           For i = 0 To Draw_Scale - 1 '^
                               SetPixelV LCD.hdc, 2 + i + k * (Draw_Scale + 1) + (LCD_Chrs * Draw_Scale * 6) + (LCD_Chrs * 4), 3 + j + (f * (Draw_Scale + 1)) + (LCD_Row * Draw_Scale * 9) + LCD_Row * 7, vbGreen
                           Next
                       Next
                   Next
               Next
           Next
       Next
    I'm forced into using calculations with the above code because we can't easily predict the values of the variables without making things even more complex than they already are. So there's plenty of valid reasoning behind this predicate arrangement. But if we can predict what we want, and it's feasible to do so, why not hard code it???
    <hr/>
    Last edited by T.Jackson; - 23rd May 2007 at 15:57.

  5. #45
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post Hard-Coded Example

    Code:
       If Total_Frames <> 0 Then
          For i = 0 To 31
       '// Test to see if this LED is already on the screen (don't blit again if so)
              If LED(Frame_Data(Current_Frame, i)) <> LED(Frame_Data(Last_Blitted_Frame, i)) _
              Or Not Run_ROM Then
                 BitBlt Tree_PCB.hDC, Tree_X(i), Tree_Y(i), 22, 22, LED_Mask.hDC, 0, 0, MergePaint
                 BitBlt Tree_PCB.hDC, Tree_X(i), Tree_Y(i), 22, 22, LED(Frame_Data(Current_Frame, i)).hDC, 0, 0, SrcAnd
              End If
          Next
       End If
    
       Tree_X(0) = 162
       Tree_Y(0) = 2
       Tree_X(1) = 190
       Tree_Y(1) = 42
       Tree_X(2) = 218
       Tree_Y(2) = 82
       Tree_X(3) = 180
       Tree_Y(3) = 83
       Tree_X(4) = 203
       Tree_Y(4) = 123
       Tree_X(5) = 226
       Tree_Y(5) = 163
       Tree_X(6) = 249
       Tree_Y(6) = 203
       Tree_X(7) = 205
       Tree_Y(7) = 204
       Tree_X(8) = 230
    The above procedure relies mostly on a hard coded arrangement. The two single dimension arrays Tree_X() & Tree_Y() contains all fixed values that actually saves a lot of calculating. Hard coding is definitely a worth while consideration. So instead of making the PIC do (2 + 2), why not just assign 4 to the variable. (Anyhow this is my final comment about this, it's completely off topic) Sorry
    Last edited by T.Jackson; - 23rd May 2007 at 15:59.

  6. #46
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Steve

    Thank you for your keypad routines! I implemented and it works with no compilation errors.
    However, I do have a minor problem:
    In my logic, the call to

    @ READKEYPAD _myvar

    is part of a larger loop that performs some other functions.
    Now my program will not continue with the rest of the loop until a key on the keypad was pressed?
    What must I do so that it will read the keypad but if no key was pressed it will simply continue as normal?

    Initially the myvar variable continuously returned random key values and I was then advised by you to use the
    OPTION_REG.7=0
    command so that the routine will only register a value when a key was actually pressed. Adding the OPTION_REG.7=0 command solved that problem but now the program flow does not continue until a key was pressed.

    Thank you in advance.

    Here is the definitions I used:

    DEFINE KEYPAD_ROW 4 ' 4 ROW keypad
    DEFINE KEYPAD_ROW_PORT PORTC ' ROW port = PORTC
    DEFINE KEYPAD_ROW_BIT 4 ' ROW0 = PORTC.4
    DEFINE KEYPAD_COL 4 ' 4 COL keypad
    DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
    DEFINE KEYPAD_COL_BIT 4 ' COL0 = PORTB.4
    DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
    DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature

    PAUSE 500
    LCDOUT $FE,1,"Initializing ...."
    Pause 1000

    INCLUDE "KeyPad.bas"

    OPTION_REG.7=0

    ---------------------------------------------

    Steve

    I just looked at your code again.
    Can I simply remove the

    repeat

    until key!=0

    lines, because this seems to force the loop to be repeated until a key was pressed?
    Last edited by passion1; - 14th June 2007 at 15:06.

  7. #47
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    OK NO NEED FOR THAT

    i've attach the latest version... which i thought i had posted here


    So the only thing you will have to do, is to add this simple line
    Code:
    DEFINE SCAN_ONCE 1
    And this should cure the problem.

    I have added this feature once i needed to scan a keypad with a timer interrupt... which is certainly the way to go for any Push-Button/Keypad entry anyways.

    Enjoy!
    Attached Files Attached Files
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #48
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Steve

    EXCELLENT!! Now everything works 100%!

    One last question:
    What is the debounce and autorepeat functionality as set by

    DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec
    DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature

    Thanks again!

  9. #49
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Let's say the user press on a specific key for awhile, the AUTOREPEAT feature should allow to scan/give you the Keypad scan each 200mSec.. handy? Not sure of it In your case, of course not.

    Debounce delay will be the delay the software will wait after a key have been pressed before to go out and giving you the right Key. On most tact-switch keypad, 100 mSec is more than enough, but.. the best way to know it, is to test it.

    Glad to know it's working now!
    Last edited by mister_e; - 14th June 2007 at 22:00.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #50
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Steve

    Thus, am I right in saying that if I want the keypad scanner to interfere the least with the rest of the program execution, then I must switch the AUTOREPEAT OFF?

  11. #51
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    If you don't define AutoRepeat, the program will spin in round until you release the keys.

    To make a short story Use AutoRepeat and SCAN_ONCE... i should have written that routine in a different way...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  12. #52
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Maybe using Darrel's Instant Interrupts? Just an idea...

    When I have some spare time I'll try it to have a true multitasking keyboard scanner.

    Ioannis

  13. #53
    Join Date
    May 2007
    Location
    Harvest, Alabama
    Posts
    10


    Did you find this post helpful? Yes | No

    Question Pullup Resistor

    I have noted this discussion on Pull Up resistors. I am running the PIC18F series chip and it in the documentation says it supports a weak pull up setting internally in the chip. Could I get any discussion of this relative to the pull up resistors on Vcc. Also Pull Ups as I understand their function is to bring the voltage on the pin up a little so that when the transistor in the chip is triggered only slightly the pin will appear digitally to have tripped.

    As such what values do you think these resistors should be generally?

    If the support is internal, does this mean we still have to place the external resistors?

    Thanks to all.

  14. #54
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CluckShot View Post
    I have noted this discussion on Pull Up resistors. I am running the PIC18F series chip and it in the documentation says it supports a weak pull up setting internally in the chip. Could I get any discussion of this relative to the pull up resistors on Vcc. Also Pull Ups as I understand their function is to bring the voltage on the pin up a little so that when the transistor in the chip is triggered only slightly the pin will appear digitally to have tripped.
    As such what values do you think these resistors should be generally?
    If the support is internal, does this mean we still have to place the external resistors?
    Thanks to all.
    Generally, a pullup resistor (or a pulldown) is used to keep a pin from 'floating', which basically happens when nothing is driving the pin. The pin's voltage floats around due to induced voltages from traces around it, the weather, humidity, your hand, etc.etc...
    Another reason is that the pin might be an 'open drain' ('open collector' for older school types). This means that the pin only has a switching transistor to pull it low, and not high. So you connect a resistor of about 4.7K to Vcc across it. This provide a couple of mA (@ 5v) at most to keep the pin high.
    The internal pullups are valued at around 100K, which means they'll only provide about 50uA of current to hold it high. If you connect a load of much more than 50uA to that pin (a load resistance of much more than 100K), you'll be able to draw that pin low.
    Most likely, even though you're using the internal pullups, sometimes, depending on the outside circuitry, yes, you'll have to add a small pullup resistor.
    Generally speaking, a pullup resistor's value is either 4.7K or 10K, depending.
    Make the resistance too low, and you draw unneccessary current and it won't allow external circuitry to pull the pin low.
    Make the resistance too high, and you might not have enough current to pull the pin high like you wanted in the first place.
    Stick with 4.7K, and you should be fine.

  15. #55
    Join Date
    May 2007
    Location
    Harvest, Alabama
    Posts
    10


    Did you find this post helpful? Yes | No

    Unhappy Pullup resistors

    How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?) I really want to trigger the circuit with a minimum of time so I want the pullup fast so that my transistors (Nice NPN's for switching) with about 4.7 K ohms lead in resistance trigger off pretty much as fast as any current comes on the pin to signal it.

    I will be pushing a signal in the switch of the NPN transistor so that there is some current to pull a MOSFET fast. I need some current to move like NOW.

    In any case since I just cooked a $15 chip and an X1 Board , I really want to know some answers. (I just burned up some money) I need to know what voltage appears on the pins of the chip when we set for example a PORTA.2 =1. or PORTA.2 = 0 Is it on PORTA.1 = 1 a positive or negative voltage. It was logic testing that cooked this equipment.

    All advice will be appreciated.

    Well I got a cross of a posting that occurred between my post and an answer.

    The issue of Pullups seems to be a feature of the pin to cause it to draw some current to make it pull down a few thousandths of an ampere so that the circuit stays logic stable. I would think that if I am driving a transistor as I am the obvious value to use is about 10K because the transistor will have a 4.7 K or so leading out of the logic pin into the transistor Emitter. Or does this 4.7 to Vss draw down enough power so that the transistor needs no other resistor on the emitter?

    Generally a 5 VDC to emitter of a switching transistor with logic state high would take a 4.7 K ohm in the way of the signal feeding into the emitter (P of the NPN). If you take a 5 VDC state with a 10 K ohm to Vss and the positive voltage on the pins as high logic state then a 4.7 to the emitter should keep enough current to the transistor to open the gate so I am guessing based upon the previous answer that a 10 K ohm is in order (???)

    When we change from an input drain state as in the keyboard to an output control state, I would suspect that we add a current to bring the pin near switch on state but just below in order to logically control things, Is this so?


    Thanks
    Last edited by CluckShot; - 18th June 2007 at 01:52. Reason: cross posting

  16. #56
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    For Switchs, Keypad the Pull-up value is not really important. 10K is common, that's what i use. They can be higher... but i stick with 10K.

    For switches and Keypad, yes you could use the internal one without having too much problem.

    If you don't use any, this will cause you some problem as the internal gate don't see a logic level... it will see noise, so it will react weird. It has nothing to do with the Output driver, as the pin is set as Input. And BTW, if you enable ALL internal pull-up, they will be disabled on all Output configured I/O.

    <hr>PORTA.x = 1 = 5Volt
    PORTA.x = 0 = 0Volt<hr>

    To drive a transistor (NPN/PNP) you need a resistor in serie with the base, unless you will burn the I/O. Roughly, if you don't insert a resistor in serie with the transistor base, the i/O will see only a diode, as there's no current limiting resistor the current will be infinite. I=E/R, I=Vdd/0 hence some obvious damage to the PIC which can't provide more than 25mA by I/O, and x/PORT.

    The base resistor will have to be calculated. But you need to know how much current your transistor will drive and the transistor Hfe. The base resistor have to be higher than Vdd/25mA to avoid burning the I/O and few time lower than the calculated one to ensure proper switching.

    rb=Vdd-0.7/(Ic/Hfetyp)

    HTH
    Last edited by mister_e; - 18th June 2007 at 02:17.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  17. #57
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Steve

    Does the same apply to driving a n-channel power mosfet?
    I would like to drive a IRFP250N n-channel mosfet.
    (for this mosfet the static drain-to-source on-resistance Rds(on)=0.075ohm,
    drain-to-source leakage current Idss = 25-250uA)
    Do I also need a resistor inbetween the mosfet and the output pin?
    If so, should I use the same calc as above to determine the ohm value of the resistor?

  18. #58
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    in theory, you don't need any resistor in between as the gate impedance and their gain(not the right term but.. ) is quite large . BUT if you worry of a Gate to Source short, or else weird stuff, you should use a resistor in serie to 'protect' the PIC.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  19. #59
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    ... you should use a resistor in serie to 'protect' the PIC.
    If your concern is speed then
    this res should be as low as possible, 0-470 Ω.
    Else
    use larger one about 1K
    Endif

    Ioannis

  20. #60
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I tend to not use any resistor. If i need to drive high current, i sure use something else in between...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  21. #61
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Thank you Steve & Ioannis.

    Steve, what do you mean with:
    "If i need to drive high current, i sure use something else in between..."

  22. #62
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Another transistor or other driver I suppose.

    Microchip has such Mosfet drivers (either for high or los side)

    Ioannis

  23. #63
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Ioannis / Steve

    I would like to drive a 220V circuit with a power mosfet.
    Do you think an optocoupler is a MUST or will I be able to get away with a diode to protect my pic?
    If so, what diode or alternative protection would you recommend?
    Last edited by passion1; - 22nd June 2007 at 16:14.

  24. #64
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it's up to you. Everything will depend of what the whole beast will do, and how the enclosure design is done. But to me, as long as there's room to fit a transformer and optocoupler and keep away the AC line away of the user... i feel better and sleep all night without any problem.

    What do you need to drive?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  25. #65
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    ...

    But to me, as long as there's room to fit a transformer and optocoupler and keep away the AC line away of the user... i feel better and sleep all night without any problem.

    I double that. Even if the end user is well isolated from the circuit, YOU are not trying to make it work. You will have to debug the circuit while alive and sure put your life in danger.

    How many pcs are you going to sell? If it is say low quantity, for sure you will be paid by your time to develop the system. That money should be more than enough to let you put that transformer without second thought.

    In my country people say that coward's mother will never cry over the grave! Of course it sounds more elegant in greek than the awkard translation!!!

    Ioannis

  26. #66
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Ioannis / Steve

    Thank you for the wise advice!! I agree 100%.

  27. #67
    Join Date
    Apr 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Is it not just? AND am I missing somthing?

    Hello all,

    I have to ask because I have NEVER seen it done any other way. But is it not just plain good design practice to current limit with series resistors and pull up or down ALL digital I/O's?

    And as far as driving your 220AC device. You should ALWAYS use some sort of isolation device to protect your DC circuits AND the poor person that is trying to use them!

    But back to the thread....

    Tell me if I am missing something here and if this would work at all:

    if doing a keypad scan could you not use portb 0-2 and portb 3-7 for a 3x4 keypad. then use a look up table to get the actual key pressed? If you could do this it would be easy to add "secret" key combinations to do special functions in the project.

    I am just getting started here and learning lots by reading. I have spent quite some time looking over the Keypad code posted here and its VERY complex more so then I would have thought. am I missing something here?
    (I am not saying anything bad about the code. I could just be ignorant to what it takes to actually do this. So please don't be insulted.)

    Also, I see no accomidation in the keypad for compairing the input from the keypad to stored values for say "pin access" or the such. Or is this code ment to be only the keyscan?

    Just asking?

    ;Smart A** Programing Joke starts here
    cls
    Print "Best Regards,"
    Print "Bill12780"
    end

  28. #68
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Bill,

    It's not that it really takes that much code to scan a keypad. You can write your own that's much simpler, (Except that YOU actually have to write it). And then it will probably only work with that one set of hardware that you wrote it for.

    But mister_e's keypad module was written to work with Everybody's program. With lots of options to allow the user to customize it to work with whatever hardware they are using, and with different modes such as Auto Repeat, and Scan Once, or Modal modes. Without the user having to do much at all.

    It looks complicated on the inside, but that's the part you don't need to worry about. All you have to deal with is the actual useage of the module. Which is really easy. Define your pins and desired features, use an @ READKEYPAD _KeyVar, and you're done.

    It's just like when you use PicBasic Pro itself. You don't care how the code works inside the compiler. You just want to say LCDOUT "Hello World" and have it show up on the LCD display.
    Also, I see no accomidation in the keypad for compairing the input from the keypad to stored values for say "pin access" or the such. Or is this code ment to be only the keyscan?
    Correct. Just reads the keypad.
    For some sample code that can recognize a sequence of key presses. This might help.

    Combinaton Gate access
    http://www.picbasic.co.uk/forum/showthread.php?t=5695
    DT

  29. #69
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Single Port Pin

    Hello,

    I remember seeing an idea of connecting multiple (more than 1) switches on a single Port(analog) pin and working with the adc val.

    Cannot find this anymore on the forum.

    Any help on this topic/idea.

    regards

  30. #70
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    I don't remember where is the link, but you can do it easily just like that.

    From the analog port put some resistors in series to 5V. t the joints of the resistors put switch to ground. So every switch will result in different voltage at the ADC input. No switch pressed, the ADC will read 255 or 1023 (8 or 10 bit result).

    Ioannis

  31. #71
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Post Scanning Many Keys With One Input

    Hi charudatt,
    Quote Originally Posted by charudatt View Post
    Hello,

    I remember seeing an idea of connecting multiple (more than 1) switches on a single Port(analog) pin and working with the adc val.

    Cannot find this anymore on the forum.

    Any help on this topic/idea.

    regards
    TIP #5 Scanning Many Keys With One Input
    EDIT: TIP #7 4x4 Keyboard with 1 Input

    Microchip’s Tips ‘n Tricks (DS40040C)
    http://ww1.microchip.com/downloads/e...Doc/40040C.pdf

    Hope this helps,
    -Adam-
    Last edited by Pic_User; - 3rd July 2007 at 15:25. Reason: Added TIP #7

  32. #72
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Thanks

    Thank you Adam and Ioannis.

    That was exactly what I was looking for.

    regards

  33. #73
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CluckShot View Post
    How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?)
    I was taught, back in the "old days", to figure for about 1 ma to flow in the pullup (or, when needed, pulldown). Thus for 5-volt TTL, 4.7K; for 12-volt CMOS logic, 10K. I still use these values without thinking, and everything still works.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  34. #74
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bill12780 View Post
    I have to ask because I have NEVER seen it done any other way. But is it not just plain good design practice to current limit with series resistors and pull up or down ALL digital I/O's?
    This is what I was taught back in the "old days", but there are lots of circumstantial exceptions--there were circumstantial exceptions, then, too, but probably not as many of them!
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  35. #75
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CluckShot View Post
    How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?)
    I was taught, back in the "old days", to figure for about 1 ma to flow in the pullup (or, when needed, pulldown). Thus for 5-volt TTL, 4.7K; for 12-volt CMOS logic, 10K. I still use these values without thinking, and everything still works.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  36. #76
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think that's for a standard 10 TTL loads.

    But a PIC pin is only 1 load. So you can be fine with 40K, which is somewhere around the range of the internal weak pull-ups.
    <br>
    DT

  37. #77
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I think that's for a standard 10 TTL loads.

    But a PIC pin is only 1 load. So you can be fine with 40K, which is somewhere around the range of the internal weak pull-ups.
    <br>
    I'm sure you're correct, Darrel. As I wrote, that was a long time ago. My feeble point was, I still automatically use that thumb rule and those values and the circuits still work. (Probably kind of like driving a tack with a sledgehammer . . . )
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  38. #78
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Or shooting Quail with a Deer slug.

    But keep in mind we're talking keypads here.
    For something like high speed communication with I2C, lower values are required to overcome any capacitance that might cause a Slew Rate.

    In which case 4.7K is the perfect value.

    I'd say, just keep doing what you're doing, and you should be fine.
    <br>
    DT

  39. #79


    Did you find this post helpful? Yes | No

    Default problem with serout and keypad routin Mister_E

    Hi Steve,

    Some time ago you modified your code for pbp243 (if you remember)
    Meanwhile I have updated to 2.50

    After playing with your code I have a strange behavior
    If I want to serout something in the main loop it is not working
    any idea how to fix this



    INCLUDE "KeyPad.bas"
    myvar var byte

    start:
    Hserout ["test",10,13] 'does not do anything
    @ READKEYPAD _myvar
    hserout ["Key=",dec myvar,13,10]
    if myvar =1 then
    Hserout ["test2",10,13] 'does work if button 1 pressed
    endif
    goto start



    Quote Originally Posted by mister_e View Post
    Here's a simple INCLUDE file wich allow to scan any matrix KeyPad format on any PORT you decide. Yeah i know, a bit code hungry but simple to use and it's free...

    The defaults setings are
    1. Keypad ROW are connected to PORTB<3:0>
    2. Keypad COL are connected to PORTB<7:4>
    3. Debounce delay = 200 mSec
    4. No auto-repeat
    5. Keypad type 4X4

    Code example using the default setting
    Code:
        INCLUDE "KeyPad.bas"         
        myvar                    var byte
    
    start:
        @ READKEYPAD _myvar
        hserout ["Key=",dec myvar,13,10]
        goto start
    NOT MUCH!
    If you decide to change default settings, here's the DEFINEs list
    Code:
            DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
            DEFINE KEYPAD_ROW_PORT   PORTB    ' ROW port = PORTB
            DEFINE KEYPAD_ROW_BIT    4        ' ROW0 = PORTB.4
            DEFINE KEYPAD_COL        4        ' 4 COL keypad
            DEFINE KEYPAD_COL_PORT   PORTB    ' COL port = PORTB
            DEFINE KEYPAD_COL_BIT    0        ' COL0 = PORTB.0
            DEFINE KEYPAD_DEBOUNCEMS 200      ' debounce delay = 200 mSec
            DEFINE KEYPAD_AUTOREPEAT 1        ' use auto-repeat feature
    When using the auto-repeat feature, the delay is the debounce delay (DEBOUNCEMS)

    Code example #2: Using a 8X4 keypad
    Code:
        INCLUDE "KeyPad.bas"         
    
        '                      
        '    Hardware connection
        '    ===================
        DEFINE KEYPAD_ROW        8       ' 8 row 
        define KEYPAD_ROW_PORT   PORTB   '   on PORTB
        DEFINE KEYPAD_ROW_BIT    0       '      <7:0>
        DEFINE KEYPAD_COL        4       ' 4 col 
        DEFINE KEYPAD_COL_PORT   PORTA   '   on PORTA
        DEFINE KEYPAD_COL_BIT    0       '      <3:0>
        DEFINE KEYPAD_DEBOUNCEMS 200     ' debounce delay = 200 mSec
        define KEYPAD_AUTOREPEAT 1       ' use auto-repeat
        
        '
        '    Serial Communication definition
        '    ===============================
        DEFINE HSER_TXSTA 24h            ' enable transmit, BRGH=1
        DEFINE HSER_SPBRG 129            ' 9600 Bauds
    
        '   
        '    Variables definition 
        '    ===================
        myvar                    var byte
    
        '    ---------------------------------[Program Start]----------------------------------------------
    start:
        @ READKEYPAD _myvar
        hserout ["Key=",dec myvar,13,10]
        goto start
    It set the according TRIS register for you everytime you call the MACRO.. kinda bullet-proof

    Everything is explain in the attach file... don't forget to rename it

  40. #80


    Did you find this post helpful? Yes | No

    Default Optional timeout keyboard routine

    Hi MisterE

    Using with succes your keypadroutine on a 4x2 keypad

    I was wondering if it would be possible to jump out the keypadroutine if no key is pressed
    in order to handle the main loop

    I need to receive some serial commands by HSERIN, but when a key is pressed
    it should go to a label and then return to the main loop checking Hserin

    Now it waits for a keypress

    Thanks

Similar Threads

  1. calculator-like code entry with matrix keypad and display
    By Dennis in forum mel PIC BASIC Pro
    Replies: 35
    Last Post: - 16th December 2009, 23:58
  2. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 14:16
  3. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 22:25
  4. Inconsistent output on a 4x4 matrix keypad
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 04:54
  5. very basic matrix keypad question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th July 2006, 22:33

Members who have read this thread : 3

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts