Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Clock suddenly running slow (used to work perfectly)

Status
Not open for further replies.

aljamieson

Newbie level 1
Joined
Mar 4, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,299
SETUP

Chip: PIC16F690
IDE: MPLAB (v8.30)
Compiler: HI-TECH C PRO (v9.65 Lite)
Programmer: PICkit2 (SW v2.50, FW v1.51, OS v2.32)

SITUATION

I have been building a project with the above setup, everything was working fine and my project was near completion. However I kept running out of room due to the reduced code compression of the Lite C compiler.

So, instead of spending £100's on a compiler upgrade, I looked at upgrading my setup to a PIC18 series with more memory (for a few £), which involved upgrading my PICkit2 firmware/OS... I'm fairly certain that's when it all went wrong (it was late at night and I was making changes to many aspects of the project!)

My project relies on critical timing for USART and IR communication and what used to be a 10ms interrupt timer is now a 15.92ms timer.

I tried reverting the PICkit2, which didn't work. I have even tried a new PICkit2 which didn't help either. I have checked, double checked and triple checked all IDE, compiler and PICkit2 settings and cannot see what is causing the change.

SANITY CHECK

As a sanity check, to make sure it wasn't a software issue, I started with a clean project and wrote the simple code below to generate what should be a square wave with 10ms mark followed by 10ms space...

Can someone please verify that this should generate the aforementioned square wave, and also offer any ideas as to why I am seeing this sudden but consistent slowdown of the timers

Thanks!
Al

Code:
#include <htc.h>

void main(void)
{
	__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & BOREN & IESODIS & FCMDIS);

	OSCCON=0x71;		// internal clock, Fosc = 8MHz
	OSCTUNE = 0;		// set to factory cal, just to be sure

	// CONFIGURE TIMER 1 for 10ms interrupts

	TMR1IE = 1;		// enable timer1 overflow interrupt
	TMR1CS = 0;		// internal clock (Fosc/4) = 2MHz
	T1CKPS1 = 0;		// pre-scalar set to 1:1, so T1clock = 2MHz
	T1CKPS0 = 0;
	TMR1H = 0xB1;		// 10ms is 20000 (0x4E20) counts at 2MHz
	TMR1L = 0xE0;		// so, preload is 0x10000 - 0x4E20 = 0xB1E0
	TMR1ON = 1;
	PEIE = 1;		// enable peripheral interrupts

	TRISA0 = 0;		// configure toggle bit, for logic tool

	GIE = 1;		// global interrupt enable

	for(;;) { NOP(); }
}

static void interrupt isr(void)
{
	static bit toggle = 0;

	if(TMR1IF)
	{
		// preload register for overflow after another 10ms
		TMR1ON =0;
		TMR1H = 0xB1;
		TMR1L = 0xE0;
		TMR1ON =1;

		// toggle a pin for logic tool
		if(toggle == 0) { RA0=1; } else { RA0=0; }
		toggle = !toggle;

		TMR1IF = 0;	// clear interrupt flag
	}
}


---------- Post added at 21:34 ---------- Previous post was at 21:30 ----------

PS - the device still erases, programs and verifies perfectly. The increased time of 15.92ms was measured using the PICkit2 (I even tried calibrating the VDD to see if that helped)
 

Have you tried making the simplest 'led on-off' program with 2-3 second delay, and time it with a stopwatch.
If the clock is really that much out of whack, you should see a significant difference.
 

Have you tried putting a scope probe on the toggle pin to see what you are actually getting?

Instead of the Pic18 series, look at Pic24. Not a lot of difference in cost but a massive leap in power with 16-bit regs.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top