View previous topic :: View next topic |
Author |
Message |
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
capacitive sensing using PIC16f727 |
Posted: Thu Feb 24, 2011 1:33 am |
|
|
Hello,
I am using compiler PCW 4.105. I couldn't get the built in capsense functions to work. I had no errors but LED0 AND 1 simply won't light up to a capsense input. Any idea if i am missing anything? Thanks
Code: |
#include <16F727.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
//#include <stdarg.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOMCLR,VCAP_A6
#use delay (internal=4000000) //(clock=4M)
#use fast_io (A) // use the manual way for assigning IO pins
#define CLR 12
#use touchpad(scantime=32ms,threshold=6,PIN_B0='C',PIN_B1='D',PIN_B2='E',PIN_B3='F')
//---------------------------------------------------
// Main
//---------------------------------------------------
void main()
{
set_tris_a(0xf0);
setup_adc_ports(NO_ANALOGS);
//Set PORT A Output to GND
output_low(PIN_A0);
output_low(PIN_A1);
output_low(PIN_A2);
output_low(PIN_A3);
//Set PORT E Output to GND
output_low(PIN_E0);
output_low(PIN_E1);
output_low(PIN_E2);
//-----------------------------------------------------
//main loop
//-----------------------------------------------------
char c;
enable_interrupts(GLOBAL);
while(TRUE)
{
TOUCHPAD_STATE(1); //calibrates, then enters normal state
if(touchpad_hit())
{
c=touchpad_getc();
}
If (c=='C')
{
//TURN ON LED0
output_low(PIN_A0);
output_high(PIN_A1);
output_high(PIN_A2);
delay_ms(1000);
}
if (c=='D')
{
//TURN ON LED1
output_high(PIN_A0);
output_low(PIN_A1);
output_low(PIN_A2);
}
delay_ms(1000);
}
|
|
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
Re: capacitive sensing using PIC16f727 |
Posted: Thu Feb 24, 2011 8:13 am |
|
|
kbruin79 wrote: |
//---------------------------------------------------
// Main
//---------------------------------------------------
void main()
{
set_tris_a(0xf0);
setup_adc_ports(NO_ANALOGS);
//Set PORT A Output to GND
output_low(PIN_A0);
output_low(PIN_A1);
output_low(PIN_A2);
output_low(PIN_A3);
//Set PORT E Output to GND
output_low(PIN_E0);
output_low(PIN_E1);
output_low(PIN_E2);
//-----------------------------------------------------
//main loop
//-----------------------------------------------------
char c;
enable_interrupts(GLOBAL);
while(TRUE)
{
TOUCHPAD_STATE(1); //calibrates, then enters normal state
if(touchpad_hit())
{
c=touchpad_getc();
}
If (c=='C')
{
//TURN ON LED0
output_low(PIN_A0);
output_high(PIN_A1);
output_high(PIN_A2);
delay_ms(1000);
}
if (c=='D')
{
//TURN ON LED1
output_high(PIN_A0);
output_low(PIN_A1);
output_low(PIN_A2);
}
delay_ms(1000);
}
|
My guess is that you'll want to move the highlighted line OUT of the main loop of your program. Calibrate the touch sensor just before your while(TRUE) loop. With it where it is, the system will attempt to calibrate "out" finger touches. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Feb 24, 2011 10:17 pm |
|
|
Or, maybe call it every 10,000 (or some number) passes. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
kbruin79
Joined: 02 Aug 2010 Posts: 30
|
Re: capacitive sensing using PIC16f727 |
Posted: Wed Mar 02, 2011 1:11 am |
|
|
Thank you newguy. I followed your suggestions and I got it to work. |
|
|
|