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

PIC16f690 Timer1 not working properly

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



Joined: 16 Mar 2010
Posts: 11

View user's profile Send private message Send e-mail

PIC16f690 Timer1 not working properly
PostPosted: Wed Apr 21, 2010 11:51 pm     Reply with quote

Hi,

What is the maximum clock can I get using internal oscillator? What is
that noclear in ISR? Is this Timer code right?
Code:

#include <16f690.h>
//#inlcude "stdio.h"
//#fuses NOWDT,NOPROTECT,CPD,NOMCLR,NOIESO,NOFCMEN  // preprocessor directive that defines fuses for the chip
#fuses INTRC_IO,NOWDT,NOPROTECT,CPD,NOMCLR,NOIESO,NOFCMEN

#use delay(clock=8000000)

#priority timer1//#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5) // preprocessor directive that includes the rs232 libraries

#define Square_Pulse PIN_B4
#define LED_Blink    PIN_B5
#define test       PIN_B6
unsigned char fStartOfPolling;

/*****************************************************
**************  TIMER ISR FUNCTION   *****************
******************************************************/
#INT_TIMER1  noclear
void my_timer()
{
static int tCountFor20msec,tCountFor1sec,fFor12Sec,CountForLEDBlink;
//      disable_interrupts(GLOBAL);   
//   clear_interrupt(INT_TIMER1);
//SET_TIMER1(25536);
   //   OUTPUT_TOGGLE(test);
      if(   tCountFor20msec++ == 50 )      
         {
            //   output_toggle( Square_Pulse);
               if( CountForLEDBlink == 0)
                  output_toggle(LED_Blink);                
               else if (CountForLEDBlink == 5)
                  OUTPUT_LOW(LED_Blink);
               
               if( tCountFor1sec++ == 12)
                  {
                     output_toggle( Square_Pulse);
                     fStartOfPolling  = 1;
                      tCountFor1sec    = 0;
                      CountForLEDBlink = 5;
                   }
            tCountFor20msec=0;   
         }
      //   puts("micro");

//enable_interrupts(GLOBAL);   
}

void main()
{
int InputPortValue = 0;
SET_TRIS_C(0b00000000);   // 3 OUTPUT
SET_TRIS_A(0b11111111);   // 4 INPUT   
SET_TRIS_B(0b00000000);   // FOR SQUARE WAVE, LED BLINK
//setup_oscillator(OSC_INTRC);
setup_adc_ports(NO_ANALOGS | VSS_VDD);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
//setup_adc_ports(sAN8 | VSS_VDD);


      // for 20msec 40000 count required

//disable_interrupts(INT_TIMER1);
//SET_TIMER1(0);
//clear_interrupt(INT_TIMER1);
SET_TIMER1(25536);
SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_1 );

enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);

/************ LOW-HIGH-LOW PULSE ON PWRKEY PIN OF GSM */
OUTPUT_C(0x00);
OUTPUT_LOW(Square_Pulse);
OUTPUT_HIGH(LED_Blink);
OUTPUT_HIGH(test);
while(1)
    {   
   
      
      if( fStartOfPolling  == 1)
      {
         InputPortValue = INPUT_A();
         InputPortValue = (InputPortValue & 0x0F );
         if(InputPortValue == 0x08 )   // INPUT 1 IS HIGH
         OUTPUT_C(0x04);
         else if(InputPortValue  == 0x0C )
         OUTPUT_C(0x02);
         else if(InputPortValue  == 0x0E )
         OUTPUT_C(0x06);
         else if(InputPortValue  == 0x0F )
         OUTPUT_C(0x01);
      }
      
    }
}

Thanx in anticipation
Lokesh
_________________
Thanks & Regards
Lokesh Bhatt
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 5:39 am     Reply with quote

Answers to your questions:

1. See the data sheet page 48 for the max oscillator speed.

2. See page 116 of the current manual for the meaning of noclear

3. no
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 9:33 am     Reply with quote

And, because noclear is used, the code as posted cannot work. It'll hang forever in the timer1 interrupt...

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