Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PIC]: Debounce Circuit

126 views
Skip to first unread message

Bill & Pookie

unread,
Mar 4, 2003, 11:39:38 AM3/4/03
to PIC...@mitvma.nospam.mit.edu
Mr. Scott Dattalo's debounce code is a work of
art.

After some experience with keys, switches, photo
cells and magnetic detectors, I denounce
everything in software. everything.... Even
debounced a few software switches.

As the software denounce depends on timing, have a
constant time free running interrupt routine that
denounces all the input pins, and also outputs all
the updated output pins at same time.

Now to get on the SOAP BOX....

While Mr. Dattalo's debounce code is a work of
art, But "DON'T TRY THIS AT WORK". Use the code,
but don't try to emulate the style.

You wrote....
>Take some time to fully understand it<

It would be very difficult to modify and if it
didn't work, would be hard to debug. It would be
a nightmare to debug a page of code written in
this style, even if you wrote it a month ago.

Notice that it takes a web page to comment this
code? I sort of have a rule that if it takes more
lines to comment a bit of code then the code
takes, then the code is too complicated. When the
code is written and debuggeg, the programming job
is only half over. Latter comes the
modifications. Also the same code may be ported
to other programs. And the time involved to write
the code could be excessive.

I am so impressed with this code that I tried to
port it to basic one time.

Bill

the code
http://www.dattalo.com/technical/software/pic/debo
unce.html


----- Original Message -----
From: "Biswanath Dutta"
<biswana...@HOTMAIL.AntiSpam.COM>
To: <PIC...@MITVMA.RemoveThis.MIT.EDU>
Sent: Wednesday, February 26, 2003 6:19 PM
Subject: Re: [PIC]: Debounce Circuit


> Thanks to all for help. Specially Mr. Scott
Dattalo whose amazing code I,ve
> started using.
> Take some time to fully understand it. Thanks a
lot
>
> Biswanath Dutta
>

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

Wouter van Ooijen

unread,
Mar 4, 2003, 3:08:03 PM3/4/03
to PIC...@mitvma.we.hate.sp.am.mit.edu
> Notice that it takes a web page to comment this
> code? I sort of have a rule that if it takes more
> lines to comment a bit of code then the code
> takes, then the code is too complicated.

I think your argument holds only when you compare two solutions that
require a compareable number of code lines, and one requires much more
comment lines than the other. A lot of things (involving vertical
counters and other clever constructs) can also be done by 'simple' code,
but when a very compact coding style is the only way to squeeze the
application in the code space and/or CPU time that is available there is
no other solution to compare it to, so it wins by default.

And you might know (or not) that Scott spends some of his time hacking
at a PIC compiler (at least he used to). Now do yopu or don't you want a
compiler to create compact yet unreadable (at least to you) code?

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: www.voti.nl
consultancy, development, PICmicro products

Michael Rigby-Jones

unread,
Mar 5, 2003, 2:36:12 AM3/5/03
to PIC...@mitvma.bogus.mit.edu
> -----Original Message-----
> From: Bill & Pookie [SMTP:williamc...@ATTBI.Extra.COM]
> Sent: Tuesday, March 04, 2003 4:51 PM
> To: PIC...@MITVMA.Delete.MIT.EDU
> Subject: Re: [PIC]: Debounce Circuit
>
> I denounce everything in software. everything....
>
>
Yeah, I have days like that too... :o)

Mike


=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to postm...@bookham.Bogus.com.

--
http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.

Scott Dattalo

unread,
Mar 5, 2003, 9:09:18 AM3/5/03
to PIC...@mitvma.nothis.mit.edu
On Tue, 4 Mar 2003, Bill & Pookie wrote:

> Mr. Scott Dattalo's debounce code is a work of
> art.

Well, I don't know about that...
<snip>

>
> Now to get on the SOAP BOX....
>
> While Mr. Dattalo's debounce code is a work of
> art, But "DON'T TRY THIS AT WORK". Use the code,
> but don't try to emulate the style.

Nor do I know about that!

>
> You wrote....
> >Take some time to fully understand it<
>
> It would be very difficult to modify and if it
> didn't work, would be hard to debug. It would be
> a nightmare to debug a page of code written in
> this style, even if you wrote it a month ago.

I certainly wouldn't know *anything* about that! :)

>
> Notice that it takes a web page to comment this
> code? I sort of have a rule that if it takes more
> lines to comment a bit of code then the code

> takes, then the code is too complicated. When the
> code is written and debuggeg, the programming job
> is only half over. Latter comes the
> modifications. Also the same code may be ported
> to other programs. And the time involved to write
> the code could be excessive.

If you write code professionally, you'll find that quality commenting is
necessary. The project I'm working on now has a ratio of about 6:1 for
lines of comments to assembly instruction. I.e. for every instruction,
there are on average SIX lines of comments describing it. The comment
style is not too unlike the one on my debounce webpage: a few paragraphs
describing the problem and solution, followed by a high-level psuedo code
implementation, and succint single line descriptions near every
instruction relating back to the more verbose descriptions.

There's nothing wrong with writing complex code in and of itself. However,
sometimes it's important to just get *something* working, and later on go
back and optimize it if necessary. What you'll find is that over time
you'll build up a library of snippets and experience upon which you can
leverage for future projects. Writing a debounce routine from scratch is
fairly trivial, writing one that's highly optimized is challenging, and
using a highly optimized one that has already been written is the ideal
situation! The same goes for just about any code (though in some cases,
starting from scratch is not trivial).

> I am so impressed with this code that I tried to
> port it to basic one time.

That should be easy! There's the C-implementation right in the comments.

A challenging thing to do would be to modify the code to have a 3-bit
vertical counter instead of a 2-bit one. I think it'd take five more
instructions.

Scott

0 new messages