this
Member level 2
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:
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 } }