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

help for use timer1 in external mode

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



Joined: 29 Aug 2010
Posts: 15

View user's profile Send private message

help for use timer1 in external mode
PostPosted: Tue Sep 04, 2012 8:02 am     Reply with quote

hello
I want to configure timer1 in external clock mode.
And the clock is provided by the 32.768 khz crystal.But it does not work.
I want to create accurate 1 second time with this crystal. Anyone can do to help me please.
1-what is problem ?
2-If i use this function (set_timer1(value)) for initialized this timer in
beginning of the program need not to use it in another line program?


Code:
#include <18f452.h>
#fuses HS
#use delay(Clock=20000000)
#include <stdio.h>

int time[3];

#int_TIMER1
void  TIMER1_isr(void)
{
time[0]=time[0]+1;
if(time[0]==60){
time[0]=0;
time[1]=time[1]+1;
}
if(time[1]==60){
time[1]=0;
time[2]=time[2]+1;
}
}



void main()
{
   
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_8);//start timer
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

while(true)
{
.
.
.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 8:08 am     Reply with quote

Code:


setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_8);//start timer


You are telling T1 to use an external clock input, but not telling it to feed the signal back out, to form an oscillator.....

Best Wishes
isv10



Joined: 29 Aug 2010
Posts: 15

View user's profile Send private message

PostPosted: Tue Sep 04, 2012 11:09 pm     Reply with quote

hi
So thanks.
In this case, I should use _t1oso and t1osi_ for connect crystal to 18f452 ???
and not need anything.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Sep 05, 2012 1:56 am     Reply with quote

Don't know where your underbar characters are coming from....
The pins are T1OSO, and T1OSI.

If you look at the data sheet, the oscillator has a nice little drawing.

T1OSCEN, is the setting T1_CLK_OUT
TMR1CS, is T1_EXTERNAL
Then the DIV_BY_xxx settings control T1CKPS0:1

The earlier settings were enabling the clock input, but not enabling the oscillator.

Best Wishes
isv10



Joined: 29 Aug 2010
Posts: 15

View user's profile Send private message

PostPosted: Wed Sep 05, 2012 1:57 pm     Reply with quote

Dear Ttelmah
Thanks for your guide. I realized that it should connect crystal to T1OSO and T1OSI and config timer1 like that and then i can use this timer:
Code:

setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);

And if i want to initialized the timer ,necessary use this function before main loop.
Code:

set_timer1(value);
isv10



Joined: 29 Aug 2010
Posts: 15

View user's profile Send private message

PostPosted: Wed Sep 05, 2012 2:06 pm     Reply with quote

Mr.Ttelmah
This project when it working ,Sometimes restart and i cant know what i do?
or send unknown character for lcd?
and A/D is not stable?
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Sep 05, 2012 2:34 pm     Reply with quote

This is an open forum. Generally you shouldn't address a problem to one person.

Most likely possibility - supply is not adequately regulated, or a poor ground.

Separate comment:

Quote:
And if i want to initialized the timer ,necessary use this function before main loop.
set_timer1(value);


No. The timer needs to be re-initialised, every time it overflows.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Sep 05, 2012 3:57 pm     Reply with quote

got a schematic to post?
that might point to your restart trouble

also just for fun

Very Happy Very Happy

Code:


unsigned int32 mytix,tix=0;

#int_TIMER1
void  TIMER1_isr(void){ ++tix;}
// then only when you want the time as H:M:S   

do{   mytix=tix; }while mytix!=tix;

time[0]=mytix%60;  // secs
time[1]=(mytix/3600)%60; //mins
time[2]=(mytix/86400)%24; // hrs

//



UNLESS this is a school project and a clock display is the only product - then the way you did it is going to obviously be OK 2 , as it mostly works now.

Very Happy Very Happy Very Happy Very Happy Very Happy
isv10



Joined: 29 Aug 2010
Posts: 15

View user's profile Send private message

PostPosted: Wed Sep 05, 2012 11:15 pm     Reply with quote

Thanks
1- Can I use set_timer1(value) in timer1 interrupts?
2- What means poor ground??
Code for A/D:
Code:

#include <18f452.h>
#fuses HS
#device ADC=10
#use delay(Clock=20000000)
.
.
.
setup_adc_ports(AN0_AN1_AN2_AN4_AN5_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_64);
.
.
.
set_adc_channel(1);                 
delay_us(15);                       
 for(j=1;j<=20;j++){             
 TT=TT+read_ADC();               
 delay_ms(1);                     
  }
TT=TT/20;
TT=(TT*4.882);
TT=(TT-1000)/3.86;
sensor1[1]=TT;
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