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

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,

That's great thanks for sharing the updated program, I will have a play.

Not too sure about the new fancy sleep features of the newer devices so not really sure what is possible. I would have a go at going to sleep and reading the cap touch pads. If you can't get it working then using the timer to wake up the device is a good fall back position.

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

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

Post by Creative25 »

Hi.
I just read the data sheet of the Pic12 F 1822 about ADC during sleep mode.
It looks like you can give it the instruction to Read a ADC just before the sleep command, and then it will actually go to sleep before reading the ADC. If you enable the ADC interrupt it will wake up after reading the ADC, it works only If you use FRC.
This is good for noise reduction while reading the ADC, but I think it can not be used for Capacitive touch sensing.

So I would have to definitely go for the option of waking it up for the Capacitive sensing to be done.
I read on the forum about the sleep command, but am not sure about all the conditions that need to be fulfilled before using it.
It looks to me the best way to wake it up would be to use the watchdog timer.
How would I set the WDTCON register or whatever is needed, in Flowcode? According to the data sheet the value 0x07 would give a timeout of about 128ms.
Is there some settings I would have to change in the configuration file as well?

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,

I would use timer 1 instead. Once you have the watchdog enabled it can be a bit of a pain unless you specifically need a watchdog operation.

To be honest though I'm not that clued up on sleep, this is the kinda of thing I would try first.

Enable Timer 1 with the timeout period set to be the period of sleep, the macro to be called can be empty or could have your CAP touch routine followed by a command to go back to sleep.

Then after enabling the interrupt use a C icon with the following command.

Code: Select all

sleep();
If this works ok then maybe try again with the watchdog as I could be wrong about this.

Let me know how your getting on.

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

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

Post by Creative25 »

Hi,
I just found a mistake in the Code a posted previously. (Cap_dimm_switch2)
The ontime variable has an initial value of 10 instead of zero, that is why it came on initially when plugged in.

Just got sleep and wake up working.
I read in the datasheet of the PIC12F1822 it says you can only use timer1 for waking up a chip if you use an external oscillator.
So I went for the watchdogtimer option. And a separate loop that checks the increase button.
The watchdogtimer gets enabled before it goes to sleep and disabled when a button is touched.
I am actually surprised I got it working, since I count myself as a beginner.
Cap_dimm_switch4.fcf
(39.41 KiB) Downloaded 499 times
It works ok but it it introduced some instability, sometimes the Light flickers a bit while increasing or decreasing the light intensity.
Can anyone who is an expert give some advice how to improve stability of the code?

Best Regards:
Uli

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

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

Post by Creative25 »

Hi to all.
I just wonder how long it takes for the high speed oscillator to stabilize after start up.
Would it be advisable to put a delay before doing capacitive touch sensing?
How long does an oscillator take till it is stable after start up?

Best Regards:
Uli

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

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

Post by Creative25 »

Hi,
Just found the reason for the instability that came with the modified code. That uses the sleep command.
I had removed the delay within the Capacitive sense macro, that is used to set the speed the PWM increases. I put it in a different part of the program so it will check the Capacitive touch pad immediately after wake up.

I have discovered.
HFOSC needs between 2 and 8 us for start up, and PLL needs about 2ms for start up.
So after wake up it will need a delay of about 3ms so the oscillator will be stable and the ADC reading will be accurate.
That was the reason why it was unstable.

I am trying to find out if a capacitive touch using ADC would be feasable for battery operated devices.
My thought is to use a lower frequency without PLL after wake up, when just checking if a button is pressed. And then increasing the speed if a button has been pressed, before going into the main loop. So there would be extra energy saving, and I could use a 10us delay instead of a 3ms delay.
I have established that it should work changing frequency within the program, according to the data sheet.
But still I wonder how to apply this within Flowcode.
In the project options you set the oscillator speed for the Program.

So now if I use a different frequency within parts of the program and put a delay Icon, I guess it would not work correctly.
How could I work around this in Flowcode?

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,

Some good findings there, thanks for letting us know how your getting on.

Regarding the different length delays this is a tricky one. Could you make simple loop based to do the low speed non PLL delaying.

eg.

Code: Select all

count1 = 0
while count1 < 255
{
 count1 = count1 + 1
 count2 = 0
 while count2 < 255
 {
 count2 = count2 + 1
 }
}
Would delay for at least 256 x 256 = 65536 operations.

At 8MHz or 2MIPs this would delay for at least 0.032768s or 32ms.

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

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

Post by Creative25 »

Hi Benj,

I see I would also need a C code block to edit ADCON1 register.
In order to adjust ADCS Bits when frequency is changed.
I guess in flowcode this gets automatically set under the ADC Component settings under EXT properties.
However when changing frequency while the program is running i would have to change from Fosc/32 to Fosc/8
In the ADCON1 register.
Is that correct?
16.1.6 RESULT FORMATTING
The 10-bit A/D conversion result can be supplied in two
formats, left justified or right justified. The ADFM bit of
the ADCON1 register controls the output format.
Figure 16-3 shows the two output formats.
Bit 7 of ADCON1 is for setting the data format of the ADC result. What format does flowcode use for the result?

Best Regards:
Uli

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

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

Post by Creative25 »

Hi.
I finally got it working fine putting to Sleep, and waking it up at a slow speed for checking the Capacitive Pads.
I think this can save tremendous energy by only needing a 8 us delay after wake up.
If it would wake up at 32MHz you would need to wait 2ms or more for the PLL to stabilize.
When a touch is detected it goes to 32MHZ
If there is no touch it goes back to sleep.
I have attached the file.
Note there is a special macro for reading the pads at low speed since a normal delay would not work when clock speed is changed within the program.
Low_energyCap_dimm_switch.fcf
(47.43 KiB) Downloaded 518 times
Best Regards:
Uli

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi all

I'm trying to make a capactive key pad (3 x 4) (0-9 * & #) What i would like to do is when the relevant key is pressed e.g 1 it must send Char 1 via uart and print to LCD im not sure how to implement this in the sample code (CapTouch_pressure) to test and is it posible to simulate please help

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi guys

Have a small problem and not sure whats wrong what I'm doing is testing in real pic simulator the sample code below it works for 0, 1, 2, then 3 and 4 are swapped around and then 5, 6, 7 all operate from 5. then 8 ,9, *, # are all fine again can anyone tell me what I'm doing wrong.

Brian
Attachments
CapTouch_with_output.fcf
(65.59 KiB) Downloaded 441 times

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

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

Post by Creative25 »

Hi.
I f you try to simulate it in flowcode it shows some errors.
uninitialised Variable: .sum
uninitialised variable: .Return

All variables do need to have an intial value.
Somewhere you must put a formula. .sum=0 and .return=0

At the Beginning of your macro you need to set ".sum" to zero, or else your readings will not be correct.
That part was missing in one of your macros.
I added a formula that removes those errors.

Hopefully it will work now in Real Pic Simulator.

Best Regards:
Uli
Attachments
CapTouch_with_output2.fcf
(65.82 KiB) Downloaded 407 times

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Thanks

It Worked and simulates right there was also 2 variables left out in 6 & 7 but it is working great now.

Brian

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi Guys

Can any one tell me if this cod is right as I've tried it on the hardware with a PIC16F887 and i cant get it to do anything not sue if the c code is right or im doing something stupid

Brian :?
Attachments
CapTouch_with_output3.fcf
(111.98 KiB) Downloaded 380 times

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

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

Post by Creative25 »

Hi.

For capacitive touch I would first change the code a little to display the ".return" value on your display instead of "char".
Press each key to see how the values change. Then you can decide on a threshold value.

Best Regards:
Uli

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

HI Uli

Thanks again for the advise will do so.

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

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

Post by Creative25 »

Put the formula Char="0" etc before your send the data.

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi Guys

I'm not to sure if i am right as i do not understand C code I'm using a PIC16F887 chip and have tried to expand the key pad to 12 keys in Benj exsample he had 5 keys and the C code is adcon0 0x01, adcon0 0x05, adcon0 0x09, adcon0 0x0D, adcon0 0x11. If i expand now will the next adcon0 be 0x15, adcon0 0x19, adcon 0x2D, adcon0 0x21, adcon0 0x25 adcon0 0x29, adcon0 0x3D?? I saw in this thread that he said this C code selects the relevant ADC channels and .

Brian
Attachments
CapTouch_10_str2.fcf
(54.51 KiB) Downloaded 348 times

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

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

Post by Creative25 »

Hi
I think most of your code for selection is correct.
You can check in the data sheet of the Pic under adcon, according to my understanding AN7 is 0x1D and an11 is 0x2D
Do you get any results numbers on your display?
Also check on page two in this thread there is a bug in flowcode 5
For my program to work on the pic16F1939 I had to change some code in CAL_ADC file.
Did you check this?

Best Regards:
Uli

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi Uli

Thanks for all your help i sorted the adcon0 addresses out from E2 on wards it was wrong. i did read about the bug but have no clue how to fix it and not sure if my version has been fixed im using version 5.5.2.1 do you know if it has the bug and how do i sort it if so.

Brian

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

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

Post by Creative25 »

Hi Brian.
Is your program working now in real hardware?
If not it would help if you could describe a bit more what it is doing.
And what you have on your display when pressing a pad.

Best Regards:
Uli

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi Uli

I'm pulling my hair out here cant seem to see what I'm doing wrong, what i have is an EB006 board with a PIC16F887 chip clock speed 19.660800 all I have connected to it is the resistor between RE0 & RE1
a LCD display connected to port C and only 1 pad connected to A0 and what I'm trying to do is get A0 to display the Return value on the display for test purposes and send The Char via uart. But what is happening is that the display shows 2 digits that are rapidly changing.

Brian
Attachments
CapTouch_Print_Return1.fcf
(99.41 KiB) Downloaded 405 times

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

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

Post by Creative25 »

Hi Brian.

I had a look at the PIC_CAL_ADC file on the latest version of flowcode, It looks like they did not fix it yet.
I have a modified file that works for capacitive touch for Pic 12F1822 and Pic16F1939 I modified it for you so it should work also for yours pic 16F887
I have no pic 16F887 so I can not test it for you. Try if it works.

Go to the following folder and paste the file. Programs/flowcode/v5/cal/pic, You should see your original PIC_CAL_ADC file.
Before you do that it is always good to backup the original PIC_CAL_ADC file.

Best Regards:
Uli
Attachments
PIC_CAL_ADC.c
(89.73 KiB) Downloaded 365 times

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi Uli

Sorry took so long to reply but have been very busy and had no time to design but thanks for the the changes i have implemented it but still cant get it working. I have ordered new chips PIC16F1939 this chip has 16 capsensitive pins lets see if i can get it working with this.

Brian

User avatar
jollybv
Flowcode v5 User
Posts: 376
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times

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

Post by jollybv »

Hi Guys

Have a slight problem and cant find it I'm trying to display the cap sens state variable on my e-blocks but for the life of me i cant get the display to work i have made a small test program and that works fine but in my cap sense program it refuse to display on the LCD all i get is a top row of squares can someone take a look and maybe see what i have done wrong. The chip settings are the same as in my test program but nothing

Regards
Brian
Attachments
CapTouch_with_output4.fcf
(77.71 KiB) Downloaded 303 times

Post Reply