CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

capacitive sensing using PIC16f727

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kbruin79



Joined: 02 Aug 2010
Posts: 30

View user's profile Send private message

capacitive sensing using PIC16f727
PostPosted: Thu Feb 24, 2011 1:33 am     Reply with quote

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: 1903

View user's profile Send private message

Re: capacitive sensing using PIC16f727
PostPosted: Thu Feb 24, 2011 8:13 am     Reply with quote

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: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Feb 24, 2011 10:17 pm     Reply with quote

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

View user's profile Send private message

Re: capacitive sensing using PIC16f727
PostPosted: Wed Mar 02, 2011 1:11 am     Reply with quote

Thank you newguy. I followed your suggestions and I got it to work.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group