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.

pic16f877 timer0 counter

Status
Not open for further replies.

lassy

Newbie level 4
Joined
Oct 6, 2004
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
53
pic16f877 counter

I have a simple question. How would I configure the TMR0 of the PIC16F877 to run on an external clock (32.786kHz). eventhough the chip will be running at 4MHz?or maybe even if it runs on the internal instruction clock cycle?how do i get the timer0 to produce an interrupt every 1 second?I am trying to implement a RTC using the timer0 counter.
please help!
 

timer0 pic16f877

Configurate the time0 module to use t0cki pin as time0 clock source
 

pic16f877 tmr0

16f877 has timer 1 why don't you use it???
it is dadicated tasks like that....
 

16f877 timer0

Hi,

Set this bits as folows:
Code:
TMR0IF = 0;
TMR0IE = 1;
GIE = 1;
OPTION = 0b11110111;
   TOCS = 1
   PSA = 0
   PS2:PS0 = 111
TMR0 = 0x80; // TMR0 = 1sec/prescaler/(1/32786Hz) = 128 = 0x80
Then every time you will get TMR0IF flag you will go the the interupt, there you will have to do:
Code:
if (TMR0IE && TMR0IF )
{
     TMR0IF = 0;  // Clear flag
     TMR0 = 0x80; // Reload TMR0 reg
}

Good luck.
 

tmr0 register

This is a replay to a PM that the user worte me. My answer was long and im sure some others whould want to read my explanation, so i posted it here

Hi,

First of all, if you think that i helped, then in the window where i wrote my answer any maybe in this one there is a buttom with Helped me writen on it. Please click that, so i will know that you did appritiate my help.

Regarding your questions:
what bits do i set within the INTCON register?
Ok, If you will look at the PIC16F87XA.pdf the you will see in FIGURE 14-10: INTERRUPT LOGIC the table what you need to enable inorder to get your interupt.
Also go to 2.2.2.3 INTCON Register and there you will see what bits you need to set on ( =1 ) and what you need to see off (=0 ).

also,if i want to use the 4MHz crystal i am currently using and trigger the timer using the internal instruction cycle=1us or 1mHz(if im not mistaken),how do i go about getting the clock to work as desired
If you will look at FIGURE 5-1: BLOCK DIAGRAM OF THE TIMER0/WDT PRESCALER in the data sheet then you will see what you need to turn ON or OFF for the clock to work from the internal 4MHz. BUT, you need to remember this. The internal clock needs to be divided by 4 { each instruction will be 1/( 4MHz / 4MHz ) }.
So lets say you will use the prescaler at max, thats 1:256 and using the internal clock at 4MHz then will get this timing:
4MHz/4MHz = 1MHz = (1 / 1MHz ) = 0.000001 Sec.
The TMR0 will incrament every prescaler * 1MHz = 256 * 0.000001 = 0.000256 Sec
To find out when you will get an interupt if you will load 0x30 to TMR0 register:
TMR0 max register - Var = 0xFF - 0x30 = 0xCF
Interupt = 0xCF * 0.000256 = 0.052992 Sec.
So, if you will load this settings, you will get an interupt every 0.052992 of the second when using the OSC of 4MHz.

Good luck.
 
  • Like
Reactions: mdarweesh

    lassy

    Points: 2
    Helpful Answer Positive Rating

    mdarweesh

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top