4x4 keypad on bus

joeyd999

Joined Jun 6, 2011
5,234
No! The one-wire has to be done as independent tight code, probably with precise software delays (and therefore ints disabled)....
I'd like to elaborate just a bit further:

If I could not afford to disable ints for the period of a 1-wire transception, I'd look at at least 3 options:

1. Can I use dedicated external hardware to process the 1-wire?
2. Can I repurpose existing on-chip hardware to drive the 1-wire (i.e. UART)?
3. Can I bit-bang in a high-priority interrupt?
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
Wow i was away just a few hours and the thread managed to blow op. Ok, lets do it


Where is the 1-wire connected?
The 1 wire devices are connected separately from everything else, port 3.5 for reading and 3.4 for writing(not really important)

Even better, Ernie, is to just set a flag that a period of time has elapsed in the ISR. Then, poll that flag in your main loop to activate the keypad polling routine synchronously with the main program.

In fact, every application I write has the following timer 0 code:

Code:
;********************************************************
;** Timer 0 -- Main Program Heartbeat Every 1.024ms    **
;********************************************************

tmr0int    bcf    intcon,tmr0if        ;turn off t0 int

    movf    _timer,w        ;get current time
    incf    _timer,f    ;and increment it
    xorwf    _timer,w        ;compare with last
    iorwf    _tmrchg,f        ;and save changed bits

    bra    intdone            ;and getout
This gives me a set of bits in _tmrchg that represent elapsed time of 1,2,4 ... ms that I can use to trigger events in the main code.

The first routine of the main loop looks like this:

Code:
;******************************************************************
;** GETTIM -- Get current time and changed bits since last check **
;******************************************************************

gettim    clrf    tmrchg1            ;clear bits from previous pass

    bcf    intcon,tmr0ie        ;disable ints
    movff    _timer,timer        ;copy timer data
    movff    _tmrchg,tmrchg
    clrf    _tmrchg        ;clear for next time
    bsf    intcon,t0ie        ;and reinable ints

    return
I give each bit of tmrchg a name using #define, and then I can do this:

Code:
;*****************************************
;** GETKEY -- Process key every 32 ms   **
;*****************************************

getkey    clrf    keychg            ;clear changed keys
    clrf    keypr            ;clear press and release registers
    clrf    keyph            ;clear press and hold registers
    clrf    keyrpt            ;clear key repeat register

    retbc    TC4ms            ;process kbd row every 4 ms (total 32 ms debounce time)

    ...
where the flag bit TC4ms is set for the loop every 4.096ms.
I sadly can not read assembly, but you are right about the delays having to be very very tight. As i stated before, a few microseconds can make me get wrong data from the 1wire (e.g. 1 command has to have a maximum of 4us delay if i remember right)

@John P
I think using external interrupt to read from the keypad is a good idea. It keeps the code cleaner and saves me the bother to call functions where i could read them. The problematic part is the polling of the keypad. That is why i wanted the timer interrupt, but it did not work as i hoped.
What i am doing now is that inside a while 1 i am constantly calling a function that is polling the keypad and if a button is pressed it will act accordingly. This is not perfect because, well, it just feels slow, and beginnerish.


I'd like to elaborate just a bit further:

If I could not afford to disable ints for the period of a 1-wire transception, I'd look at at least 3 options:

1. Can I use dedicated external hardware to process the 1-wire?
2. Can I repurpose existing on-chip hardware to drive the 1-wire (i.e. UART)?
3. Can I bit-bang in a high-priority interrupt?
1. no
2.no
3. 0.1 knowledge in bit banging
 
Last edited:

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
Learn. Even if you don't code in it.

It's not that hard, and it will provide great insight into the kinds of problems you are having.
Well you are probably making it sound easier than it actually is because you already know it.
The thing is, im an intern in this R&D company, and i do not have much time left. I can not spare time on assembly at the moment. But if you say that, and such developing is really my cup of tea i will probably study it in the future
 

joeyd999

Joined Jun 6, 2011
5,234
The thing is, im an intern in this R&D company, and i do not have much time left.
As an intern, you should not be required to solve every problem on your own. There should be engineers there mentoring you on solving problems like this. If not, what is the point of interning?
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
As an intern, you should not be required to solve every problem on your own. There should be engineers there mentoring you on solving problems like this. If not, what is the point of interning?
My personality is in the way of that. I have asked some hardware questions since i did not have much idea about buses, but i find it hard to ask help from someone in person, that is why i am here. Plus for me it kinda helps to write about my problem, my brain usually realizes something then, i don't even know :D
 

joeyd999

Joined Jun 6, 2011
5,234
My personality is in the way of that. I have asked some hardware questions since i did not have much idea about buses, but i find it hard to ask help from someone in person, that is why i am here. Plus for me it kinda helps to write about my problem, my brain usually realizes something then, i don't even know :D
The more problems you solve on you own -- on a timely basis -- the better you will look. The more you fail, or fail to hit the time budget, the worse you will look.

It's a tricky balance.

IMHO, an intern asking questions rarely reflects negatively upon him -- unless the question reveals lack of something the intern advertised he had.
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
The more problems you solve on you own -- on a timely basis -- the better you will look. The more you fail, or fail to hit the time budget, the worse you will look.

It's a tricky balance.

IMHO, an intern asking questions rarely reflects negatively upon him -- unless the question reveals lack of something the intern advertised he had.
Well, i guess you are right, the guys at the firm are just way out of my league, i mean Ph.D out of my league
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
Fine. So you're on the farm team. They already know that. Do what you need to do to get into the big leagues. Whatever it takes.
I am, the last thing i need to get a hold of to hopefully join some project is to get 1wire search function working

And thank you for your words. I always come to this forum during my lunch. You guys are just awesome and i am sad i did not find this place earlier.
 
Last edited:
Top