hello everybody, i am new in GCB (good software ) i would like to use debounce button with millis (30 ms debounce) , could you give some example or idea, thanks in advance
Last edit: Alex 2020-02-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Anobin, actually yes, i have used arduino with millis for debounce also ldmicro, i am not good at using interrupts or ticks, maybe some example with them i could give it a try
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You do not need to use millis() but you can if you really want to.
Use something like, assumming you have LED(via a suitable resistor) and a Switch.
#defineInputSwitchporta.1
#defineLEDporta.2dirInputSwitchindirLEDoutLED=OFFdoforeverifInputSwitch=Onthen'debounce using WAITwait10msifInputSwitch=ONthenLED=ONendifelseLED=OFFendifloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks for your reply, i have read in documentation that "wait" "cause the program to wait for either a specified amount of time..." i think it is like "delay" in arduino, but the reason i started to use millis is that i couldn´t make a multitask program using delay , i think i will not be able to make a multitask program using "wait"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the mulstitask is for a conveyor that counts every object that touches a limit switch, conveyor doesn´t have sensor just switch, when the limit switch counts an object also activates a servo motor arm that pulls the object out of the conveyor into a box also when the servo is working a green light is blinking every 1 second, i was thinking working with the limit switch counter first .
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have written a few games using gcb but never used debounce code for the button switches.
They are just tied high via 10K resistors and when pressed drag the port low and I check if the port is off.
Is that unusual? It has not caused a problem so far.
edit, in the above application ie checking switches, the switches will be on and an object touching will set the switch low. One would only be testing for it to go low once then the next line , is it low then do something. By the time the program had looped to testing the switch again, it would be hi again.
edit again- yes , I can see how when the program checks the switch it could be bouncing and be hi when it was being pressed. Hmmmm, something I must consider in future.
An on interrupt by the switch would involve some sort of code or there would be lots of interrupts.
Last edit: stan cartwright 2020-02-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you need know the switch is down for a specific time? Then, store the millis() and compare when millis()+your_delay has elapsed and make sure the switch is still down. Is this what you need?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks for your reply, yes, i need to make sure that the button(limit switch) has been pressed (set ON)for 50 ms (time enoguh to avoid debounce) after that my microcontroller counts 1 object and repeat again(comes another object button is pressed, after 50ms another object is counted)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OK. You need to save the millis() at the first event, and, then do other stuff, and then check the first event+10ms has happened then check again that is switch is still down.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i am counting every objet that a limit switch detects, i have read that mechanical switches bounce everytime they are pressed, for a small period of time, every bounce could be read by the microcontrollers, so, to avoid that you can use a software debounce,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I hope I'm not upsetting anyone by pokeing my nose in.
If the program is testing various switches sequencionally then there's a chance of testing a switch at the time it was activated but bouncing so giving a false result.
pressed =0:unpressed=0
do
if switch=0 then pressed++
else
unpressed++
end if
until pressed>unpressed
I am responding to millis alternative as in a previous post. Things one takes for granted like debounce.
I don't like my programs wasting time so a fast result is needed....but there's time to waste on some programs.
I just trying to make debounce routine and lots of syntax errors like
do
if var=x then
var2++
exit do
end if
loop
is that ok?
Last edit: stan cartwright 2020-02-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just as an alternate view. I always debounce in hardware that is I have a resistor (in series) and a capacitor (in parallel). If there is a problem with the long reset I set input pin to ouput and discharge the capacitor in the interrupt routine.
Last edit: David Stephenson 2020-02-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hello everybody, i am new in GCB (good software ) i would like to use debounce button with millis (30 ms debounce) , could you give some example or idea, thanks in advance
Last edit: Alex 2020-02-25
Hello Alex,
Are you coming from the Arduino usage to Great Cow BASIC? This is to give some context to your question.
Hello Anobin, actually yes, i have used arduino with millis for debounce also ldmicro, i am not good at using interrupts or ticks, maybe some example with them i could give it a try
I thought so.
You do not need to use millis() but you can if you really want to.
Use something like, assumming you have LED(via a suitable resistor) and a Switch.
thanks for your reply, i have read in documentation that "wait" "cause the program to wait for either a specified amount of time..." i think it is like "delay" in arduino, but the reason i started to use millis is that i couldn´t make a multitask program using delay , i think i will not be able to make a multitask program using "wait"
OK. Wait is none blocking. Interupts will still fire etc.
So, I get a better idea - what is the multitask program doing in the meanwhile.
Do you want to detect the switch is down (in some on or off state) for a specific period of time?
the mulstitask is for a conveyor that counts every object that touches a limit switch, conveyor doesn´t have sensor just switch, when the limit switch counts an object also activates a servo motor arm that pulls the object out of the conveyor into a box also when the servo is working a green light is blinking every 1 second, i was thinking working with the limit switch counter first .
I have written a few games using gcb but never used debounce code for the button switches.
They are just tied high via 10K resistors and when pressed drag the port low and I check if the port is off.
Is that unusual? It has not caused a problem so far.
edit, in the above application ie checking switches, the switches will be on and an object touching will set the switch low. One would only be testing for it to go low once then the next line , is it low then do something. By the time the program had looped to testing the switch again, it would be hi again.
edit again- yes , I can see how when the program checks the switch it could be bouncing and be hi when it was being pressed. Hmmmm, something I must consider in future.
An on interrupt by the switch would involve some sort of code or there would be lots of interrupts.
Last edit: stan cartwright 2020-02-25
@Alex. No really a debounce.
Do you need know the switch is down for a specific time? Then, store the millis() and compare when millis()+your_delay has elapsed and make sure the switch is still down. Is this what you need?
thanks for your reply, yes, i need to make sure that the button(limit switch) has been pressed (set ON)for 50 ms (time enoguh to avoid debounce) after that my microcontroller counts 1 object and repeat again(comes another object button is pressed, after 50ms another object is counted)
OK. You need to save the millis() at the first event, and, then do other stuff, and then check the first event+10ms has happened then check again that is switch is still down.
i think i can store 50ms like this:
Last edit: Alex 2020-02-25
Should work but you code is not checking the switch. :-)
thanks for your reply, that is where i get stuck
Could the 328p use on interrupt to set a var if the switch was pressed?
Then you would only need to test the var and reset it if true, not debounce.
thanks for your reply, could you give an example please for a counter?
https://sites.google.com/site/qeewiki/books/avr-guide/external-interrupts-on-the-atmega328
What are you counting? Time? Number of times the switch is low (or high).
I recommend you flesh out the process else this will be coding by guessing (by us)
i am counting every objet that a limit switch detects, i have read that mechanical switches bounce everytime they are pressed, for a small period of time, every bounce could be read by the microcontrollers, so, to avoid that you can use a software debounce,
I hope I'm not upsetting anyone by pokeing my nose in.
If the program is testing various switches sequencionally then there's a chance of testing a switch at the time it was activated but bouncing so giving a false result.
pressed =0:unpressed=0
do
if switch=0 then pressed++
else
unpressed++
end if
until pressed>unpressed
I am responding to millis alternative as in a previous post. Things one takes for granted like debounce.
I don't like my programs wasting time so a fast result is needed....but there's time to waste on some programs.
I just trying to make debounce routine and lots of syntax errors like
do
if var=x then
var2++
exit do
end if
loop
is that ok?
Last edit: stan cartwright 2020-02-26
Just as an alternate view. I always debounce in hardware that is I have a resistor (in series) and a capacitor (in parallel). If there is a problem with the long reset I set input pin to ouput and discharge the capacitor in the interrupt routine.
Last edit: David Stephenson 2020-02-27
great idea i could test that, thanks a lot
Like this?
Does it stress the cap or switch?
thanks, all for your reply i´ll try
https://www.google.co.uk/search?hs=XH5&sxsrf=ALeKk02vifZl6-KYp3bJn_eSMNAFDMrCJA:1582823242459&q=hardware+switch+debounce+circuit&tbm=isch&source=univ&client=opera&sa=X&ved=2ahUKEwidhe-InPLnAhXMbMAKHfUFAsIQsAR6BAgCEAE&biw=1326&bih=696