No capactive sensing (CPS) module in FC 5

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by jgu1 »

Hi Ben!

As I play around with your example, I understand better and better how it works. I can also see the possibilities. Of course, I could just have used the examples from PCB haeven but I don´t understand C and Assambler and it is better when I have the opportunity to implement it in FC and further in a project, and certainly it will be. Again, thank you Ben. :D

Greetings

Jorgen

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Benj wrote:Here is a picture of the prototype E-block.
CapTouch_Eblock.jpg
Hi I am following this thread with great interest.
I almost gave up on Capacitive touch.

How does this module work?
Is it just a Ground plane at the bottom of the board, and some copper areas on the top of the board?
I am thinking of making such a button for my next camping light. How would you use the board. What cover so that it will still work?
Just a Label or paint?

An interesting thing that I read on the Microchip website is that you can even use a metal cover.
That sounds very cool how would one do this? Could you simply stick a thin peace of metal on an aluminium front panel with epoxy glue, connect the front panel to GND and connect the plate you stick on the back to the Capacitive sense channel?

Best Regards:
Uli

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi
I Just found the answers to all my questions in the Microchip website.
Sorry for not doing that before my last post.

http://ww1.microchip.com/downloads/en/A ... 01102a.pdf
http://ww1.microchip.com/downloads/en/A ... 01325A.pdf

As I can see from the Application not a Metal over cap sensor is not an easy to make at home since you need to find the right thikness of metal, and also the right spacer.

But the normal Capacitive touch sensor described on the first link looks quite easy. And it can look good too. If you print a nice Paper label and put it between the pcboard and the perspex.
However it would not be too good for a camping equipment, what if the paper gets some moisture? It will not look good anymore.
Could a plastic label also work?
Best Regards:
Uli

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi
Now that I figured out how to make a capacitive switch I want to start playing around with it.
Question can I still use the other ADC channels for reading voltages?
Also How would I choose different channels to read them?
I do not fully understand the C code part (adcon0 = 0x01;) etc.

Best Regards:
Uli

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi
I am trying to use the following file: CapTouch_pressure.fcf

What I am trying to do is to copy this code into an existing program.
I use the copy and paste functions and create the variables that are needed.
However in the sample code I can not see the variables .sum .channel .state etc.
I do not know If I have to create them myself or not. I tried to but flowcode does not allow a variable name with a dot in front.
Could you help me get an understanding of the meaning of a variable with a dot in front of it?
Can I replace them with any name I want to or is there something special about them?

Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Enamul »

I do not know If I have to create them myself or not.
If you copy a part of program to other program...variables are not copied with them, you have to declare the variables to make the code in act.
I tried to but flowcode does not allow a variable name with a dot in front.
variable that has dot in front actually local variable which means the variable only usable to a particular macro. If you are inside any macro and go to variable declaration window and on the right side of the window you will see different option...Ports,Globals,macroname(here you will see variable; if you declare variable here it will be local variable and that can be used as dot in that macro...not need to declare by dot), Macro, Numeric, Textual.
Can I replace them with any name I want to or is there something special about them?
If you want to replace the local variable with different name you can but you have to change in code..you can also use global variable sometime in place of local variable.
Enamul
University of Nottingham
enamul4mm@gmail.com

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi Enamul.
Thanks for the Info.
I do not understand why it does not show locals on the Project explorer.
I actually had to create them from within a calculation.
How do you get the variable .Return
between Sample_Cap_Touch and Parameters?

I see the Sample_Cap_Touch Macro ends with leaving a value in the variable .Return
The main program uses the variable State.
How does it get a value state from return?

Best Regards:
Uli

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Enamul »

I do not understand why it does not show locals on the Project explorer.
Yes, you are right. That's not available in project explorer.
How do you get the variable .Return between Sample_Cap_Touch and Parameters?
Return variable is something automatically defined if you declare return type non-void while macro is declaring. That is done by Ben when he made the code..But if you want to copy simple_cap_touch macro you can declare that in main macro and while creating the new macro you will see in the bottom of the window there is an option return type. If you select "No return type" you will not get ".Return" variable as local variable in the macro. But if you select BYTE/INT or any type you want..you will be able to use that in your macro.
I see the Sample_Cap_Touch Macro ends with leaving a value in the variable .Return. The main program uses the variable State.
You will see in the Sample_Cap_Touch macro..at the end. Ben uses .return and it gets some value. so when you call "Sample_Cap_Touch" macro from main function you have to put some variable where Sample_Cap_Touch will return it's return value...in this case "State" is that variable.
How does it get a value state from return?
As I mentioned above the macro will return the return variable value to state variable and that is done in c code..you don't need to worry
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
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: No capactive sensing (CPS) module in FC 5

Post by Benj »

Hello,

You could potentially export the current macro from the example program and then import into your new program and this will bring across all the local variables including the return.

Please note I have found a bug in the ADC code in v5.5 which was introduced to make the DSP type RAW ADC readings more efficient. It is simple to fix so let me know if your using v5.5 and want to use this cap touch example.

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi
Thanks for all your advice.

I decided to use the original code and modified it a bit to suit my hardware.
Actually I made a pad with only two buttons.
I use the following pins

AN0 for pad one
AN1 for pad two
AN2 is where i put the pull up resistor from vss. Is this a problem? I see this pin is also for vref+

Also I see that the ADC channel is set to FOSC/2 is that not a bit fast? Or does it not matter for capacitive touch?

I am using Flowcode 5.5

I added one line to see the return value and the state value at the same time.
It alsways gives state 0 and return is alsways 255

Is the problem I have due to a bug in Flowcode 5.5 or is there something wrong wit connecting the 1K pull up resistor to AN2

Best Regards:
Uli
Attachments
CapTouch_pressureLCD.fcf
(18.1 KiB) Downloaded 314 times

User avatar
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: No capactive sensing (CPS) module in FC 5

Post by Benj »

Hi Uli,
AN2 is where i put the pull up resistor from vss. Is this a problem? I see this pin is also for vref+
I think this should work fine as long as the +VREF is not enabled. All you should have to do is change the ADC component connection to AN2.
Also I see that the ADC channel is set to FOSC/2 is that not a bit fast? Or does it not matter for capacitive touch?
This really needs to be based on your clock frequency. Using the RC conversion method was a bit too slow on my hardware and Fosc/2 was generating good results. Have a play around and see what setting provides you with the accuracy your after.
Is the problem I have due to a bug in Flowcode 5.5 or is there something wrong wit connecting the 1K pull up resistor to AN2
There is a specific bug for doing this in v5.5, as I say making the DSP stuff more optimized has broken my cap touch demo file.

To fix the bug have a look at the generated C code file and near the top it will tell you which ADC type your chip is using.

Go into the CAL and open the CAL_ADC file. You may have to copy the file out of the program files folder first to be able to edit it.

Find the ADC section for your device - has the same type number and then look for this line of code at the end of the Enable ADC function.

Should look something like this.

Code: Select all

adcon0 = adcon0 | 0x04;									//begin next conversion
Cut the line of code out so that the last line is the delay_us function.

Then paste the line of code into the Sample_ADC function just above the while line of code.

E.g. this code

Code: Select all

		*tris_reg = old_tris | tris_mask;
		adcon0 = (0x01 | (Conv_Speed << 6)) | (Channel << 3);	//turn ADC on
		delay_us(T_Charge);										//wait the acquisition time

		adcon0 = adcon0 | 0x04;									//begin next conversion
	}

	MX_UINT16 FC_CAL_Sample_ADC (MX_UINT8 Sample_Mode)
	{
		MX_UINT16 iRetVal;

		while (adcon0 & 0x04);
		if (Sample_Mode)
Changes to this code

Code: Select all

		*tris_reg = old_tris | tris_mask;
		adcon0 = (0x01 | (Conv_Speed << 6)) | (Channel << 3);	//turn ADC on
		delay_us(T_Charge);										//wait the acquisition time
	}

	MX_UINT16 FC_CAL_Sample_ADC (MX_UINT8 Sample_Mode)
	{
		MX_UINT16 iRetVal;

		adcon0 = adcon0 | 0x04;									//begin next conversion

		while (adcon0 & 0x04);
		if (Sample_Mode)
Or you can tell me which device your using and I will make the mod for you.

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi Benj
Thanks for your reply.
I got it all working now. :lol: :lol:
My Pic 16F1939 is running at 16MHZ and I get good results wit fosc / 8 to fosc / 64
With a paper on the pad I get quite big differences in return value in the region of hundreds when pressing it.
With a peace of perspex on top of it I only get a difference of two when pressing, is that still a good result?
Are there other things I can play around with to improve sensitivity when having a peace of perspex over it?


Does this bug in Flowcode 5.5 only affect Capacitive touch, or does it also affect Normal ADC reading.
If I want to read a normal ADC in addition to capacitive touch sensing do I first have to disable The ADC channel that is connected to the 1K resistor?

Best Regards:
Uli

User avatar
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: No capactive sensing (CPS) module in FC 5

Post by Benj »

Hi Uli,

The bug was just present in my Cap touch file as it is doing non standard things with the ADC component.

Glad you got it working well, not sure about going through perspex. You basically need to balance the capacitance that is currently there with the capacitance that is added by the user. Making the pads larger or smaller may help as may reducing or increasing the associated ground plane. Not sure of the actual rules so it's all a bit of a black art at the moment.

You should be able to use other ADC components in your program no problems. Just don't use at the same time as the cap touch macro i.e. in an interrupt macro.

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi Ben.
Thanks for your help.
The Ground plane is in a grid form, would it help to make the touch pad in a grid form as well.

The question I actually had on my mind is this could one change the macro to read ADC as Int?

The circuit is quite stable but with a difference value of only 2 could you get interference when temperature changes?
Or will the basic capacitance without a person touching always be the same?

Best Regards:
Uli

User avatar
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: No capactive sensing (CPS) module in FC 5

Post by Benj »

Hi Uli,

This doc seems to have some good info on pad design.

http://cache.freescale.com/files/sensor ... AN3863.pdf

To answer your question.
Do not use filled ground planes underneath electrodes area — In case a ground plane is needed, make sure it is not filled. If the plane underneath the electrode is completely (100%) filled, the total capacitive coupling from the ground plane is much higher than the one created by a finger, adding a large offset to the capacitive measurement. It makes the detection of a valid finger touch more difficult.
Yes you can change the ADC read type to int this should still work well.

Basic capacitance should always be roughly the same, humans add capacitance to the pad. Might have to take into account children pressing the system as the capacitance could be significantly smaller.

The Read as Int method should give you more resolution anyway.

Let me know how you get on.

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi Ben.
Thanks for your advice.
I just discovered the read as int Option in ADC raw channel before you answered my question.
I wonder why I did not see it before.
I am currently trying it out with some wires from a Pic 16F1939.
In this way I can have a display to see how everything is working. I also added a filter, so it will work on any pad without adjusting the values.
So far it is working well.
The test will come when I add the components to the board and move the Program to a Pic12F1822

I will let everyone know how it goes once I use the Program on real Hardware.

Can you actually make a Sensor without a ground plane. If there is an aluminum cover on the back side?

Best Regards:
Uli

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi.
I sucessfully used the program on a Pic12F1822.
It worked fine. But then I discovered that I used the Configuration for the Pic 16F1939.
So I changed it to the Configuration for the Pic 12F1822 and it did not work.
Then I remembered about the need for modification of the Cal_ADC
However the PIC12F1822 is nowhere mentioned in pic Cal_ADC.
Is there a bug with flowcode?
Or which ADC_Cal will I have to change so that it will work with a Pic 12F1822?
With the correct Configuration?

Best Regards:
Uli

medelec35
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: No capactive sensing (CPS) module in FC 5

Post by medelec35 »

Yes there is a typing error within PIC_CAL_ADC.c
If you look at the generated C file after compiling with ADC component, you will see:

Code: Select all

#define MX_ADC_TYPE_26
So just search PIC_CAL_ADC.c for:

Code: Select all

MX_ADC_TYPE_26
There you will see that the devices stated are:

Code: Select all

16F1822, 16F1823, 16F1824, 16F1825, 16F1828, 16F1829
So its 16F1822 instead of 12F1822.
That's the section you will need to edit.
All the others are correct.
How odd (and confusing) of Microchip to have 12F1822. then 16F1823 etc.

Martin
Martin

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi Martin.
I edited the file you mentioned, and now it is working perfectly.
It even works through 2mm perspex.
I love the capacitive touch, because I never found buttons and switches I really like.
Best Regards:
Uli.

medelec35
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: No capactive sensing (CPS) module in FC 5

Post by medelec35 »

Hi Uli,
Glad its working for you.

Your touch sensor sounds really good!
I'm going to have to make one myself :)

Thanks for letting us know.

Martin
Martin

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi
Just want to share some more.
For it to work I added a filter.
So I can use greater sensitivity.
I do not know if this is needed but It should do away with the need of adjustment for each pad when reading through perspex.
Also I added some calculations on the beginning of the program so I can play around with the settings more easily.
.
Since I needed an extra ADC I had to give up the PWM pin and make a software PWM
I am sure there is much that can be improved
I have attached the Program for anyone who wants to try it with perspex.
2mm perspex works fine but 5mm becomes problematic.
Best Regards:
Uli
Attachments
Cap_dimm_switch.fcf
(36.67 KiB) Downloaded 232 times

medelec35
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: No capactive sensing (CPS) module in FC 5

Post by medelec35 »

Just a thought. For increase sensitivity, have you thought about using Vref, fixed at a lower votage e.g 1/2 supply.

With 10bit int and vref at 5V resolution is 5/1024=4.88mV
With Vref at 2.5V resolution is 2.5/1024=2.44mV etc

Thanks for sharing :)
Martin
Martin

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Thanks
I also was thinking about this,
however I could not get Internal voltage reference to work on this chip.
I posted about this in an other thread but did not get an answer yet.

On the sensitivity variable I could put some bigger value, I am sure I could put it at least 3 times higher but did not bother about it since I did not make a casing for the switch yet I was simply holding a peace of perspex over the pads. I will experiment to program it in such a way that it will need a slight pressure.

I get quite a good change in capacity with a 2mm Perspex. I think it was something between 50 and 100

The Issue with 5mm perspex is this, when the perspex over the pad is not touched there is a fluctuation of about 5, maybe one would have to make the 5mm perspex press more against the pad, to get a more stable reading.
When the 5mm perspex is touched it only gets a difference of about 5, the same as the fluctuations.


Best Regards:
Uli

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi
I think the Issue with the 5mm perspex is stray capacitances or something like that introduced through the thick perspex.
Just after connecting it to a power source it does all kinds of funny things. But after 5 Minutes or so it works perfectly.
I wonder if it will help to make a bigger time difference between measuring the two pads.
The other thing I thought of doing is to make the distance of the pads a bit bigger.
Any thoughts on this will be appreciated.
It would be nice if I can get it to work with any thickness of perspex.
(It looks like 2mm perspex is not easy to find in our area.)


I decided to post some pictures of my Capacitive Dim switch.
I like it so much I think I will use capacitive switches in most of my future Projects.
For the hobbyist it is just the easiest way to go, to make a nice finish.

Back of Pads.jpg
(79.33 KiB) Downloaded 8292 times
Pads.jpg
Pads.jpg (110.86 KiB) Viewed 14528 times
Endproduct.jpg
Endproduct.jpg (74.63 KiB) Viewed 14528 times

Next I would like to try make a capacitive panel with a Pic 18F25K22 configured as a I2C slave (since I want more than 14 capacitive pads It looks like I have to go for a Pic 18 series.) For the master I am thinking of using a Pic 18F25K80 because I like to 12 bit ADC for measuring voltages.
Are those chips working well with Flowcode?
Or is it better to just get a capacitive touch driver instead of a Pic18F25K22?

Best Regards:
Uli

Creative25
Posts: 323
Joined: Tue Sep 06, 2011 2:54 am
Has thanked: 166 times
Been thanked: 26 times
Contact:

Re: No capactive sensing (CPS) module in FC 5

Post by Creative25 »

Hi,
Just want to share some success. :lol:
I added a delay between the reading of the two pads.
Now it works 100% with thicker Perspex.
It is really amazing. See attached code.
Cap_dimm_switch2.fcf
(37.32 KiB) Downloaded 268 times
I just have another question in my mind.
The data sheet of the PIC12F1822 says that you can do both reading ADC and doing Capacitive touch sensing in sleep mode.
Is there a way to use the method of capacitive touch Sensing discussed in this thread in sleep mode, and waking up the PIC if there is a finger touching?
Or would I have to wake it up from time to time in order to see if there is a touch?
Best Regards:
Uli

Post Reply