View previous topic :: View next topic |
Author |
Message |
guenter
Joined: 01 Jun 2011 Posts: 6
|
Touch with 18F46J50 |
Posted: Wed Jun 01, 2011 2:55 pm |
|
|
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
|
|
Posted: Wed Jun 01, 2011 3:42 pm |
|
|
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
|
|
Posted: Thu Jun 02, 2011 12:40 am |
|
|
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
|
|
Posted: Thu Jun 02, 2011 3:58 am |
|
|
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
|
|
Posted: Thu Jun 02, 2011 12:35 pm |
|
|
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
|
|
Posted: Thu Jun 02, 2011 1:32 pm |
|
|
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 |
|
|
|