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 CCS Technical Support

Need to get exactly 10ms int with internal TIMER1 18f4523

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



Joined: 14 Feb 2007
Posts: 46
Location: Greece & Cyprus

View user's profile Send private message

Need to get exactly 10ms int with internal TIMER1 18f4523
PostPosted: Sat Apr 12, 2008 6:13 pm     Reply with quote

Hi
I need to get exactly 10ms int with internal TIMER1 on PIC18F4523 but some how i lose 1 sec every minute.Confused

Code:


#include <18F4523.h>
#device ICD=TRUE
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV21                   //Brownout reset at 2.1V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=4000000)
#include <flexy_lcd.c>
 
 int dec_sec=0 
 int sec_time_count=0;




void main()
  {
    setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_IDLE_MODE|OSC_PLL_ON);
  lcd_init();
 
     set_timer1(55536);                        //10000 x 1ms=10ms overflow
     setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //internal 31khz crystal
    enable_interrupts(INT_TIMER1);
    enable_interrupts(GLOBAL);
   

for(;;){                 
                     
                     
      lcd_gotoxy(1,1);
        printf(lcd_putc,"set_time %5d.%02u       \n                       ",sec_time_count,dec_sec)   ;
 
           
 
      } // for(;;) void
    } // void main



#INT_TIMER1
void micro()
 {
 
  set_timer1(get_timer1()+55536);
 

  if(++dec_sec>99){  // 100x10ms=1sec
     dec_sec=0;
  ++sec_time_count;
                  }
                             
  }



I have compare the Timer1 int with My casio watch it seems to be 1 sec back for every min. Sad is there any way i can fix the issue?
_________________
---- GREECE ----
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 7:02 pm     Reply with quote

Check table 26-8 in the datasheet. Typical accuracy of the internal RC oscillator is 1%, but can be as bad as 2%.
2% of 1minute = 1.2 seconds.

If you want to improve on this you will have to use an external (crystal based) oscillator.
E_KARVELAs



Joined: 14 Feb 2007
Posts: 46
Location: Greece & Cyprus

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 7:10 pm     Reply with quote

ckielstra wrote:
Check table 26-8 in the datasheet. Typical accuracy of the internal RC oscillator is 1%, but can be as bad as 2%.
2% of 1minute = 1.2 seconds.

If you want to improve on this you will have to use an external (crystal based) oscillator.


Wink NIce.U got right...than i should change as soon as posible to external
32.768KHz crystal.
_________________
---- GREECE ----


Last edited by E_KARVELAs on Tue Apr 15, 2008 12:10 pm; edited 1 time in total
E_KARVELAs



Joined: 14 Feb 2007
Posts: 46
Location: Greece & Cyprus

View user's profile Send private message

Can't have 1 sec external TIMER1 int with 18f2550
PostPosted: Tue Apr 15, 2008 12:07 pm     Reply with quote

Hi
I have changed the hardware im using external (32.768KHz crystal with 33pF )to produce
1 sec interrupt but im going forward 1 sec every min. Confused very strange Sad i done everything but i don't understand.im using internal 8Mhz
primary clock with PLL for cpu clock .
Ive done everything ...
Any suggestion ??Sad



Code:


#include <18F2550.h>
#device ICD=TRUE
#device adc=8


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV1 
#FUSES NOUSBDIV                 //USB clock source comes from primary oscillator
#FUSES NOVREGEN                 //USB voltage regulator disabled
#use delay(clock=8000000)
#include <flexy_lcd.c>
int sec=0, min=0,hour=0;


void main(){
   
   enable_interrupts(INT_TIMER1);
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
   enable_interrupts(GLOBAL);
   lcd_init();
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);
 
 for(;;){
 
 lcd_gotoxy(1,1);
 printf(lcd_putc"%02u:%02u:%02u"hour,min,sec);
 
      }
  }
                 
#int_TIMER1
void  TIMER1_isr(void)
{
  set_timer1(32768);     //2^16=  65536/2 = 32768 * 1/32.768Hz <--- (1sec)             
                                 
         if (++sec>59){                             
                       sec=0;
         if(++min>59){
                       min=0;
                       hour++;
                     }
 
   }
}
       


Code:


  Timer1 is 16bit so
   2^16=  (65536/2)*1/32768=1.000000sec  exacly


_________________
---- GREECE ----
E_KARVELAs



Joined: 14 Feb 2007
Posts: 46
Location: Greece & Cyprus

View user's profile Send private message

PostPosted: Tue Apr 15, 2008 1:35 pm     Reply with quote

Hi again
Searching the forum along time for this issue i found some good info on this issue:
http://www.ccsinfo.com/forum/viewtopic.php?t=29957&highlight=timer1

They suggest stop TIMER1 before reading it or writing it because it's working on asynchronus mode. Still not sure what to do
Confused
_________________
---- GREECE ----
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