debounce state diagram FSM

K

Keith Thompson

John Larkin said:
Programming embedded systems, things that interface to the real world,
are off-topic to c programmers? Why am I not surprised?

Questions which have nothing to do with programming in C are off-topic
in comp.lang.c. (If the original poster had asked for a C solution,
it might have been different, but I don't think I've seen a single
line of C source code in this thread.)

I'm getting the impression that once someone posts an inappropriately
cross-posted discussion, there's just no way to keep it from
continuing on all the newsgroups to which it was originally posted,
because most people posting followups just don't pay attention to the
Newsgroups: header. Oh, well.
 
J

Jim Granville

Keith said:
I did, but it didn't do any good. I could only set followups in my
own followup; other direct replies to the original message retained
the full cross-posting.

Err - not on this one, it seems ?

-jg
 
P

Peter Nilsson

[f-ups to clc]


Other than what you've done, no. Although you could probably
try to _make_ it topical. That way, an otherwise noisy thread
may at least have some merit.
Questions which have nothing to do with programming in C are
off-topic in comp.lang.c. (If the original poster had asked
for a C solution, it might have been different, but I don't
think I've seen a single line of C source code in this thread.)

Well, let's post some... [both single bit in - single bit out]

/* crude state machine */
int debounce(int in)
{
static enum { sxx, s00, s01, s11, s10 } state = sxx;
static struct { unsigned char out; unsigned char next; }
fsm[][2] =
{ /* 0 */ /* 1 */
/* sxx */ { { 0, s00 }, { 1, s11 } },
/* s00 */ { { 0, s00 }, { 0, s01 } },
/* s01 */ { { 0, s00 }, { 0, sxx } },
/* s11 */ { { 1, s10 }, { 1, s11 } },
/* s10 */ { { 1, sxx }, { 1, s11 } }
};
int out = fsm[state][in].out;
state = fsm[state][in].next;
return out;
}

/* shift register */
int debounce(int in)
{
static unsigned char reg = 3;
static unsigned char out = 0;
reg = ((reg << 1) | in) & 7;
if (reg == 0 || reg == 7) out = reg & 1;
return out;
}
 
K

Keith Thompson

Jim Granville said:
Err - not on this one, it seems ?

No, not on this one. In my initial message, I redirected followups in
an attempt to divert the discussion away from comp.lang.c. In my
later message, I was trying to find out why that didn't work and what
might work instead, so I didn't bother redirecting followups.
 
F

Flash Gordon

Keith Thompson wrote, On 02/05/07 04:45:
No, not on this one. In my initial message, I redirected followups in
an attempt to divert the discussion away from comp.lang.c. In my
later message, I was trying to find out why that didn't work and what
might work instead, so I didn't bother redirecting followups.

I also tried redirecting, and explicitly requested that people on other
parts of the thread exclude comp.lang.c, I was even polite about it. I
believe the reason it does not work is that a lot of people only care
about there own group, not other groups to which something might be
inappropriately cross-posted, so even after reading the requests they
continue posting to other parts of the thread without restricting
follow-ups.

I'm beginning to think the solution is to post a couple of requests, and
after 24 hours plonk everyone who ignores the requests.

Note I've not set followups this time because discussions about
topicality *are* topical.
 
F

Flash Gordon

John Larkin wrote, On 02/05/07 01:51:
Programming embedded systems, things that interface to the real world,
are off-topic to c programmers? Why am I not surprised?

I gave the best C answer, which was that it is better solved in HW. I
also stated that I have done debounce in SW, but I did not get any
response asking how, so obviously everyone agreed that implementing it
in HW was better.

Perhaps we should post questions about string theory in your groups,
after all semi-conductors only work because of the laws of physics in
the real world, so you must be interested in whether string theory is
correct or what modifications are required to it for it to be correct
and want those discussions in your groups.
 
R

Robin

Questions which have nothing to do with programming in C are off-topic
in comp.lang.c. (If the original poster had asked for a C solution,
it might have been different, but I don't think I've seen a single
line of C source code in this thread.)

I'm getting the impression that once someone posts an inappropriately
cross-posted discussion, there's just no way to keep it from
continuing on all the newsgroups to which it was originally posted,
because most people posting followups just don't pay attention to the
Newsgroups: header. Oh, well.

--
Keith Thompson (The_Other_Keith) (e-mail address removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

It's worse than that, this is really a DSP question.

The sampled input above will *require* an anti-alias filter - making
itself redundant.

Robin
 
J

jasen

FAIK the OP was asking about the design of a finite state machine. Nothing
said about the implementation. C is a perfect language to build finite state
machines.

C.L.C is for discussing the C language, anything else (eg: algorithms, a
particular implementation of c, or actual code) is off-topic.

If the kooks were to hit CLC noone would notice the newsgroup was when I
stopped reding it 20% off-topic posts, 40% complaints about off-topic posts,
10% questions answered by the FAQ, 25% "read the FAQ", and 5% actual
on-topic posts (which were boring as hell).

C.L.C.moderated is a better group, as long as you're not in a hurry for an
answer, the rules of topicality are ironically more relaxed than in the
non-moderated group.

Bye.
Jasen
 
J

jasen

On 29 Apr, 19:32, (e-mail address removed) wrote:
This debounce idea is terrible. Straight away you have aliasing
problems not to mention arbitrary latency.

The simple thing to do is detect an edge by e.g. edge driven interrupt
and then fire the output state immediately according to the edge
direction and start your one-shot debounce-duration timer that
inhibits the interrupt until it times outs.

Now you have instant "analogue" style response and you can reduce the
duration until bouncing happens and then back it off by a safety
margin.

depends if he merely wants to de-bounce or if he also wants to de-glitch

Bye.
Jasen
 
J

John Larkin

John Larkin wrote, On 02/05/07 01:51:

I gave the best C answer, which was that it is better solved in HW.

But hardware costs money on a production basis, and code is free. So
"better solved in hardware" translates to "I'm only interested in
programming, so don't annoy me with applications."
I
also stated that I have done debounce in SW, but I did not get any
response asking how, so obviously everyone agreed that implementing it
in HW was better.

If it's a pure bounce problem, just check the switch state 10 times a
second and use what you see... no debounce needed.

John
 
F

Flash Gordon

John Larkin wrote, On 02/05/07 20:01:
But hardware costs money on a production basis, and code is free. So
"better solved in hardware" translates to "I'm only interested in
programming, so don't annoy me with applications."

No, it translates to use the correct tool for the job. This is why
keyboard controllers do the debounce on keyboards rather than leaving it
to the OS.
If it's a pure bounce problem, just check the switch state 10 times a
second and use what you see... no debounce needed.

Having been this route more than once because it was a one-off and
already built, I can tell you that SW solutions do not work as well as
properly designed HW when the SW has other things to do, one reason
being that the HW can sample the data much faster.

Since the OP still has not commented on the possibility of a C solution
it still seems likely that is not what the OP actually wants.
 
J

Jim Lewis

Keith,
A few minutes of breathing, adopting a forgiving attitude,
and forgoing the concerned posts about the cross-posting
would reduce the net traffic by 30% (accurate yesterday -
includes replies - probably increased today).

Of course it would be nice if people did not cross-post
potentially irrelevant topics (which this may or may not
be), however, if you have a threaded news reader, close
the thread and the clutter is gone.

It seems to me that the only difference it makes is to
the people who are following the thread. I have to flip
through the posts without content (your complaints).

Regards,
Jim
 
F

Flash Gordon

Jim Lewis wrote, On 02/05/07 21:24:
Keith,
A few minutes of breathing, adopting a forgiving attitude,
and forgoing the concerned posts about the cross-posting
would reduce the net traffic by 30% (accurate yesterday -
includes replies - probably increased today).

A little consideration by those continuing to cross-post after it has
been pointed out would reduce traffic more. After al, the requests were
polite.
Of course it would be nice if people did not cross-post
potentially irrelevant topics (which this may or may not
be),

Since no one from comp.lang.c has come in to say it is topical on
comp.lang.c and the thread has so far had one post with C in it, from
someone saying basically "you are complaining so here is some C" I think
it is fairly conclusive.
> however, if you have a threaded news reader, close
the thread and the clutter is gone.

The additional time downloading is not, and some people are still on
slow dial-up *and* paying per minute. Also, if it is OK for one it is OK
for all, so we get loads more off topic cross-posting and matters become
worse.
It seems to me that the only difference it makes is to
the people who are following the thread. I have to flip
through the posts without content (your complaints).

If people would stop the cross-posts when it was pointed out that would
be one or two posts not lots. Therefore, the thing that will reduce it
most is if people stop inappropriate cross-posts when it is pointed out.

Why do you think it reasonable for us to have to put up with
inappropriate cross-posts and not for you to put up with polite requests
to stop the cross-posts?
 
D

Default User

Jim Lewis wrote:

Of course it would be nice if people did not cross-post
potentially irrelevant topics (which this may or may not
be), however, if you have a threaded news reader, close
the thread and the clutter is gone.

While I'm not Keith, I'll say I can't agree with your position. The
best way to keep a newsgroup clear of clutter is to speak up when
off-topic stuff appears, not just ignore it.

That's a fairly typical reaction here in comp.lang.c. Those who don't
like it should refrain from posting off-topic messages here. The easy
way to avoid that in this thread is start removing clc from the
newsgroup list. By now, most people should have seen the complaints,
and really have very little excuse.

The original message was off-topic, and the vast majority of follow-ups
have been off-topic. There's very little question about that.




Brian
 
R

Rich Grise

Questions which have nothing to do with programming in C are off-topic
in comp.lang.c. (If the original poster had asked for a C solution,
it might have been different, but I don't think I've seen a single
line of C source code in this thread.)

I'm getting the impression that once someone posts an inappropriately
cross-posted discussion, there's just no way to keep it from
continuing on all the newsgroups to which it was originally posted,
because most people posting followups just don't pay attention to the
Newsgroups: header. Oh, well.

Well, you could have removed comp.lang.c from your own followups, rather
than perpetuating it. After all, you only want to bitch at the people in
the other groups, right?

And you _do_ know how to set "followups-to", don't you?

I envision a squad of about a half-dozen people, back-to-back-to-back, etc.,
trying to fend off the onslaught of C++, perl, assembler, etc, etc,
etc...

Good Luck!
Rich
 
D

Default User

Rich Grise wrote:

Well, you could have removed comp.lang.c from your own followups,
rather than perpetuating it. After all, you only want to bitch at the
people in the other groups, right?

And you do know how to set "followups-to", don't you?

People keep saying this like it's some sort of magic. All that does
direct replies to THAT message to certain groups. It has jack to do
with the thread.

It's also the case that topicality IS on-topic in comp.lang.c, as in
all groups, so there's really no need to set follow-ups in those cases.
In fact, I'd argue that it's the wrong thing to do.
I envision a squad of about a half-dozen people,
back-to-back-to-back, etc., trying to fend off the onslaught of C++,
perl, assembler, etc, etc, etc...

This demonstrates that you have little familiarity with C or
comp.lang.c.




Brian
 
F

Flash Gordon

Rich Grise wrote, On 02/05/07 23:41:
And you're still following up to the group that you want the crosspost
removed from.

Are you C people all that lame?

Here's a clue: Set your followups to:
comp.lang.vhdl,comp.arch.fpga,sci.electronics.design,comp.lang.verilog
for your whining and bellyaching - you might be surprised!

That does sod all good because the off topic posts are not in response
to it being redirected.
Of course, in this case, I've already repaired it.

In the wrong direction since you directed it at the one group we can all
be reasonably sure you do not read, so I've redirected it back to the
groups where people have been inconsiderate enough not to restring
cross-posts after polite requests and are getting upset about some
people not liking it.
> And threads like
this usually die soon anyway.

They die a lot faster when people take note when it is pointed out the
thread is off topic in one or more groups.
 
J

John Larkin

Jim Lewis wrote, On 02/05/07 21:24:

A little consideration by those continuing to cross-post after it has
been pointed out would reduce traffic more. After al, the requests were
polite.


Since no one from comp.lang.c has come in to say it is topical on
comp.lang.c and the thread has so far had one post with C in it, from
someone saying basically "you are complaining so here is some C" I think
it is fairly conclusive.


The additional time downloading is not, and some people are still on
slow dial-up *and* paying per minute. Also, if it is OK for one it is OK
for all, so we get loads more off topic cross-posting and matters become
worse.


If people would stop the cross-posts when it was pointed out that would
be one or two posts not lots. Therefore, the thing that will reduce it
most is if people stop inappropriate cross-posts when it is pointed out.

Why do you think it reasonable for us to have to put up with
inappropriate cross-posts and not for you to put up with polite requests
to stop the cross-posts?


You're right, engineers and programmers should communicate as seldom
as possible.

John
 
F

Flash Gordon

John Larkin wrote, On 03/05/07 01:09:
On Wed, 02 May 2007 22:59:08 +0100, Flash Gordon


You're right, engineers and programmers should communicate as seldom
as possible.

OK, so you are incapable of reading, understanding or answering
questions even when those you are responding to are staying polite.

For the record, I have never said engineers and programmers should not
communicate, and I have worked very closely with HW people in the past
where it was appropriate. However, that still does not, and never can
make, posting stuff in comp.lang.c about how to design the HW
appropriate in comp.lang.c

Note that the only comment I got when asking if posting physics
questions to the other groups was a post saying one of the groups was
already being invaded by trolls, not a response saying that it would be
acceptable. So you obviously only care about the topicality of YOUR
group(s) and sod everybody else.
 
J

John Larkin

John Larkin wrote, On 03/05/07 01:09:

OK, so you are incapable of reading, understanding or answering
questions even when those you are responding to are staying polite.

For the record, I have never said engineers and programmers should not
communicate, and I have worked very closely with HW people in the past
where it was appropriate. However, that still does not, and never can
make, posting stuff in comp.lang.c about how to design the HW
appropriate in comp.lang.c

Note that the only comment I got when asking if posting physics
questions to the other groups was a post saying one of the groups was
already being invaded by trolls, not a response saying that it would be
acceptable. So you obviously only care about the topicality of YOUR
group(s) and sod everybody else.


s.e.d. routinely discusses electronic circuit design, thermal design,
mechanics and materials properties, manufacturing and economic issues,
fpga design, uPs/firmware/dsp/numeric algorithms, operating systems,
and computer languages. In a real electronic design, all these must be
accounted for and all trade off against the others. If switches
bounce, there are a number of solutions, the cheapest and most
reliable (assuming no coding bugs!) being to do it in software.

I'm always interested in how hermetic some disciplines are, how
intense some programmers are to keep the programming pure, to abstract
away the real world, and to do their best to know nothing about the
environment their programs actually live in; hence comments like
"switch debouncing is best done in hardware."

I mean, if all you know is programming, how do you find a problem to
program? Do you depend on an exhaustive specification that's created
by someone else who understands the end application, so you don't have
to get involved? Would you ever look at a switch datasheet to see how
long it might bounce?

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top