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

Timer1 overflow and counter problem

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



Joined: 25 Apr 2006
Posts: 2
Location: Venezuela

View user's profile Send private message

Timer1 overflow and counter problem
PostPosted: Tue Apr 25, 2006 7:19 am     Reply with quote

I have a simple circuit wuith a 12F675 like a 300Hz. pulse generator, a LCD and a PIC16F688 like counter.

I have this program code in PIC16F688 for counter 500 pulses and stop the pulse generator (MCLR of 12F675) and show the counter in a LCD.
The problem is:
The counter do not stop at 500 pulses, its answer is erratic, sometimes is 545, other is 525, Confused ...but, if I erase all program lines with delay_ms and replace this for a 'for cycle' it work good. Smile

I use another PIC like counter, 18F252 and is the same.

Some ideas? Idea
why delay routine affects timer1 overflow interrupt? Question
Which is my error? Question

#include <16F688.h>
#device adc=8
#use delay(clock=8000000)
#fuses NOWDT,INTRC_IO, NOPROTECT, BROWNOUT, NOMCLR, NOCPD, NOPUT, IESO, FCMEN
#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8)


#define Led pin_A0
#define Stop pin_A1


int16 Counter;


#int_TIMER1
TIMER1_isr()
{output_low(Stop); //Reset 12F675 (300 Hz generator)
delay_ms(100);
output_high(Stop); //Enable 12F675
delay_ms(100);

Set_Timer1(65036); //Set timer1 for overflow interrupts after 500 Pulses
}



void main()
{setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_EXTERNAL_SYNC);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator( OSC_8MHZ );

output_high(Stop); //Enable 12F675

delay_ms(1000);

Set_Timer1(65036); //Set timer1 for overflow interrupts after 500 Pulses

putchar(254); // LCD command
putchar(254);
putchar(128);

printf("(Active)"); //LCD Ok

enable_interrupts(INT_TIMER1);
enable_interrupts(global);


while(True)
{output_low(Led);
delay_ms(300);
output_high(Led);
delay_ms(300);

Counter= get_timer1();
putchar(254); // LCD command
putchar(192);
printf("%lu", Counter); //Show in LCD Counter Value
}



}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 25, 2006 11:09 am     Reply with quote

You are using delay_ms() inside your timer isr and other places
in your program, so read this post for the solution:
http://www.ccsinfo.com/forum/viewtopic.php?t=25631&start=5
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