Go Down

Topic: [clarified] Software debounce without millis and attiny13a, respectively (Read 1 time) previous topic - next topic

terraduino

Hi,

I'm wondering what the most efficient way is to implement a software debouncing routine when using the attiny13a and no millis(), respectively.
Do I have to implement a "waiting routine" with NoOP or the like?

Thanks & best
--
Just a curious hobbyist. Only basic knowledge about electronics, microchips and the like.
Non-native speaker, please bear with me.

PaulRB

What do you mean by "efficient"? Efficient in what way?

Why do you not want to use millis()?

terraduino

Thanks for your reply. :)
I'm using MicroCore for the attiny and both millis() and micros() are disabled.
With "efficient" I mean "the smallest possible solution" due to the limited space on the attiny13a "that comes an expert into mind after less than 2 minutes thinking". ASM would also be possible but I've never done that before and read some threads were people had problem with compiler optimization.

Hope that clarifies my intention :)
Best!
--
Just a curious hobbyist. Only basic knowledge about electronics, microchips and the like.
Non-native speaker, please bear with me.

PaulRB

This one supports millis().

Quote
"that comes an expert into mind after less than 2 minutes thinking".
Who is that quotation from?

hansibull

Enabling the millis function occupies about 100b because of the interrupt routine. The millis implementation can be found here. If you have 100b to offer, this is the simplest option. Of course you can debounce a button using a fixed delay. The delay() function is based on the avrlibc _delay_ms() function.

A simple debounce function might look like this, and works _ok_
Code: [Select]

// Wait while the button is pressed
while(digitalRead(buttonPin) == LOW)
{
  delay(100);
}

// Button is now debounced
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

Smajdalf

You can also use the Watchdog or Timer/Counter for generating the delay.
How to insert images: https://forum.arduino.cc/index.php?topic=519037.0

septillion

But if you do that, why not make it a bit more useful and make it into a "millis()" then?

If you really don't want to enable millis() (or enable a timer to to the timing) then you could just use delay() but know that's (ugly) blocking code....
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

terraduino

Thank you all for the replies.

I think this is a misunderstanding
This one supports millis().
millis() was disabled to save space, as hansibull pointed out.

Who is that quotation from?
Well, I didn't use those to quote, more like signaling unusual usage cf. https://en.wikipedia.org/wiki/Quotation_marks_in_English


@hansibull 
Thanks for the idea. That would be pretty simple ;) I'll have a look how good this works.
Btw. blocking is no problem for my use case.

@Smajdalf
I'm not sure how you suggest to use the Timer. Do you have a link for an example?

Thanks & best!
--
Just a curious hobbyist. Only basic knowledge about electronics, microchips and the like.
Non-native speaker, please bear with me.

septillion

I'm not sure how you suggest to use the Timer. Do you have a link for an example?
But if you do that, why not make it a bit more useful and make it into a "millis()" then?
Aka, if you disabled millis() to save space (which is pretty minimal btw) this isn't going to help because this will take the same amount of memory.... millis() isn't that complex.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Jiggy-Ninja

A simple debounce function might look like this, and works _ok_
Code: [Select]

// Wait while the button is pressed
while(digitalRead(buttonPin) == LOW)
{
  delay(100);
}

// Button is now debounced


What the hell is that snippet supposed to do? It certainly isn't a debounce routine. If the button is held instead of pressed everything stops.
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

septillion

Mehh, it does debounce. In a very ugly and blocking way but it does debounce. Will even give some extra headaches when you want to read multiple buttons etc.

Aka, why make it hard and not just implement millis() and have all the timing issues under control without wasting everything...
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Jiggy-Ninja

Mehh, it does debounce. In a very ugly and blocking way but it does debounce. Will even give some extra headaches when you want to read multiple buttons etc.

Aka, why make it hard and not just implement millis() and have all the timing issues under control without wasting everything...
That isn't a debounce routine, that is a "Stop EVERYTHING until the button is released!" routine.
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

septillion

I agree :D But with it button bounce isn't a problem so it "debounces" xD
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Jiggy-Ninja

I agree :D But with it button bounce isn't a problem so it "debounces" xD
I just read this wonderful comment from EEVBlog's forum:
Quote
[It] works in the same way that crushing someone's skull stops a headache. The goal may be achieved, but the side effects might be considered undesirable.
I'll just leave that there for all to appreciate.
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

Go Up