|
|
View previous topic :: View next topic |
Author |
Message |
Emmo
Joined: 02 Feb 2017 Posts: 14
|
#USE TOUCHPAD on internal RC@64MHz not working, PIC18F67J94 |
Posted: Mon Mar 06, 2017 10:02 am |
|
|
Hello guys,
I'm trying to get a touchpad working, but have no luck.
I'm using a PIC18F67J94 with internal RC and touchpad is connected to pin C2.
Compiler version: 5.070
Here is my code:
Code: |
#include <18F67J94.h>
#device ADC=12 //return 12bit adc value
#FUSES NOWDT //No Watch Dog Timer
#FUSES BROWNOUT_SW //No brownout reset
#FUSES BORV20 //Brownout reset at 2.5V
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES SOSC_DIG //Digital mode, I/O port functionality of SOSCI and SOSCO pins
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#pin_select U4TX = PIN_E1 //RP29
#pin_select U4RX = PIN_E0 //RP28
#pin_select U3TX = PIN_B5 //RP13
#pin_select U3RX = PIN_B4 //RP12
#pin_select U2TX = PIN_G1 //RP39
#pin_select U2RX = PIN_E2 //RP30
#pin_select U1TX = PIN_A7 //RP10
#pin_select U1RX = PIN_B3 //RP7
#use delay(internal=64MHz) //run at 64MHz
#use rs232(UART1, baud=115200, parity=N, bits=8, ERRORS, stream=LCD)
#use rs232(UART2, baud=115200, parity=N, bits=8, ERRORS, stream=WIFI)
#use rs232(UART3, baud=115200, parity=N, bits=8, ERRORS, stream=BL)
#use rs232(UART4, baud=115200, parity=N, bits=8, ERRORS, stream=MB)
#USE TOUCHPAD(RANGE=H, THRESHOLD=6, SCANTIME=32, SOURCETIME=10, PIN_C2='A')
void main(void)
{
setup_lcd(LCD_DISABLED);
TOUCHPAD_STATE(1);
delay_ms(200);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(touchpad_hit())
{
fputc(TOUCHPAD_GETC(), LCD);
}
}
}
|
I tried setting TOUCHPAD_STATE(2) and read out TOUCHDATA[], but the values inside never change. I also play around with range, threshold, scantime and sourcetime and can't get it working.
When I set the internal RC to 8MHz or 16 MHz, it is working!! Somebody has an idea why 64MHz is too much for touchpads? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Mar 06, 2017 10:24 am |
|
|
I'd suspect it just can't program the timer.
Try just dropping the scantime to 30mSec. The absolute maximum time that timer3 can get to, with the maximum prescaler, at 64Mhz, is just on 32mSec. It may be finding it "can't cope", with the time being this close to the limit.
You don't want to go much faster, but a tiny change may be all it needs.
I'd suggest asking CCS, since they know their own library better than anyone else... |
|
|
Emmo
Joined: 02 Feb 2017 Posts: 14
|
|
Posted: Tue Mar 07, 2017 1:28 am |
|
|
Ttelmah wrote: | I'd suspect it just can't program the timer.
Try just dropping the scantime to 30mSec. The absolute maximum time that timer3 can get to, with the maximum prescaler, at 64Mhz, is just on 32mSec. It may be finding it "can't cope", with the time being this close to the limit.
You don't want to go much faster, but a tiny change may be all it needs.
I'd suggest asking CCS, since they know their own library better than anyone else... |
Thanks for your advice, but it doesn't help. I wrote to CCS support. Hope they figure it out. |
|
|
Emmo
Joined: 02 Feb 2017 Posts: 14
|
|
Posted: Wed Mar 08, 2017 1:55 am |
|
|
Here is the solution. The ADC clock is too fast.
Easily add the following before calling TOUCHPAD_STATE(1); :
Code: |
#byte ADCON3L=getenv("SFR:ADCON3L")
ADCON3L = 0x09; |
Thanks to CCS support for their quick help! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Mar 08, 2017 2:09 am |
|
|
Good. I'm perhaps not surprised. Many of the assumptions will start to break down when the chip is this fast. In fact many of the chips do as well (if you look at the data sheet on several of the faster chips, it's actually impossible to set some peripherals up 'optimally' in many cases). This is why on the even faster DSPIC's there are separate clocks for the peripherals.
One of the great things about the CCS compiler is that their support will answer this type of question, and quickly. |
|
|
|
|
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
|