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.

timer0 delay differs from calculated value - anything missing?

Status
Not open for further replies.

bimalkamal

Member level 1
Joined
Nov 27, 2011
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,529
Please anyone tell me how many times in a minute the LEds of PORTB will blink? Or the delay time the mydelay() will create.


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
void mydelay();
 
 
void main() {
  OPTION_REG = 0x87;       // Assign prescaler to TMR0
  TRISB = 0;               // PORTB is output
  PORTB = 0xFF;            // Initialize PORTB
  TMR0  = 0;              // Timer0 initial value
    while(1)
            {
            PORTB = ~PORTB;
            mydelay();
    
            }
  
 
    }
    
 void mydelay()
 {
   unsigned int n=0;
  INTCON.TMR0IE=1;
  do{
  while(!INTCON.TMR0IF);
   n++;
       if(n==76)
   
             { TMR0IE_bit=0;
               n=0;
               INTCON.TMR0IF=0;
               break;
             }
             }while(1);
   }



---------- Post added at 00:21 ---------- Previous post was at 00:16 ----------

Crystal=20Mhz
 

You can achieve a precise answer by some simulation tools.
Take in mind that not only Scaler and Pre-scaler are accounted, but also amount of instructions processed before timer register reload.


+++
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top