[Coco] Detecting Shift key.

Dave Philipsen dave at davebiz.com
Sat Sep 23 19:50:22 EDT 2017


So one way I have written debouncing routines in the past for mechanical switches is to create an accumulator which is initially zero'd out. When the switch tests as closed you increment the accumulator.  When the switch tests as open you decrement the accumulator. The routine continues looping until the accumulator reaches a preset threshold the keypress is generated.  That means a greater than 50% duty cycle is needed on a noisy switch in order to get the accumulator to accumulate. Once a keypress is generate for that switch, a new one cannot be generated until the accumulator reaches zero again.  You can also generate a key release code by using a threshold that is reached as the accumulator decrements. Of course a key release can only be generated after a keypress.

Once you write the routine you can test it by connecting a square wave signal generator to the input with a frequency of a few hundred hertz.  A 50% or less duty cycle square wave will do nothing.  Greater than 50% will eventually generate a keypress.



Dave

> On Sep 22, 2017, at 1:16 PM, Joel Rees <joel.rees at gmail.com> wrote:
> 
> 2017/09/22 22:09 "Dave Philipsen" <dave at davebiz.com>:
>> 
>> That's a pretty crude debounce routine and for the original intention
> it's probably not needed. A more robust routine would do more than just
> check for the same result a couple of microseconds later.
>> 
>> Dave
>> 
>>> On Sep 22, 2017, at 7:36 AM, Johann Klasek <johann+coco at klasek.at>
> wrote:
>>> 
>>>>> On Fri, Sep 22, 2017 at 12:06:04PM +0200, Tormod Volden wrote:
>>>>> On Fri, Sep 22, 2017 at 2:39 AM, Steven Wallis  wrote:
>>>> [..]
>>>> This will work on all machines to detect shift:
>>> 
>>> How about to debouce? Could this be done like this?
>>> Added the "wait for shift" line in case one waits until
>>> the shift key is pressed ...
>>> Would these modifications of any value?
>>> 
>>>> 
>>>>        ldb   #$7F         ; pull down row containing shift
>>>>        stb   $FF02
>>> wait
>>>>        ldb   $FF00
>>>          cmpb  $FF00
>>>          bne wait         ; debounce
>>>>        comb
>>>>        andb  #$40       ; check column containing shift
>>>          beq   wait       ; wait for shift
>>> 
>>>>        bne   gocmdl          ; return if shift key pressed
>>> 
>>> Johann
> 
> This ancient diver framework I wrote for a college class may provide some
> insight as to handle the keyboard without wasting CPU cycles riding it, and
> providing true debounce.
> 
> On the other hand, just checking on whether the shift key is pressed
> doesn't really need debounce. And this should also provide reference on how
> to do that.
> 
> https://ja.osdn.net/users/reiisi/pf/jmr6809bos/
> https://ja.osdn.net/users/reiisi/pf/jmr6809bos/scm/tree/master/
> https://ja.osdn.net/users/reiisi/pf/jmr6809bos/scm/blobs/master/oswind3test.as9
> 
> It's written for the Coco, so certain constants would need to be changed
> for the Dragon.
> 
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco



More information about the Coco mailing list