Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to connect xtal to T0CKI pin on PIC

Status
Not open for further replies.

this

Member level 2
Joined
Apr 14, 2011
Messages
44
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,623
Hi.
Problem: I need precise clock.
I have a 32768Hz xtal. I know I have to set prescaler to 1:128, and timer interrupt will be called on every overflow of 8bit timer(every 256 ticks), so I will get my precise 1s interrupt(32768/128/256 = 1).
This is clear for me, and I believe I have no problem with programming part.
I think the problem is with connecting xtal to T0CKI pin.(I tried few xtals, so it's not xtal fault)
I was trying to connect it like shown on 13 page of **broken link removed** but it's very unstable, sometimes it's way slower than 1s, sometimes it runs like crazy.
Could someone explain to me what is the proper way of connecting xtal to T0CKI? I would appreciate explanation of what and why.

Currently I have the circuit mentioned above(except i have two 2x22pF caps instead of 33 and var.)
I'm using PIC16F677
My code looks like this:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
TRISA = TRISB = TRISC = 0; //output only
    ANSEL = 0;// digital IO
    ANSELH = 0;// digital IO
        
    OPTION=0b10100110;
    //       1-------   pullups disabled
    //       -0------   
    //       --1-----   TMR0 source = transition on T0CKI
    //       ---1----   increment on L2H T0CKI
    //       ----0---   prescaller assigned to TMR0
    //       -----110   prescaller 1:128
    
    T0IE = 1;   //enable TMR0 interrupt
    GIE = 1;    // enable gloabl ints
    unsigned volatile char cnt=0;
    ......
    
    while(1)
    {
        lcd_clear();
        lcd_goto(0);//clear lcd
        display_on_lcd(cnt);//and display
        for(unsigned char i = 0; i<3;i++)//wait ~100ms
            __delay_ms(33);
    }
    
    .......
    
    
    void interrupt isr(void)
    {
        if(T0IF)//if timer interrupt
        {
            cnt++; //increase "stopwatch"
            T0IF = 0; //clear int. flag
        }   
    }

 

hi

please read the datasheet of 16F677,and check what's missing.

ml
 

Well, I did read it before I started, what did I miss? Some hint? page# or something :)
And small correction to my code - T0CKI is actually set as input, not output.
 

hi

TRISA = TRISB = TRISC = 0; //output only
ANSEL = 0;// digital IO
ANSELH = 0;// digital IO

OPTION=0b10100110;
// 1------- pullups disabled
// -0------
// --1----- TMR0 source = transition on T0CKI
// ---1---- increment on L2H T0CKI
// ----0--- prescaller assigned to TMR0
// -----110 prescaller 1:128

T0IE = 1; //enable TMR0 interrupt
GIE = 1; // enable gloabl ints
unsigned volatile char cnt=0;
bit test = 0; // display update when test == 0
......

while(1)
{
if(test == 0){
lcd_clear();
lcd_goto(0);//clear lcd
display_on_lcd(cnt);//and display
test = 1;
}
}

.......


void interrupt isr(void)
{
if(T0IF)//if timer interrupt
{
cnt++; //increase "stopwatch"
test = 0;// update display
T0IF = 0; //clear int. flag

}
}


you may change the crystal. may be this is the problem of the crystal too

regards

ml
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top