Тёмный
No video :(

13. Arduino for Production! AVR Atmega32 - Understanding Button Debouncing 

BuildYourCNC
Подписаться 101 тыс.
Просмотров 91 тыс.
50% 1

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 72   
@maisonheidi
@maisonheidi 6 лет назад
The best Videos on the www i`v ever see for how to learn programming a AVR . Respect and verry thanks how to getting started with all the diverence of Programms like WINAvr or Atmel Studio too. I learn alot thank you for doing videos like this !
@PatrickHoodDaniel
@PatrickHoodDaniel 6 лет назад
You're welcome!!
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
Thanks. It may be set to zero by default, but this is really just a good practice to make sure that it is really set at zero. When the program becomes larger and more complex, this practice may save you time. For example, if the DDRB commands get used in its own function, there may be other functions or places that set this bit to 1, and finding that error would be time consuming.
@PatrickHoodDaniel
@PatrickHoodDaniel 11 лет назад
Just ordered a sample. I will make a tutorial when the sample arrives.
@kithinjimuriungi8811
@kithinjimuriungi8811 8 лет назад
I officially declare you the best :-D
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
Thanks. You can't set a pin high or low if it is set as input. The state of an input pin in changed by some device outside of the chip.
@aalavandhaann
@aalavandhaann 12 лет назад
Thank you anajonesr for the clarification. Your tutorial rocks....
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
@somebody301 the PC versions are actually less expensive than what I bought and have better features. The Owon that I purchased was around $400.
@jalaluddinrumi4889
@jalaluddinrumi4889 6 лет назад
U are awesome.U should have different color of wire.Upload a diagram
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
@somebody301 Good tip. Another good investment is a logic analyzer. I actually have one of those and it's great to see if serial communication is actually happening. They usually come with many leads to probe multiple legs. I may get into that in the uart tutorial. A good project may even to create one from scratch and show the result on the LCD. Hmm!!
@Omar.bin.khattab
@Omar.bin.khattab 2 года назад
thanks so much for your effort and time ..........
@PatrickHoodDaniel
@PatrickHoodDaniel 2 года назад
My pleasure!
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
@somebody301 I'm using a cheap Owon oscilloscope. I hear that PC scopes are a great alternative.
@aalavandhaann
@aalavandhaann 12 лет назад
Thanks a lot guru I understand now. I will follow as my guru says.
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
@somebody301 Yeah, I wouldn't invest in anything until you see a need for it. Even an oscilloscope is handy but not an absolute necessity.
@imon4mRUET
@imon4mRUET 2 года назад
Thanks brother.
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
@somebody301 I don't use a wave generator... yet!
@Anonymous-to3jj
@Anonymous-to3jj 10 лет назад
Ok.... I'm lost I can't find the project where you created the starting code file. So I'm lost on the following lines of code. DDRB |= 1
@beepsntones
@beepsntones 10 лет назад
I have thought of the NI national instrument that might required me to buy their extra boards for inputs and output for data transfer..
@m4unot
@m4unot 11 лет назад
i just realzed that you are using the 2 pins button which is most logical, but keep the good work
@Kalec1994
@Kalec1994 5 лет назад
best of the best
@pravineeshkrishna9709
@pravineeshkrishna9709 2 года назад
while (1) { if (bit_is_clear(PINB,1)) { PORTB ^= 0x05; // pin0 and pin2 toggle } } Is this correct? The code works fine for me. In this case, we don't need to use the variable pressed.
@ns5253
@ns5253 12 лет назад
@anajonesr In the statement - PORTB |= 1
@PatrickHoodDaniel
@PatrickHoodDaniel 11 лет назад
Thanks.
@ShaunDobbie
@ShaunDobbie 11 лет назад
I end up with one LED being dim and the green one switching off when I press the button.
@badyammar2289
@badyammar2289 7 лет назад
Thank you so much.. Amazing explanation Would you please add numbers to the names of the videos in the playlist so the one can remember where did he arrived
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
Bady Graphics that's a good idea. I will do that.
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
Done
@badyammar2289
@badyammar2289 7 лет назад
A big thank you 🌷
@n3crokun
@n3crokun 10 лет назад
I am having trouble understanding how the 2nd if() statement comes into play.I realize that its used to prevent continuous toggling by making sure the button was released first before toggling.But if i were to follow the code systematically im having a hard time visualizing how this is done. So if i were to start the program and the button has not been pressed, it will fall into the else{} where var "Pressed" will be assigned to 0. But if we now press the button, it will now satisfy the first if() condition and thus fall into that bracket . it will now check the condition for the 2nd if() statement which should be true since var "Pressed" was assigned to 0 on the else{} earlier. Therefore now the toggling of the 2 leds occur. This is the part where im having trouble with as I don’t see how the button needs to be released ,since as soon as we press the button both if() conditions are satisfied and the toggling should occur immediately as opposed to waiting for the button to be released before toggling. But the code does seem to work as ive tried it, but i just cant grasp how the waiting for release is done.
@m4unot
@m4unot 11 лет назад
It would be Nice if you can show how to use AT42QT1012 as touch button, becouse AT42QT1012 is made with the ability to toggle in touch mode
@aalavandhaann
@aalavandhaann 12 лет назад
Anajonesr, I have a question. By default the DDRB of all the pins will be 0bit right? Then why do we have to explicitly set the Pin1(switch) to 0bit when it is already 0bit? BTW your videos are great and anybody who has not seen it is not blessed.
@cristapia6833
@cristapia6833 7 лет назад
What is the size of the capacitor between VCC and GND (power to the uC)?
@ParkourNerd
@ParkourNerd 11 лет назад
I'm pretty sure some of the code if wrong. it should be 1. Pressed_Confidence_Level ++; Released_Confidence_Level = 0; 2. Released_Confidence_Level = 0; if inside the if 3. if (Released_Confidence_Level > 500) needs a closing brace.
@thejking
@thejking 12 лет назад
noob question here. Can i use any micro controller with the programming language that you are using? (with a different programmer) and if i'm right the micro controller is enough of a resistor to not short the circuit right? since you connected the button to ground.
@MrAlexthemachine
@MrAlexthemachine 12 лет назад
Okay I have a quick question. Wouldn't a rectifier diode work better for dealing with the reverse voltage caused by a switch?
@beepsntones
@beepsntones 10 лет назад
also what do you recommend if I need to use video recognition any kits out there which works with atmel? thanks
@m4unot
@m4unot 11 лет назад
Hi Patrick, are you using 2 or 4 pin button, what the value of the capacitor are you using? and you can actually use true and false if you include the header stdbool.h which is part of the standard C library.
@harshitagarwal5188
@harshitagarwal5188 9 лет назад
how does capacitor remove switch debouncing ?
@sksahil4374
@sksahil4374 6 лет назад
Thanks you sir
@nazatkabir3442
@nazatkabir3442 7 лет назад
I have made a program for a CLICK project just like you but the problem is not about debounce in my case.After uploading this program the led keeps blinking very fast can you point out the problem is in this program?? #include #include int b=2; int main(void) { DDRA=0x00; DDRC=0xFF; while (1) { int c=b/2; int a = PINA; _delay_ms(10); int a1 = PINA; _delay_ms(10); if(a!=a1){ b+=1; } if(c%2==0){ PORTC=0xFF; } else if(c%2==1){ PORTC=0x00; } } } in this program i have made PORTC to be output for the LED. I have used ATMEL STUDIO`s GCC C but that should not matter.
@beepsntones
@beepsntones 10 лет назад
what would happen if you had put a delay in the prob meaning if the switch is pressed wait 10ms then switch/toggle. would that also solve the problem? back in the day we had used assembly language that seemed to work that was only 8bit and much smaller micro controller . thanks in advance
@PatrickHoodDaniel
@PatrickHoodDaniel 10 лет назад
Delays will work and many folks do this but I like to keep delays out of the code. It's best to treat programming in microcontrollers like state machines where the clock cycles are there if you need it.
@nazatkabir3442
@nazatkabir3442 7 лет назад
sorry i have made a mistake in coments of the program A was set as INPUT and C was set as OUTPUT
@arinjoyhere
@arinjoyhere 6 лет назад
Hey..pattrick greetings...may I know why both pins pinb0 and pinb1 are initially zero
@PatrickHoodDaniel
@PatrickHoodDaniel 6 лет назад
If no pin is set high or low, it will default to low (0). However, it is important to set the pins that you are using to your desired level even though there is a default state. This is so you understand their intended state and you are not putting the pin in a tri-state (an input state that is not pulled high or low) condition where interference can cause undesirable results.
@arinjoyhere
@arinjoyhere 6 лет назад
Yeah,,I thought that should be that...thank you...got your confirmation... Salutations@patrick
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
@josepaul2000 Canon Rebel T1i.
@josepaul2000
@josepaul2000 12 лет назад
What camera are you using?
@mgcristi
@mgcristi 10 лет назад
A boolean doesn't use only 1 bit of memory ! Get it right :D. You can't allocate only 1 bit of memory.
@nazatkabir3442
@nazatkabir3442 7 лет назад
yes
@thanhphongphan
@thanhphongphan 7 лет назад
Amazing tutorials sir! I have a question. I tried writing my code like this: if (bit_is_clear(PINB, 1) && (Pressed == 0)) {...} but it didn't toggle when I pressed the button (1 LED keeps turning on and the other keeps flashing every time I pressed) I changed my code to be like yours and separate 2 conditions then it works as expected. Can you explain what is the problem with using && operator here? Thank you! Looking forward for your answer!
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
Thanks for the kind words. Looks like you may be missing a closing parenthesis. if (bit_is_clear(PINB, 1)*)* && (Pressed == 0)) Does it work by nesting them? That may answer your question.
@thanhphongphan
@thanhphongphan 7 лет назад
Sir, I don't think I've missed any closing parenthesis. This is my conditional statement when it didn't work if ( bit_is_clear(PINB, 1) && (Pressed == 0) ) { PORTB ^= (1
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
Yes, you are right. Sorry about that. Separating the condition into a nested condition worked. Not sure the && doesn't work. I typically use that logic statement in my C# code, but I don't recollect using it in C.
@thanhphongphan
@thanhphongphan 7 лет назад
Thank you for your answers. I guess I'll just stick to the nested if statement for the moment ;)
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
You're welcome. Not sure how helpful I was, however. Let me know if you find a solution with the other option.
@Sonia_prc
@Sonia_prc 7 лет назад
can u please tell how did u put pinb2 as input?? I didn't get d way u made pinb2 input using bitwise operation..
@Sonia_prc
@Sonia_prc 7 лет назад
hope u'll solve this query..
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
You need to set the data direction register for that port and pin as input.
@Sonia_prc
@Sonia_prc 7 лет назад
Patrick Hood-Daniel ddrb&=~(1
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
You still want to set it even if it is already 0. It's a good practice because programs get longer and more complicated and you may not know what state that bit is all the time. I would suggest really looking at the program closely and test, test, test.
@Sonia_prc
@Sonia_prc 7 лет назад
Patrick Hood-Daniel thnxxxx.... I jst started my engineering... really loved d stuff u doing... keep posting tutorial lyk dis..
@nsutahmid
@nsutahmid 10 лет назад
I think u should start from the first video to understand @M.Wali M
@nazatkabir3442
@nazatkabir3442 7 лет назад
let me elaborate it with the program with comments #include #include int b=2; int main(void) { DDRA=0x00; //here i`ve set all the pins of PORTA as output DDRC=0xFF; /here i`ve set all the pins of PORTC as input while (1) { int c=b/2; // the value of b is going to be divided by tow for a further purpose int a = PINA; // first of all a is going to get a value _delay_ms(10); // in this delay the button will pressed or not pressed int a1 = PINA; //here i am getting the value to check if the button is pressed in the delay //in this part the if logic is going to work //and when i will take my finger off the button the b is going to increase with 1 value again //totally the increamention of b will be 2 // and with the (c=b/2) i am going to get a value of c increased 1 if(a!=a1){ b+=1; } //so on the first click c%2 will be 0 and an another click will make the value of c%2 to 1 // it is going to go on like this if(c%2==0){ PORTC=0xFF; // if the value of c%2 is 0 the LED will light up } else if(c%2==1){ PORTC=0x00; //if the value of c%2 is 1 the LED will turn off } } } AND I hope that the program should have worked just fine
@PatrickHoodDaniel
@PatrickHoodDaniel 7 лет назад
Hi Nazat, I am unfortunately not able to investigate code for others, which is why I make tutorials. the best way to learn how to code embedded applications is to dig deep and trudge through. I am generally focused on making new tutorials and investigating others code would take time out of creating new tutorials.
@nazatkabir3442
@nazatkabir3442 7 лет назад
okii
@PatrickHoodDaniel
@PatrickHoodDaniel 12 лет назад
I would not consider myself a guru, but thanks anyway.
@m.mohammad4545
@m.mohammad4545 10 лет назад
i dont understand nothing
Далее
나랑 아빠가 아이스크림 먹을 때
00:15
Просмотров 3,2 млн
What is a Monad? - Computerphile
21:50
Просмотров 600 тыс.
The RS-232 protocol
26:10
Просмотров 834 тыс.