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.

single stepping increment a 16bit Timer

Status
Not open for further replies.

hhhsssmmm

Member level 1
Joined
May 14, 2009
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,732
Hello

I have PIC18F2420 running via 4MHz ceramic resonator....and the compiler is used C18.

I can single step increment TMR0 (8bit mode) just by changing TMR0L regsiter value from 00 - FF. So lets....

TMR0L = 0;

So i can change the TMR0 interrupt every single step just by the command TMR0L++...(that is from 256us all the way to 1us).

Now my question is, how can i perform similar single stepping for a 16bit timer? Im confused and therefore im asking since 16bit timer has two registers to initiallize....for example for timer1 is initiallized from 5ms and you wish to single step it by incrementing it to 10ms....we have...

5ms intiallized TMR1
-----------------------
TMR1L = 78;
TMR1H = EC;

.....so from here how would you, in a similar 8bit fashion, single step a 16bit timer all the way to 10ms?


Please can some one help me here?

thank you
haseeb
 

I think you have misunderstood the actual point of the Timer. You don't have to increment it yourself, it is done automatically. If you set up the timer as a counter, it will increment itself on every CPU instruction cycle.

So, if you did:


TMR0L = 0;
NOP
NOP
NOP
NOP

The value of TMR0L will now be 4 because you've done 4 instructions.

You can prescale the Timer so it counts every second, fourth, 8th, .... 64th .... 256th instruction. Once it goes over the top (and re-starts) it generates an Interrupt.

With the PIC18Fs you also have the CCP module which can actually generate an interrupt once the Timer value is equal to the pre-selected value in CCP special function registers. So, instead of having an interrupt on 65535 instruction cycles, you can make it generate an interrupt on a nice round figure of 50.000 instructions cycles, making timing much easier :)
 

thank you for replying.

ok i understand your point.

But suppose i needed to increment the 16bit timer after every 10ms INT....how would you do this?....let me explain further...

suppose i had a interrupt generated on INT0 at every 10ms. So in the INT0 ISR, i would like to re-initialize the 16bit timer and have it increment from 5ms....then on the next INT0 increment from 6ms....then on the next INT0 increment from 7ms etc...all the way to 10ms...then reset back to 5ms again on the next INT0.....meaning changing the timer initiallization value at every INT0 interrupt once only.

I know how this can be done by just plenty of if else statements and i can write the desired timer values in these statements....but i want it so that it is similar in operation as doing it with and an 8bit timer....

for 8bit timer, suppose i increment a variable bulb++ at every 10ms (INT0)
In the INT0 ISR i then assign the bulb variable variable to timer0 as.....

TMR0L = bulb;

this will reinitiallize the timer0 to the new value instead of me having to calculate and write a desired value in the TMR0L my self.

So do you follow me?.......in the 8-bit timer similar manner I wish to increment a 16bit timer as well.

How can this be done?

Haseeb
 

If you just need to increment a 16 bit value, why not declare a variable (don't use timer at all) and increment that variable every time the desired event occurs?


You can also set up the timer so that it counts pulses on a specific pin, instead of counting instruction cycles.
 

use auto reload feature of the timer.
or else write ans ISR which will reload the desired value at the end of downcount.
BTW timers are design to downcount. so your reload value must be FF-count and FFFF -count. you can also specify it with a -sign.

hcok

Added after 3 minutes:

enjoy this program.

hock
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top