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

#USE TOUCHPAD on internal RC@64MHz not working, PIC18F67J94

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



Joined: 02 Feb 2017
Posts: 14

View user's profile Send private message

#USE TOUCHPAD on internal RC@64MHz not working, PIC18F67J94
PostPosted: Mon Mar 06, 2017 10:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 06, 2017 10:24 am     Reply with quote

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... Smile
Emmo



Joined: 02 Feb 2017
Posts: 14

View user's profile Send private message

PostPosted: Tue Mar 07, 2017 1:28 am     Reply with quote

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... Smile


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

View user's profile Send private message

PostPosted: Wed Mar 08, 2017 1:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 08, 2017 2:09 am     Reply with quote

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.
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