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.

1 sec timer with PIC16F877A

Status
Not open for further replies.

jigarpatelp

Junior Member level 2
Joined
Aug 27, 2014
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Vadodara,Gujarat,India
Activity points
132
Hello

working with calender application and got a problem with timer.

I want to generate 1 second timer interrupt using any timer .
I'm using PIC16F877A,mikroC PRO and Proteus.

Please help.
 

if you search the forum for PIC16 timer you will get plenty of links

also have a look at Microchip's code examples
**broken link removed**
 

this code may help it is for a Microchip mechatronics trainer using a PIC16F917
Code:
volatile int tenMillSecCounter=0;               // incremented every 10mSec
static volatile int tenMillSecCounter2=0;       // incremented every 10mSec - used for delays
static volatile int revolutionTimer=0;          // used for counting revs/min or motor
volatile int tenthsSecond=0;                    // incremented every tenth of a second
volatile int second=0;                          // incremeneted every second

// Timer 0 is programmed to interrupt every 10mSeconds
//  T0 clock is FOSC/4 = 200000
//  with 256 prescaler decrements 2000000/256 times / second
//  to get an interrupt every T mSec the calculation for TMR0 overflow from 0xFF to 0 is
//    count = 255 - T * 2000/256
//    i.e. for 10mSec counter is
#define tenMillSec 177
static void interrupt isr(void)
{
    if (T0IF)                           // A TMR0 interupt occurred
    {
        TMR0=tenMillSec;                // increment counters every 10 mSec
        tenMillSecCounter2++;
        revolutionTimer++;
        if((++tenMillSecCounter % 10)==0) tenthsSecond++;
        if((tenMillSecCounter % 100)==0) { second++; tenMillSecCounter=0; }
    }
    T0IF=0;                             // clear TMR0 interrupt flag
}

// delay for count tenths of a second
void tenthsSecondDelay(int count)
{
    tenMillSecCounter2=0;                         // zero counter
    while( tenMillSecCounter2  < (count*10)) ;    // wait
}
        
// delay for count seconds
void secondDelay(int count)
{
    tenMillSecCounter2=0;                         // zero counter
    while( tenMillSecCounter2  < (count*100)) ;   // wait
}
        
// initalise clock, set port A for digital input, set up timer 0, etc
void systemInitialise(void)
{
        OSCCON=0x70;             // Fosc use oscillator 8MHz
        ANSEL=0;                 // set digital inputs
        // PORTB PULL-UP DISABLED, TMR0 Timer mode Clock Source Select bit FOSC/4,  
        // Prescaler is assigned to the Timer0 module & TMR0 RATE 1:256
        OPTION=0x87;             
        TMR0=tenMillSec;         // initialise timer 0 counter
        T0IE = 1;                // enable interrupt on TMR0 overflow from 0xFF to 0
        GIE = 1;                 // Global interrupt enable
 }
 

* Timer Delay Calculations:
1. Crystal Source Frequency Fosc
2. Timer Frequency Fcy = Fosc / 4
3. Prescalar then
Ftimerpre = Fcy / scalar value
4. Time Interval, Ttimer = 1/Ftimerpre
5. To calculate the value to be filled in Timer rolling over
register to generate 10m sec delay :
No of count for 10 msec delay = 10 ms / Ttimer = x
PR1 = x;
 
i build time laps station to one of my friend, for this i needed a 1 second interrupt
i used a real time clock ds1307 he save time and data and work separately form the mcu, you can read when ever you like and the time is very accurate.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top