PIC16F1827 Capacitive Touch Sensor not Incrementing Timer?

So I have a PIC16F1827 on a breadboard and was trying to get a simple demo working where I touch a wire to turn on an LED using the Capacitive Sensing Module. I was primarily going off this example I found, cross-referencing section 27 of the datasheet to make any corrections. However, despite my best efforts it wont do anything. From what I can gather the Timer1 isn't incrementing at all, just sitting at 0. Can someone help me figure out what I've screwed up here?

int count = 0;
int thresh = 0;

void main(void)
{
// initialize the device
SYSTEM_Initialize();
SWDTEN = 0;

TRISA1 = 0;
RA1 = 0;
TRISB5 = 1;
ANSB5 = 1;
// Set CPS module as Timer1 clock source
T1CON = 0b11000100;
T1GCON = 0;
// Set CPS range to high and channel to 8(B5)
CPSCON0 = 0b10001100;
CPSCON1 = 0b1000;

TMR1ON = 1;
TMR1 = 0;
__delay_ms(16);
TMR1ON = 0;
thresh = TMR1 * 8 / 10;;
TMR1 = 0;
TMR1ON = 1;
//SWDTEN = 1;
//SLEEP();
__delay_ms(16);

while (1)
{
TMR1ON = 0;
count = TMR1;
RA1 = count < thresh;
TMR1 = 0;
TMR1ON = 1;
//SWDTEN = 1;
//SLEEP();
__delay_ms(16);
}
}

• When I have problems with microcontroller peripherals that I just can't resolve, I try backing up and doing something really simple. In this case, given the description of the CPS module in your link, I think I would make code that just turns the light on any time the timer number goes above half it's range, and don't reset the value. This should give you an LED that blinks at a rate roughly proportional to the CPS oscillator's rate, only divided by 2^16 (or whatever the timer size is). So if it blinks, and blinks different when you touch it, you've learned a LOT. Oct 20 '18 at 17:07
• I've tried a few variations of that and similar ideas. That's how I confirmed the timer isn't counting. I set RA1 = count == 0;. The LED stayed solidly lit. Oct 20 '18 at 21:42
• So, I poked at the datasheet a little bit. I strongly suspect that there's some "screw the processor bit" that you haven't set correctly yet. The fact that you're not getting and indication of oscillation at all tells me that either you don't, in fact, have the capacitive sensing oscillator going, or that you've not correctly configured its output to the timer, that you haven't connected it to the expected pin, or that something is dreadfully wrong electronically. Sorry for the vague answer -- I haven't actually used this part, so I can't help with specifics. Oct 21 '18 at 1:37
• So I did some more poking and prodding and was able to determine that the issue is definitely something to do with the capacitive module or its connection to Timer1, as changing the Timer1 clock source to the system click sends it oscillating exactly as expected. Oct 21 '18 at 4:51