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

Timer0 set up for 18F4520

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



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

Timer0 set up for 18F4520
PostPosted: Tue Nov 06, 2007 2:26 pm     Reply with quote

I am trying to use the rtcc timer in my program by setting up a rtcc_isr. HOwever, something is not running correctly. When i put in code for the correct number of interrupts per second, it runs way too slow. This is the first time i have used the 18F4520, so i am wondering if i am missing something in the set up of the chip. Can anyone quickly look through this code and see if there is a noticable error? I have used this timer isr in other programs (pic16F819) and it worked fine.
Compiler PCWHD V4.06
Code:

#include <18F4520.h>
#device adc=10
#include <stdio.h>
#include <math.h>



#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XT                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES NOPUT                    //No 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 IESO                     //Internal External Switch Over mode enabled
#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 LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled



#use delay(clock=4000000,RESTART_WDT)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,RESTART_WDT,ERRORS)

#define  INTS_PER_SECOND   1  //should be(4000000/(4X256X16))=244.14

//#include <Flex_LCD.C>

int   i,step,phase1,phase2;
char  reply,int_count,loop_int;
int   byte1,byte2,byte3,byte4,byte5,byte6,byte7,byte8,byte9,byte10,byte11,byte12;
int   byte13,byte14,byte15,byte16,byte17,byte18,byte19,byte20;
int   rbyte1,rbyte2,rbyte3,rbyte4,rbyte5,rbyte6,rbyte7,rbyte8,rbyte9,rbyte10;
int   rbyte11,rbyte12,rbyte13,rbyte14,rbyte15,rbyte16,rbyte17,rbyte18,rbyte19,rbyte20;
long  crc_result,seconds;
int16 crc,r_crc;
int32 tempbyte,disbyte,mult;

////////////////////////////////////////////////////////////////////////////////
#int_rtcc
clock_isr()
{
   if(--int_count==0)                     //decrement counter until 0
   {
      ++seconds;                          //count up seconds
      int_count=INTS_PER_SECOND;          //reset counter
      if (seconds>=65000)
         seconds=65000;
   }
}
////////////////////////////////////////////////////////////////////////////////

void main()
{
   
   setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
   set_rtcc(0);
   enable_interrupts(INT_RTCC);
   enable_interrupts(global);
   set_tris_b(0b00000000);
   output_low(PIN_B5);
   int_count=INTS_PER_SECOND;             //used for timer
   seconds=0;
   while (true)
   {
       if (seconds<=1)
         output_high(PIN_B5);
       else
         output_low(PIN_B5);
       if (seconds>=3)
         seconds=0;
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 06, 2007 2:39 pm     Reply with quote

See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=30618
nmeyer



Joined: 09 Jul 2004
Posts: 70

View user's profile Send private message

PostPosted: Tue Nov 06, 2007 2:53 pm     Reply with quote

Great. I knew I was missing something. Thanks
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