Notifications
Clear all

[Solved] Arduino Timers – no pain and all gain!

56 Posts
8 Users
36 Likes
4,189 Views
ron bentley
(@ronbentley1)
Member
Joined: 2 years ago
Posts: 385
Topic starter  

Ron, @zander ,

if you have an interest of running multi-tasking solutions on Arduino then search out the Real-Time Operating System (RTOS) library for Arduino.

I have not used it but it purports to manage multi-tasking designs(?)

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@ronbentley1 Thanks, I did start to poke around in that area, but of course got distracted. I think I even downloaded it.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

It appears the site you mention only works for Arduino boards, I want a timer for an ESP32 board. A quick look at some doc'n tells me that at least some of the lingo is the same. Any thoughts? BTW, I am working on the next Button code. It is using an ISR but now I am adding a MUX based critical section and it isn't finding a typedef otherwise it would be done except for debouncing.

Can you tell me a real quick hdw debounce trick, I thought I read a small cap across the contacts was all that was needed.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Inst-Tech reacted
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 2 years ago
Posts: 385
Topic starter  

@zander 

Yes, that site is for avr boards like the Arduino range. I'm not aware of an ESP ewuivalent, sorry about that.

For switch denounce you could use a library for switch reading, my own is published on the Arduino Project Hub, link address here.

The library is called ez_switch_lib and handles different switch types wired in different schemes. It handles denounce and offers many more features.

But there are others I'm sure and putting aside software denounce you could implement a hardware solution, as you hint.

If you want to implement your own software or hardware denounce then there are numerous articles providing guidance.  For me, though, I always use my own ez switch library as I'm more comfortable with software.

This library is also able to be used to drive external interrupts via switch activations, single or multiple switches, on Arduino anyway.

If that is of interest I also have an article on the Arduino Project Hub. Let me know and I can send the link.

Sorry I cant be any more specific and definitive on this occasion.

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@ronbentley1 Thanks Ron,  know about your library, but I am building a real time system and need very lean code. I have the button code now using an ISR and need to start a timer on activation. I have found the ESP32 info, but all new so still learning. For some reason when I try to set up critical sections with a Mutex, the code doesn't work. No idea why. Next step is to figure out how to pass compiler switches to the IDE so I can produce assembly listings and see what is happening. 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 

@zander

Can you tell me a real quick hdw debounce trick, I thought I read a small cap across the contacts was all that was needed.

That seems a workable solution.  With the Arduino I just rely on a software solution.

I remember using this in some purely hardware electronics.

To enlarge image right click image and choose Open link in new image.

NandGateDebounce

 


   
Inst-Tech reacted
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 2 years ago
Posts: 385
Topic starter  

@robotbuilder 

Oh yes, yuk, that's why I prefer software! That way I can tune the denounce period to each particular implementation and depending on quality of the switches

Still, whatever floats your boat!

Thanks for the addition to the post, I will know where to look if I ever want to implement a hardware solution.

 

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
ReplyQuote
(@yurkshirelad)
Member
Joined: 3 years ago
Posts: 493
 

What about using a 555 timer in monostable mode to debounce a button? I haven't tried it myself but I remember reading an article or watching a video on it.


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@ronbentley1 The problem is I am building a time critical application, the button press code is inside an interrupt service routine. You can't be looping to let a switch settle down, the solution must be hardware, sorry if I wasn't clear about that.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
YurkshireLad reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@yurkshirelad Seems like overkill. If I go with PULLUP then a simple RC setup on the pin will stop the noise, I just don't like inverted logic but may have to give in on this one.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
YurkshireLad reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@robotbuilder Can't use software, it's in a critical section inside an ISR. Your diagram looks more complicated than what I can deal with at the moment, and most likely don't have parts since I don't know what some of them are. What are the two unlabelled devices, transistors?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
YurkshireLad reacted
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 2 years ago
Posts: 385
Topic starter  

@zander 

Ron, 

No, you are correct, you cannot afford to debounce inside an interrupt but you can generate an interrupt after the switch handler has finished debouncing.

My ez_switch_lib library has a unique feature that allows you to link a switch to a nominated output pin. This pin can be an external interrupt pin which will be triggered by the switch once debounce is complete. You dont even have anything connected to the nominated switch and any number of switches may be linked to the same nominated pin.

Basically you define/set up your switch(es) and then link to an external output pin.

Inside the interrupt you are then able to determine which switch triggered the interrupt and do whatever processing you need to do.

Here is my Arduino Project Hub article for you to mull over.

It might give you food for thought.

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 
Posted by: @zander

What are the two unlabelled devices, transistors?

NAND gates.

Anything seems possible when you don't know what you're talking about.


   
Inst-Tech reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 

@zander

What are the two unlabelled devices, transistors?

 

As @will says, NAND gates, that perform logic,

https://en.wikipedia.org/wiki/NAND_gate

You can build your own computer out of such logic gates.
They are the physical means by which a software statement like,
IF X and Y then Z
is executed.

Here is an example I wrote to simulate a full adder. It uses NOR gates.

To enlarge image right click image and choose open link in new window.

fullAdder

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7021
 

@ronbentley1 I think we are talking about two different things. I do not plan on any kind of polling, there may not even be a main loop if I can avoid it. My system is interrupt driven, one of the things generating the interrupts is a mechanical switch. Anytime there is a hardware solution that is the best solution in most cases. 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 2 / 4