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

Problem with the counting external clock pulse

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



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

Problem with the counting external clock pulse
PostPosted: Thu Dec 11, 2008 2:19 pm     Reply with quote

Hi everyone,

I face a weird problem. I have this piece of code to count external clock pulses.
When I first time run in debugger mode with setting breakpoint in while loop end; it gives around variable 27000-32000 count more.

My external clock is clean, and I use port A3 to external trigger to oscillator.
But after stopping first time I loop around it gives me accurate number.
If someone can throw light on this one it would be a great help.

Thanks
nehal

Code:

int8 count = 0;
int16 counter = 0;

//!timer1 ISR
#INT_TIMER1
void wave_timer() {   
   clear_interrupt(INT_TIMER1);   
   count++;
}


void main()
{
   int16 i = 0;
   
   //!initalization
   setup_adc_ports(sAN1|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);   
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_low_volt_detect(FALSE);
   setup_oscillator(OSC_32MHZ);                  //!oscillator freq is 32 MHz
   //setup_oscillator(OSC_64MHZ);                  //!oscillator freq is 64 MHz
   enable_interrupts(GLOBAL);                   //!enable global interrupt 

   while(1){
      count = 0;
      counter = 0;
     
      //!timer1 counter setup ...     
      setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);         //!setup timer
      clear_interrupt(INT_TIMER1);                    //!clear timer before use
      enable_interrupts(INT_TIMER1);   

      //delay_ms(1000);
      set_timer1(0);
      output_high(PIN_A3);
      delay_ms(6);
      output_low(PIN_A3);
     
      //delay_ms(50);
     
      counter = get_timer1();
      setup_timer_1(T1_DISABLED);
      delay_ms(100);
   }     
}

_________________
nehal
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Dec 11, 2008 2:49 pm     Reply with quote

It sure sounds like a debugger problem. Program a real chip and I bet the problem goes away.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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