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

problem with timer1 and external signal

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







problem with timer1 and external signal
PostPosted: Mon Dec 11, 2006 5:14 pm     Reply with quote

I have a 32.768 Khz crystal (Digi Key # X802-ND) and (2) 33pf caps connected to T1OS0 and T1OS1 pins on a 16F877A. I preload timer1 and expect the timer to roll over every sec. This is not happening. I checked the clock signal with a scope and there is nothing there. I have setup timer1 both with and without sync and nothing changes.

Here is a segment of the code.



#int_TIMER1
TIMER1_isr()
{
++second_cnt;
bit_set(flag,1); // set update flag bit
set_timer1(timer_preload);
TMR1IF_BIT = 0;
output_high(digit1_power);
delay_ms(20);
output_high(dig_a_off);
delay_ms(150);
output_low(dig_a_off);
delay_ms(150);
output_high(dig_a_on);
delay_ms(150);
output_low(dig_a_on);
delay_ms(150);
}

void main()
{

long int batt_timer = 0;


set_tris_a (0x11); // 2 inputs, 3 outputs 0x11
set_tris_b (0x01); // 7 outputs, 1 inputs
set_tris_c (0x07); // 3 inputs, 5 outputs, RC7 output, RC6 output for LED
set_tris_d (0x10); // 1 inputs, 7 outputs
set_tris_e (0x00); // 3 outputs

output_a (0x00); // set I/O pins at low state
output_b (0x00);
output_c (0x00);
output_d (0x00);
output_e (0x00);

setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1); //_SYNC

flag = 0; // initialize flags
if(!input(digit_config)) // check for jumper, if shorted config for 4 digits
bit_set(flag, 3); // set flag for 4 digit configuration

set_digits(0,0,0,0); // initialize digits to "0"

set_timer1(timer_preload); // preload timer1
enable_interrupts(INT_TIMER1); // enable timer interrupt
TMR1IF_BIT = 0;



enable_interrupts(global); // timer is started

while(1) // continuous loop
{
delay_ms(100);
}



Could someone tell me what I have missed or where the problem could be?


Thank you,
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Dec 11, 2006 5:47 pm     Reply with quote

try taking off the caps.
I think the cap is built into the PIC or can crystal..
read section "6.5 Timer1 Oscillator" pg 61 and note 1,2 near by.

Also is the T1OSCSEN bit set?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 11, 2006 6:00 pm     Reply with quote

I think the problem is your Timer1 setup. The demo program at
the following link shows how to do it so the Timer1 oscillator is enabled:
http://www.ccsinfo.com/forum/viewtopic.php?t=28158&start=8
Ttelmah
Guest







PostPosted: Tue Dec 12, 2006 3:10 am     Reply with quote

As another comment, unless you are using 'fast_io', _all_ the pins of the chip, will be set as outputs, with what you are doing.
It is key to understand, that in 'standard_io' mode, the compiler will change the TRIS for you, reflecting what you ask it to do. Now after your TRIS statements, you perform port wide outputs on all the ports, which will result in the compiler at this point setting all the pins as outputs...

Best Wishes
KLCL
Guest







PostPosted: Tue Dec 12, 2006 6:35 pm     Reply with quote

Thanks for all of the suggestions and feedback. I have tried all and still have the same problem. Any other ideas?

Thanks,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 12, 2006 6:40 pm     Reply with quote

Post your compiler version. This will be a number such as 3.249 or
4.018, etc. You can find it at the top of the .LST file, which will be in
your project directory.
klcl
Guest







PostPosted: Tue Dec 12, 2006 8:59 pm     Reply with quote

I located the problem. Bit 3, T1OSCEN has to be set to enable the oscillator. Timer1_setup() does not set this bit. Once it is set the interrupt works with the external crystal.

Thank you all for the input.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 12, 2006 9:36 pm     Reply with quote

It does, if you use the correct parameters as shown in the thread
that I linked. If you add the T1_CLK_OUT parameter, then bit 3 of
T1CON is set.

Without T1_CLK_OUT:
Code:
... setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1); 
0048:  MOVLW  87
0049:  MOVWF  T1CON


With it:
Code:

... setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT); 
004A:  MOVLW  8F
004B:  MOVWF  T1CON
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