Capasitive Sensing
Moderator: Benj
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Capasitive Sensing
Hi Guys
This flowcode 6 looks great one question dose it have a capsitive sensing function
Brian
This flowcode 6 looks great one question dose it have a capsitive sensing function
Brian
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Capasitive Sensing
Hello,
It has the same ADC raw functions that we used in v5 to achieve cap touch.
No native cap touch support at the moment but as v6 is so flexible, going forward it is something that should be very easy to add. Is there a specific device your interested in?
It has the same ADC raw functions that we used in v5 to achieve cap touch.
No native cap touch support at the moment but as v6 is so flexible, going forward it is something that should be very easy to add. Is there a specific device your interested in?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Capasitive Sensing
Hi Benj
Yes I've been looking at the PIC16LF1939 this has 16 cap sensitive pins
Brian
Yes I've been looking at the PIC16LF1939 this has 16 cap sensitive pins
Brian
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Re: Capasitive Sensing
A while back I did several experiments with the Capacitive Sensing Module. It worked great but the current draw was more than I expected so I abandoned it since my application used a CR2032 battery. I am not sure if the code is wrong or just that my expected current draw calculation was in error. The attached flowchart is just for a single sensor but I have done multiple sensors using an interrupt to switch the sensor input. It is written for the PIC16LF1827 but it should work with the PIC16F1939. You will have to edit the code to reflect the port#'s on the 16F1939. Try changing trisa.3=1;
ansela.3=1; to trisb.3=1; anselb.3=1; and the sensor would then be on RB3 instead of RA3. Don't forget to set wdt controlled by SWDTEN in the configuration. There is also a nice guide for this module at:
http://electronics-base.com/index.php/f ... controller
That author uses it slightly differently than me and I have not tried it that way. There are many settings to chose from depending on your application. Benj's method seems to be the best alternative since it uses the ADC module which most PIC's have and the component already exits.
ansela.3=1; to trisb.3=1; anselb.3=1; and the sensor would then be on RB3 instead of RA3. Don't forget to set wdt controlled by SWDTEN in the configuration. There is also a nice guide for this module at:
http://electronics-base.com/index.php/f ... controller
That author uses it slightly differently than me and I have not tried it that way. There are many settings to chose from depending on your application. Benj's method seems to be the best alternative since it uses the ADC module which most PIC's have and the component already exits.
- Attachments
-
- CapSense_LowPower.fcf
- (7 KiB) Downloaded 388 times
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Capasitive Sensing
Hi Kenrix2 / Benj
Thanks for your help i have tried to expand this to 10 keys but not sure how to i will eventually need 12 keys I have no clue how to program in C and have also looked at the data sheet which dose not make to much sense to me can you check this code and see if I'm on the right track.
Brian
Thanks for your help i have tried to expand this to 10 keys but not sure how to i will eventually need 12 keys I have no clue how to program in C and have also looked at the data sheet which dose not make to much sense to me can you check this code and see if I'm on the right track.
Brian
- Attachments
-
- CapSense_LowPower1.fcf
- (55.69 KiB) Downloaded 345 times
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Re: Capasitive Sensing
I don't know how to program in C either but I do it anyhow. I wish I could find a good book on it. Once you learn a little bit about C the data sheet will make much more sense. I did an experiment once using the Capacitive Sensing Module(cps) with 4 sensors. The flowchart is attached. The concept is the cps produces pulses into the timer1. The number in the timer1 registers keeps increasing over time. The number in the registers are read at precise intervals. When you are not touching the sensor you get a higher number than if you are touching it. I just make a calculation: if the number is less than 85% of the no touch number then a port pin goes high. Timer0 is used to create the precise interval using the interrupt. At each interrupt a different cps pin is connected to timer1. For a user to have a felling of good response each pin is checked every 1/15 of a second. Slower than 1/10 of a second may seem sluggish. Since the flowchart is made for the PIC16F1827 and your using the PIC16F1639 you will have to make a change since CPS0-CPS3 are on portb instead of porta. Find and change trisa=trisa & 0b00001111; ansela=ansela & 0b00001111; to trisb=trisb & 0b00001111; anselb=anselb & 0b00001111;
Good luck with it and maybe with a little tinkering you can adapt it to 12 sensors.
Good luck with it and maybe with a little tinkering you can adapt it to 12 sensors.
- Attachments
-
- CapSense.fcf
- (9.68 KiB) Downloaded 374 times
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Capasitive Sensing
Hi Kenrix2
I sort of see what is happening here, what I'm trying to do is expand to 12 keys, am i correct with the code below which I'm trying to turn on CPS0 to CPS5 on port B then CPS6 & 7 on port A and CPS8 to 12 on port D
trisa=trisa & 0b00110000;//**Turn on CPS6 & CPS7 **
ansela=ansela & 0b00110000;
trisb=trisb & 0b00111111;//** Turn on CPS0 to CPS5**
anselb=anselb & 0b00111111;
trisd=trisd & 0b00001111;//** Turn on CPS8 To CPS12**
anseld=anseld & 0b00001111;
t1con=0b11000001;//** Bit Two probably should be set, need to retest with it set **
cpscon0=0b10001110;
tmr0=0x00;
tmr1l=0x00;
tmr1h=0x00;
one other thing you have this instruction at the bottom of the int macro { cpscon1=FCV_PORT; } how dose change the port
Brian
I sort of see what is happening here, what I'm trying to do is expand to 12 keys, am i correct with the code below which I'm trying to turn on CPS0 to CPS5 on port B then CPS6 & 7 on port A and CPS8 to 12 on port D
trisa=trisa & 0b00110000;//**Turn on CPS6 & CPS7 **
ansela=ansela & 0b00110000;
trisb=trisb & 0b00111111;//** Turn on CPS0 to CPS5**
anselb=anselb & 0b00111111;
trisd=trisd & 0b00001111;//** Turn on CPS8 To CPS12**
anseld=anseld & 0b00001111;
t1con=0b11000001;//** Bit Two probably should be set, need to retest with it set **
cpscon0=0b10001110;
tmr0=0x00;
tmr1l=0x00;
tmr1h=0x00;
one other thing you have this instruction at the bottom of the int macro { cpscon1=FCV_PORT; } how dose change the port
Brian
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Re: Capasitive Sensing
I probably should have named the variable "port" as "select_cps_input" to make it clearer. Sometimes making sense of other people's code is hard to do especially if it is not commented well which I am usually guilty of. I think what needs to be done is to make a custom component for this when V6 comes out. There are a few variations depending on the IC used along with different power modes used in this module. Calibration should probably be periodically updated to account for small changes in the environment. I did not spend much time writing this code, I was just curious how it would work. Since then Benj came out with an ADC touch version so, for now, that is the probably the best way to go.
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Capasitive Sensing
Hi guys
Can any one help i modified this program slightly and changed the variable name from port to select_cps_input now it wont compile the error message is unknown identifier 'FCV_select_cps_input'. I really do not have a clue on how to program in C, am correct in saying this instruction starts with (FCV) (Flowcode Variable) then followed by the variable (select_cps_inpuit)
Brian
Can any one help i modified this program slightly and changed the variable name from port to select_cps_input now it wont compile the error message is unknown identifier 'FCV_select_cps_input'. I really do not have a clue on how to program in C, am correct in saying this instruction starts with (FCV) (Flowcode Variable) then followed by the variable (select_cps_inpuit)
Brian
- Attachments
-
- CapSense_12_button.fcf
- (28.56 KiB) Downloaded 346 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Capasitive Sensing
Hi Brian,
When assigning a register variable for example with a Flowcode variable e.g tmr0l = FCV_NAME_OF_VARIABLE;
Its important that the variable name is always in uppercase whether the actual variable created with project manager is in uppercase or not!
For example you create a variable called select_cps_input or Select_Cps_Input then within C you must use:
cpscon1=FCV_SELECT_CPS_INPUT;
As you can see the register e.g tmr0l or cpscon1 has to all be in lower case.
so if you alter your Code to reflect this change, your flowchart should compile OK.
Martin.
When assigning a register variable for example with a Flowcode variable e.g tmr0l = FCV_NAME_OF_VARIABLE;
Its important that the variable name is always in uppercase whether the actual variable created with project manager is in uppercase or not!
For example you create a variable called select_cps_input or Select_Cps_Input then within C you must use:
cpscon1=FCV_SELECT_CPS_INPUT;
As you can see the register e.g tmr0l or cpscon1 has to all be in lower case.
so if you alter your Code to reflect this change, your flowchart should compile OK.
Martin.
Martin
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Capasitive Sensing
Hi Martin
Thanks that helped a lot it works now to figure out how to do a switch debounce so it sends the relative number via uart only once while the key is pressed
Brian
Thanks that helped a lot it works now to figure out how to do a switch debounce so it sends the relative number via uart only once while the key is pressed
Brian