Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

PIC18F45K80 Timer 0

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,016
Helped
4,041
Reputation
8,082
Reaction score
3,955
Trophy points
113
Activity points
118,955
Hi,

T_max = fixed_prescaler x max_selectable_prescaler x 2^counter_bit_width / fosc

Klaus
 

Djsarkar

Member level 2
Joined
Jul 27, 2020
Messages
52
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
286
Hi,

T_max = fixed_prescaler x max_selectable_prescaler x 2^counter_bit_width / fosc

Klaus
Fixed prescaler _ five bit
2^counter_bit_width / fosc =2^8/20 MHz

What would be max_selectable_prescaler?

Is the input frequency 20MHz for Timer 0?
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,016
Helped
4,041
Reputation
8,082
Reaction score
3,955
Trophy points
113
Activity points
118,955
Hi,

What would be max_selectable_prescaler?

Is the input frequency 20MHz for Timer 0?
If I needed to know this .. have have to read the datasheet.
But you don´t want me to read the datasheet for you?

Klaus
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,382
Helped
279
Reputation
558
Reaction score
268
Trophy points
1,363
Location
France 01800
Activity points
9,669
hello,


look at the mikroE tool for Timer

18F timer0 16bits -> maxima is 3355mS with prescaler 1/256
or with an excel sheet
with prescaler 1/8 -> divide by 32
 

Attachments


    Djsarkar

    points: 2
    Helpful Answer Positive Rating

Djsarkar

Member level 2
Joined
Jul 27, 2020
Messages
52
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
286
Hi,

T_max = fixed_prescaler x max_selectable_prescaler x 2^counter_bit_width / fosc

Klaus
I don't understand your formula

lets assume Timer 0 with 8 bit prescale , fosc = 2 Mhz

fixed_prescaler = 1 : 32
max_selectable_prescaler = 1:256


2^counter_bit_width/ fosc = 2^8/ 2000 000 = 256/ 2000 000 = 0.000128


T_max = 1/32 * 1/256 * 0.000128 = 0.03125 * 0.00390625 * 0.000128 = 0.000000015625
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,016
Helped
4,041
Reputation
8,082
Reaction score
3,955
Trophy points
113
Activity points
118,955
Hi,

I did not verify your values..I just use them:

What I meant is:
T_max = 32 * 256 * 0.000128s = 1.048s
 

Djsarkar

Member level 2
Joined
Jul 27, 2020
Messages
52
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
286
Hi,

I did not verify your values..I just use them:

What I meant is:
T_max = 32 * 256 * 0.000128s = 1.048s
I want to verify time

Fosc/4 with an 8MHz clock, that is 2MHz.

I have attached page From datasheet max_selectable_prescaler = 1:256

and I am setting fixed_prescaler = 1 : 32
 

Attachments

Last edited:

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,016
Helped
4,041
Reputation
8,082
Reaction score
3,955
Trophy points
113
Activity points
118,955
Hi,

A fixed prescaler is fixed, thus and can´t be "set". Some microcontroller have, some don´t. I´m not familiar with your microcontroller. Read the datasheet.

You may set the "selectable" prescaler to 1:256.

Klaus
 

Djsarkar

Member level 2
Joined
Jul 27, 2020
Messages
52
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
286
Hi,

A fixed prescaler is fixed, thus and can´t be "set". Some microcontroller have, some don´t. I´m not familiar with your microcontroller. Read the datasheet.

Klaus
Thanks K, I have looked datasheet I don't think there is fixed prescaler option available
 

Djsarkar

Member level 2
Joined
Jul 27, 2020
Messages
52
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
286
Hi,

I did not verify your values..I just use them:

What I meant is:
T_max = 32 * 256 * 0.000128s = 1.048s
8 bit Timer with 1:256 Prescale value

T_max = 256 * 0.000128s = 0.0032768s

We need to load value into the TMR0 registers (low 8 bits into TMR0L and high 8 bits into TMR0H).

What would be timer register value for 0.0032768s ?
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
18,016
Helped
4,041
Reputation
8,082
Reaction score
3,955
Trophy points
113
Activity points
118,955
Hi,

I can´t answer without reading the datasheet.
I tried, but now I recognize that in the headline you talk about PIC18F45k80, but the uploaded page is from PIC18F66K80.

So I opened PIC18F66K80 datasheet...and Fig. 13-1 and Fig. 13-2 clearly shows "Fosc/4" as clock input. Which is a fixed 1:4 divider.
Fosc never - undivided - comes to the counter.

Klaus
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,382
Helped
279
Reputation
558
Reaction score
268
Trophy points
1,363
Location
France 01800
Activity points
9,669
hello,

see post#7 !

What would be timer register value for 0.0032768s ?
=> 3 276,8 µS

Code:
//Timer0  16bits !
//Prescaler 1:1; TMR0 Preload = 49151; Actual Interrupt Time : 3.277 ms
void InitTimer0(){
  T0CON     = 0x88;
  TMR0H     = 0xBF;   //191
  TMR0L     = 0xFF;   /255
  GIE_bit     = 1;
  TMR0IE_bit     = 1;
}
i did not see any Postscaler for Tirmer0 ...so

20MHz --> 4/20= 0.2µS per cycle
TMR0 value= (0xBF<<8) +255 = 48896 + 255 = 49151
(65536-49151) *0.2 = 3276.8µS
 

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top