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 CCS Technical Support

Touch with 18F46J50

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



Joined: 01 Jun 2011
Posts: 6

View user's profile Send private message

Touch with 18F46J50
PostPosted: Wed Jun 01, 2011 2:55 pm     Reply with quote

Hello Forum,

I wrote my first code:

Code:

#include <18F46J50.h>
#fuses INTRC_IO,NOWDT
#use delay(clock=8000000)
//#use fast_io(b)
#use TOUCHPAD(THRESHOLD=6, PIN_A0='5')

void main()
{
set_tris_d(0b11111111);
output_low(PIN_D7);
output_high(PIN_D4);
output_high(PIN_D5);
output_high(PIN_D6);
char c;
enable_interrupts(GLOBAL);
TOUCHPAD_STATE(1);
while (TRUE)
{
  if(touchpad_hit())
  {
    output_high(PIN_D3);     
    c=touchpad_getc();
    if (c=='5') output_high(PIN_D3); else output_low(PIN_D3);
  }
  output_toggle(PIN_D2);
  delay_ms(500);      
}
}


But the Touch sensor don't work. Compiler 4.121
What's the problem?
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jun 01, 2011 3:42 pm     Reply with quote

I'd suggest writing the 'blinking LED' program first to verify that your compiler, PIC, and protoboard are all working correctly then move onto the touchpad program.
guenter



Joined: 01 Jun 2011
Posts: 6

View user's profile Send private message

PostPosted: Thu Jun 02, 2011 12:40 am     Reply with quote

Hello,

the LED on D2 is binking

Code:
  output_toggle(PIN_D2);
  delay_ms(500);


the LED on D3 is never on.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Thu Jun 02, 2011 3:58 am     Reply with quote

One problem with your code is you can't tell if it never detects the touch or if it never gets the '5' from getc() (you might see a very quick pulse with a scope, but you won't see it with your eyes if it is detecting the touch, but not the '5'). Start by toggling the LED each time it detects a touch then you can move on to is it getting the right data.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
guenter



Joined: 01 Jun 2011
Posts: 6

View user's profile Send private message

PostPosted: Thu Jun 02, 2011 12:35 pm     Reply with quote

Code:
#include <18F46J50.h>
#fuses INTRC_IO,NOWDT
#use delay(clock=8000000)
#use TOUCHPAD(THRESHOLD=6, PIN_A0='5')

void main()
{
set_tris_d(0b11111111);
output_low(PIN_D7);
output_high(PIN_D4);
output_high(PIN_D5);
output_high(PIN_D6);
char c;
enable_interrupts(GLOBAL);
TOUCHPAD_STATE(1);
while (TRUE)
{
  if(touchpad_hit())
  {
    output_high(PIN_D3);     
    c=touchpad_getc();
  }
  output_toggle(PIN_D2);
  delay_ms(500);      
}
}


I changed the code, but the LED on D3 is off. I think if touchpad_hit is true the D3 gets high an stay high.
guenter



Joined: 01 Jun 2011
Posts: 6

View user's profile Send private message

PostPosted: Thu Jun 02, 2011 1:32 pm     Reply with quote

Aaarghh,

i think i found an bug in CCS:

Code:
#use TOUCHPAD(THRESHOLD=6, SCANTIME=32, PIN_B2='5', PIN_B3='6')


is not working, but this:

Code:
#use TOUCHPAD(RANGE=18, THRESHOLD=6, SCANTIME=32, PIN_B2='5', PIN_B3='6')


There should be an default value for RANGE (18)
There are also 2 Warnings:

>>> Warning 202 "main.c" Line 4(5,8): Variable never used: CTMU_STATUS
>>> Warning 202 "main.c" Line 4(5,8): Variable never used: CTMU_THRESHOLD
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