Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Capacitive Sensor - 16f628a

Status
Not open for further replies.

cybersky

Member
Hi
I tried to adapt a 3D "touchless" sensor which was based on arduino to pic.
The theory is "simple" set pin to output then set pin low. then set pin as input and wait for pin to go high. i did not use the timer i just used a for loop of 10000 and a count variable. but i think it is not enough "time" (10000) for the pin to go high, I tried using the timer but i am not sure if the interupt is firing or if i have the "bits" set correctly. BUT importantly, are there perhaps any issues relating to timing between setting a pin to an output and then setting it back to an input in oshon?
 
hi,
Please post your full program code.
 
16f628 using the internal OSC (4mhz)

Code:
dim cntchg as word
dim zone1 as word
dim zone2 as word
dim zone3 as word


get3d:

config portb = output

portb = 0 ' all low


'set to input
config portb.4 = input

'get how long it takes to chrg cap
for cntchg = 0 to 10000


if portb.4 = 1 then

       zone1 = cntchg
       goto zone2
endif

cntchg = cntchg + 1

next cntchg

'did not happen in time
zone1 = 0


zone2:

cntchrg = 0
'set to input
config portb.5 = input


'get how long it takes to chrg cap
for cntchg = 0 to 10000

if portb.5 = 1 then

       zone2 = cntchrg
       goto zone3
endif

next cntchrg


'did not happen in time
zone2 = 0


zone3:

cntchrg = 0
'set to input
config portb.6 = input

'get how long it takes to chrg cap
for cntchg = 0 to 10000

if portb.5 = 1 then

       zone3 = cntchrg
       goto send3d
endif

next cntchrg


'did not happen in time
zone3 = 0


send3d:

'used with usb2serial cable - saves on max232.
seroutinv portb.2, 4800, "x", zone1, "y", zone2, "z", "zone3"
waitms 20
goto get3d

end

i retyped it from memory - small enough. i used 2.2k resistor but i was supposed to use 220k. so i am still to change that. but i think i need some waitms's between pin config changes? and a wait after i put the pin low to give "cap" enough time to discharge. but since i only get x0y0z0 i dont think the caps are charging at all.
here is the link i found - so i used the circuit but i wrote my own code based on the theory.
http://www.touchuserinterface.com/2009/03/diy-3d-capacitive-touch-sensing.html
 
Last edited:
hi,
You cannot use the same name/label for a DIM and GOTO label, it gives a Compile error


Dim zone1 as Word and GOTO zone1
 
Last edited:
I understand that there are newer tech avail. but sometimes its in the "could i do it", know what i mean? and its suppose to be "simple" count.
 
Hi Eric

Sorry about that syntax error - but like i said i just quickly retyped it inside this reply box. the code is on my home pc.
 
Status
Not open for further replies.

Latest threads

Back
Top