Isaac, port change interrupt is like once after key is pressed. the only time it c= reates more interrupt when bounces. I can put caps but what value do you suggest? thanks Andre ________________________________ From: Isaac Marino Bavaresco To: Microcontroller discussion list - Public. Sent: Thursday, October 6, 2011 11:22 AM Subject: Re: [PIC]: keypad debounce issue I don't like to use interrupts for key scanning exactly because of bouncing. It would be safe only if you put some (electronic) low pass filtering in the lines. It is much simpler to use a timer interrupt to scan the keypad periodically, and if your scan rate is appropriate you don't need any debouncing at all. I usually scan 20 times per second. It uses minimal CPU time and is fast enough even for very fast typing. Remember that if you use interrupts, the interrupt rate may be several kHz for some ms. That's a lot of processing and interrupt servicing. I often use a software prescaler in my system tick's interrupt to call the scanning routine at an appropriate rate. Best regards, Isaac Em 6/10/2011 14:57, Andre Abelian escreveu: > Hi all, > > I am reading a keypad that is connected to other board. I am using PIC24F= J256GB110 > with CCS PICC compiler. I am using CNI interrupt "port on change" and con= netced to all 4 rows. > any time any row goes low it create interrupt but also when it goes high = creates interrupt too. > the problem I am having is that I am getting duplicated key "debounce iss= ue". Normally > I used a counter to deal with debouning or adding a delay. Since CNI inte= rrupt is not looping > is like one time shot unless there is a port change using a counter is no= t working. I also have option > using columns but this will create interrupt every 1.5 ms none stop. usin= g rows will create interupt > only when keys are pushed. > > any idea? or suggestions will appreciate > here is the code. > > > // Keypad layout: > char const KEYS[4][4] =3D > {{'1','2','3','A'}, > {'4','5','6','B'}, > {'7','8','9','C'}, > {'*','0','#','D'}}; > > // check all rows and return 1 when pushed else return 0 > int1 ALL_ROWS(void) > { > if((input(row0)) & (input(row1)) & (input(row2)) & (input(row3))) // if = any of them pushed return 1 > { > return (0); > } > else > { > return (1); > } > } > > > > > // read keypad but from other board. keypad is connected to other PCB > #int_cni //level=3D7 > void keypad_interrupt() > { > //int32 prg_counter=3D0,data_prg=3D0,read_index_counter[3]; // all = this is for other routine that is removed for now > restart_wdt(); > > delay_ms(5); // for debounce purpose > > if((ALL_ROWS())&&(system_keypad_send_once =3D=3D 1)) // any of 4 = inputs are pressed? row0 & row1 & row2 & row3 > { > redled_on; > // col0 1,4,7,* > if((!input(row0))&&(!input(col0))) > { > row=3D0; col=3D0; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > if((!input(row1))&&(!input(col0))) > { > row=3D1; col=3D0; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > if((!input(row2))&&(!input(col0))) > { > row=3D2; col=3D0; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > if((!input(row3))&&(!input(col0))) > { > row=3D3; col=3D0; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > > // col1 2,5,8,0 > if((!input(row0))&&(!input(col1))) > { > row=3D0; col=3D1; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > if((!input(row1))&&(!input(col1))) > { > row=3D1; col=3D1; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > if((!input(row2))&&(!input(col1))) > { > row=3D2; col=3D1; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > if((!input(row3))&&(!input(col1))) > { > row=3D3; col=3D1; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > // col2 3,6,9,# > if((!input(row0))&&(!input(col2))) > { > row=3D0; col=3D2; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > if((!input(row1))&&(!input(col2))) > { > row=3D1; col=3D2; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > if((!input(row2))&&(!input(col2))) > { > row=3D2; col=3D2; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > > if((!input(row3))&&(!input(col2))) > { > row=3D3; col=3D2; > kbd_down =3D true; > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } > fprintf(ZBEE,"%c", key_pressed); // print for test normally= not used > > } > else > { > redled_off; > kbd_down =3D false; // > system_keypad_send_once =3D 1; > } > > > thanks > > Andre -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .