View previous topic :: View next topic |
Author |
Message |
KLCL Guest
|
problem with timer1 and external signal |
Posted: Mon Dec 11, 2006 5:14 pm |
|
|
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, |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Dec 11, 2006 5:47 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Dec 12, 2006 3:10 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
KLCL Guest
|
|
Posted: Tue Dec 12, 2006 6:35 pm |
|
|
Thanks for all of the suggestions and feedback. I have tried all and still have the same problem. Any other ideas?
Thanks, |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 12, 2006 6:40 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
klcl Guest
|
|
Posted: Tue Dec 12, 2006 8:59 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 12, 2006 9:36 pm |
|
|
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
|
|
|
![](templates/subSilver/images/spacer.gif) |
|