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 support@ccsinfo.com

TIMER1 PIC18LF46J50

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



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

TIMER1 PIC18LF46J50
PostPosted: Thu Aug 30, 2012 6:08 am     Reply with quote

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: 19349

View user's profile Send private message

PostPosted: Thu Aug 30, 2012 8:08 am     Reply with quote

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