|
|
View previous topic :: View next topic |
Author |
Message |
Orcino
Joined: 07 Sep 2003 Posts: 56
|
TIMER1 PIC18LF46J50 |
Posted: Thu Aug 30, 2012 6:08 am |
|
|
Hi guys,
I have a problem with the TIMER1 18LF46J50. I made a small program to test the MPLAB. the TIMER 1 is not increasing and logically does not generate interrupt. Can anyone help?
thank you
Orcino
Code: |
#include <18LF46J50.h>
#device adc=10
#FUSES HSPLL
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL2 //Divide By 2(8MHz oscillator input)
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES T1DIG //Secondary Oscillator Source may be select if T1CON.3 = 1
#FUSES NOLPT1OSC //Timer1 configured for low-power operation
#FUSES NODSBOR //BOR disabled in Deep Sleep
#FUSES NODSWDT //Deep Sleep Watchdog Timer disabled
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES NOWPFP //Write/Erase Protect Page Start/End Location, set to page 0
#FUSES NOWPDIS //Erase/write-protect active for the selected region(s)
#use delay(clock=48Mhz)
#byte OSCTUNE = 0XF9B
#bit PLL_EN = OSCTUNE.6
int16 teste=0;
int16 varTimer1=0;
#int_TIMER1
void TIMER1_isr(void)
{
teste++;
}
void main()
{
setup_timer_1(T1_FOSC|T1_DIV_BY_1); //5.4 ms overflow
setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
PLL_EN=1;
while(TRUE)
{
varTimer1=get_timer1();
delay_ms(10);
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19516
|
|
Posted: Thu Aug 30, 2012 8:08 am |
|
|
Your setup is wrong for the timing you want. Use T1_INTERNAL, not T1_FOSC.
T1_FOSC, clocks the timer directly from the oscillator, not from FOSC/4. Gives 4* the rate, but has several limitations. They say in the data sheet, not to select this with ECCP features, but it seems to give problems with quite a few other things as well. For your 5.4mSec rate, T1_INTERNAL, is the correct selection, and does work OK. Using Fosc directly, appears to be limited by the same frequency limits as the timer1 clock input (12MHz max). It worked OK for me up to 16Mhz, but then wouldn't run above this. Nowhere in the data sheet does it say this limit is there, but it seems to be.....
As a comment, just use 'setup_oscillator(OSC_PLL_ON);', to enable the PLL, you don't have to set the bit yourself.
Best Wishes |
|
|
|
|
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
|