CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

idea for scan button

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
net_hw



Joined: 17 Oct 2012
Posts: 6

View user's profile Send private message

idea for scan button
PostPosted: Sun Dec 02, 2012 10:18 pm     Reply with quote

Hello All

I have a working code
that is using PIC 16F628, 6 capacitive input buttons
and its 6 correponding Outputs.
Everything is perfectly working
however I have a behavior that I would like to modify.

The system works as an auto repeat when the finger is left too long on the sensor.

6 sensors are sequentially scanned and in high speed
simulate a "mult tasking ".

I need to implement a code that prevent this behavior but without interfering with the scan of the other buttons.

This behavior is common to any press buttons scan
however I can post the code if someone believes to be necessary.

Thanks

Manoel
_________________
[]´s
hw
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Mon Dec 03, 2012 2:02 am     Reply with quote

OK.
The capacitive touchpad systems are always 'self repeating'.
The way to handle this is to have your own timer, and if a key is 'seen' without having been 'released' for a period (say 1/4 second), then ignore the key.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Dec 03, 2012 9:06 am     Reply with quote

A fail safe way to get only ONE press is to use a very VERY simple state machine code such that a very SHORT minimum delta -Time
is required to ACK the pressed state - and then activate on release ONLY.
(however long that might take)

I have used this logic on a portable MIL related gadget, and even though a bit unusual, BUT because of how the gadget is meant to be used, it was A-OK with the client. ( an ARMED led is lit on the press down, and the device operates single shot when released ).

This is very simple code to write.
net_hw



Joined: 17 Oct 2012
Posts: 6

View user's profile Send private message

PostPosted: Tue Dec 04, 2012 6:25 pm     Reply with quote

Okay,
Ttelmah thanks
I intuitively imagine that could be so
please you could cite some example for I try to join with my code?
----
asmboy also thank you, I understand your sugestion also should work fine, however I believe it would be more difficult to implement in conjunction with the capsense code that I'm using.

tks
_________________
[]´s
hw
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Dec 04, 2012 7:40 pm     Reply with quote

to have us look at and maybe tweak your code

you need to post your code complete enough
that we can compile- and tell us your compiler version number while you are at it , ok??
net_hw



Joined: 17 Oct 2012
Posts: 6

View user's profile Send private message

PostPosted: Fri Feb 08, 2013 6:00 pm     Reply with quote

Hello everyone on behalf of other chores
I needed freeze this project for a while
he was living with the running problem

I have not been able to add the code that prevents
By repeating finger pressed long
although I know what do have make use TRM0 to measure the time of finger pressure while continuing
for the scanning of 6 keys is not by any pause

as requested follows a simplification of my code

I use a code Capsense that I collected from the internet and this works fine
I use 16F628 that already have at hand
intend buy larger PICs like 16F1937 with mTouch modules
in future for produce new modules.
but I think that this problem should persist
until I get the code that does the proposed

I am very grateful for any help


Code:
#include <16f628.h>
#fuses INTRC_IO, NOLVP, NOWDT, PUT
#use delay (clock=4000000)

int8 pin_table[6] = {PIN_A2,PIN_A3,PIN_B0,PIN_B1,PIN_B2,PIN_B3};
int8 leds[6]={PIN_A1,PIN_A0,PIN_B7,PIN_B6,PIN_B5,PIN_B4};

int freqcapsense(int8 pinn){

int8 ccs_pin;

ccs_pin = pin_table[pinn];
    unsigned int avg;
    unsigned int current=0;
    unsigned int thresh=29;
    unsigned int trials=10;

    while(trials>0){
     output_high(ccs_pin);
     delay_us(1);
     while(input(ccs_pin)){current++;}
     trials--;
     avg=(avg+current)/2;
    }
    if((current-avg)>thresh){return 1;}else{return 0;}}


void reter(int8 pinn){
int8 ccs_pin;

ccs_pin = leds[pinn];

        output_toggle(ccs_pin);
        //Beep();
   }
void main (){

while (1){

int8 pX; 
for(pX=0;pX<6;pX++) {

if( freqcapsense(pX)){reter(pX);}
}
}}

_________________
[]´s
hw
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

View user's profile Send private message Send e-mail Visit poster's website

Controlling repeating keypress
PostPosted: Sun Feb 10, 2013 12:28 pm     Reply with quote

Hi,

The way I usually control key repeat features is to use a counter for each key. This counter gets reset to 0 when the key is not pressed. Every time the key is scanned and pressed is TRUE, the counter increments. To avoid repeating, ignore the key if counter is greater then 1. I also use it for a slow repeating initially, for example repeat every 100 scans and then faster repeating every 25 scans by using modulus operator.

Just one approach that should be easy to insert into any code.

Cheers, Jurgen

------------------------------------
www.jgscraft.com
net_hw



Joined: 17 Oct 2012
Posts: 6

View user's profile Send private message

Re: Controlling repeating keypress
PostPosted: Sun Feb 10, 2013 4:30 pm     Reply with quote

hello, jgschmidt
thanks for your reply
a example would be better to understand your explanation
but I imagine it's something similar that I did yesterday

I get the code from this page
http://pcbheaven.com/picpages/A_Clever_Button/
and port asm code to CCS
and
put together my main routine
after replacing input() by the function Capsense()
it worked in the simulator
however I'm still not satisfied cos
is a blocking code
when CheckForLongClick happens, the scan stops
until the end of the function,
but already this works better than before
but I think that using one of TRMs or all of them
would be better
however still need help for this
thanks
_________________
[]´s
hw
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group