PDA

View Full Version : Change Timer settings?



brodin
- 30th September 2003, 18:23
How do i change the internal Timer settings? I need to make the ticks occur more often than every 16.384 ms.

I am building a stopwatch that is going to show the time like xx:xx:xx (minutes, seconds, hundreds of a second).
It would be perfect with a tick every 10 ms or less.

I have read that it should be possible to change the "prescaler". Don't really know what it means though...



Is there any more manual than the original PBP manual from MEL? I would like some with more information. Or is there any good internet site?

Melanie
- 30th September 2003, 21:21
Download the Datasheet for the PIC that you're using. Read the Timer sections, they explain in detail how the timers work. Your timer tick will depend on the oscillator frequency (Xtal) that you've set for your PIC.

At 4MHz, the timers tick every 1uS. The smallest tick therefore is 1uS. The longest tick depends on a number of factors... Timer0 is an 8-bit Timer, giving a maximum of 255uS (@ 4MHz), Timer1 and Timer2 (if you have them) are 16-bit timers. Interrupts and Flags get set when the Timers roll from $FF ($FFFF) back to zero. By presetting the Timer Registers you can have them count up from whatever preset value you want. Additionally, pre and post scalers are available (depending on your PIC) to extend the range of the timers. Again consult your Datasheet.

The BEST manuals (other than MEL's PBP one) are actually the manufacturers product Datasheets for what you're using. I can't stress enough that you should study them. It's pretty much all that I use, and what every professional engineer uses.

Melanie

brodin
- 30th September 2003, 21:30
I have read the datasheet for my 16F84. But i still don't know how to change the values of the prescaler in PBP.

I mean, what command should i use? Is it a DEFINE command? Or do i have to make this in ASM?

Melanie
- 1st October 2003, 07:52
Just address the Registers by name directly... for example... you want to access Timer0 prescaler... Bits 3 thru 0 of the OPTION_REG Register do that.

By default, Timer0's prescaler is assigned to the WDT, to reassign it to Timer0 execute the instruction...

OPTION_REG.3=0

Any register can be accessed directly by name just as if it was a variable... so TMR0 can be preset...

TMR0=$2F

Timer0's overflow flag can be checked like this...

If INTCON.2=1 then ****

The only thing you have to remember is that some Registers are used for multiple functions... so setting Timer0's prescaler to 1:256 with this command OPTION_REG=7 is not advised, as bits 4 thru 7 have just been set to zero will affect other completely unrelated things. It's better to do it bit-by-bit like this...

OPTION_REG.2=1
OPTION_REG.1=1
OPTION_REG.0=1

...unless you are knowingly setting all eight bits of the port in one hit. That way you're unlikely to inadvertantly set or reset other register bits.

The PBP manual told you and gave examples of how to access PIC Registers in several places (4.10 Ports and other Registers) is just one such place.

Melanie

Mrfarag
- 18th August 2012, 17:52
plz I want avery simple program for making a clock on lcd and an explnation of it

mackrackit
- 18th August 2012, 18:35
http://www.picbasic.co.uk/forum/showthread.php?t=632