|
|
View previous topic :: View next topic |
Author |
Message |
R Diver
Joined: 25 Jun 2010 Posts: 2
|
PIC not Driving External Crystal to Increment Timer1 |
Posted: Sat Aug 21, 2010 3:15 pm |
|
|
I'm using a PIC18F25J10 on a pcb I layed out and compiler v4.111.
I'm trying to use the Timer1 interrupt with an external 32.768KHz crystal for a simple RTC. However, the Timer1 interrupt never occurs.
I scoped it and there is no activity on the crystal pins at all. I'm using the same crystal that I've used on other boards and two 21 pF caps.
The PIC runs my ~2K line program correctly, draws normal current, and has solid 3.3V on the Vdd pins, so all indications are that its working correctly.
Here is a simple program that fails to drive the xtal. It prints a message when main starts, and then never prints that the timer1 interrupt occurred.
Scope shows no activity on xtal pins. Solder looks clean and multimeter confirms that PIC pins are connected to xtal & caps.
Thanks for your time.
Code: | #include <18F25J10.h>
#device PASS_STRINGS = IN_RAM
#include <stdio.h>
#include <string.h>
#include "fuses.h"
#use delay(clock=8M) //external 8 MHz Oscillator, No PLL
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Function Prototypes////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Manage Interrupts
void enable_rtc_interrupt();
void clear_rtc_interrupt();
//Main
void setup_hardware();
void setup_xtal();
void setup_io();
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//RS-232 Drivers/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Serial Debug
#use rs232(BAUD=9600, XMIT=PIN_C6, BITS=8, PARITY=N, ERRORS)
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//ISRs///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ONE_SECOND 32768
/*
Real Time Clock Interrupt
*/
#int_timer1
void timer1_isr() {
printf("\r\nRTC Interrupt!\r\n\r\n");
set_timer1(ONE_SECOND); //cnt down 1x/second
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Manage Interrupts//////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void enable_rtc_interrupt() {
//clear interrupt
clear_rtc_interrupt();
//setup interrupt
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);
set_timer1(ONE_SECOND);
//enable interrupt
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
}
void clear_rtc_interrupt() {
clear_interrupt(INT_TIMER1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Main///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup_hardware() {
setup_xtal();
setup_io();
}
/*
configure PIC to go use external oscillator (normal) with no pll
and to enter idle mode on next sleep instruction
*/
void setup_xtal() {
setup_oscillator(OSC_PLL_OFF | OSC_NORMAL | OSC_IDLE_ON_SLEEP);
}
void setup_io() {
//set tris
set_tris_a(0x7F);
set_tris_b(0x00);
set_tris_c(0x02);
}
void main(void) {
setup_hardware();
printf("RTC Test\r\n");
enable_rtc_interrupt();
while(1);
} |
And here are the fuses in fuses.h:
Code: |
#fuses NODEBUG //Debugger Disabled
#fuses NOXINST //Do Not Use Extended Instruction Set
#fuses STVREN //Reset on Stack Overflow/Underflow
#fuses NOWDT //No Watch Dog Timer
#fuses PROTECT //Code Protection Enabled
#fuses NOIESO //Two-Speed Start Up Mode Disabled
#fuses NOFCMEN //Fail-Safe Clock Monitor (Switch to Internal Osc on External Osc Failure) Disabled
#fuses HS //HS Oscillator (No PLL)
#fuses WDT32768 //Watch Dog Timer Postscaler
#fuses CCP2C1 //Capture & Compare Muxing, CCP2 is Multiplexed with RC1
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Aug 21, 2010 3:24 pm |
|
|
You need:
Code: |
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);
|
Otherwise the timer expects an external clock _input_, but does not generate the drive output to operate a crystal....
Best Wishes |
|
|
R Diver
Joined: 25 Jun 2010 Posts: 2
|
Thank you |
Posted: Sat Aug 21, 2010 3:34 pm |
|
|
Thanks very much for your response. That fixed it. |
|
|
|
|
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
|