PIC TIMER CALCULATOR
Beta
Version 4
NB.
This is the beta version of this tool. If you find any errors or mistakes
please let me know by contacting HighcoPic on the Proton forum. Please dont
distribute until its proven to be correct! Code examples are based on the
Proton compiler from Crownhill and associates.
The
program was written using Easy Tools from www.easyvitools.com.
The whole program expands to under 1.6 Mb and doesn't alter Windows or add any
superfluous *.dll files. To remove the program, just delete the
folder\directory you installed it to.
Before
updating from an older version please delete the old version (directory\folder)
first.
REVISION LIST:
Beta Version 1 (23/04/05)
1.First
release
Beta Version 2 (29/04/05)
1.Slider
bars made larger to allow for finer mouse control.
2.Timer
frequency box and calculation added.
3.Timer0
Calculation modified to show proper 2 cycle delay if timer register wriitten
to, or loaded with a value other than 0.
Beta Version 4 (1/05/05)
1.Timer1
calculation corrected.
2.High
and low byte combined into single slider
3.Display
altered for bigger sliders
4.Code
example running for Timer0 and Timer1
5.Display
Code settings Button added
Download
the latest file by clicking on this link : Download PicTimercalcV4.zip
INTRODUCTION
The
Pic Timer Calculator will calculate the real time period of the various timers
associated with most of the PIC 16F series. No longer will you need to adjust
and load a PIC with your code to get the timer periods right, the Pic Timer
calculator will do that for you!

|
USER INSTRUCTIONS: Contents: 1. Timer Type 2. Oscillator Frequency 3. Timer Offset 4. Low/High Byte Offset 5. Prescaler Ratio 6. Post Scaler Ratio |
7. PR2 Offset 8. Instruct Cycle Time 9. Timer Period 10.Timer Frequency 11.Help 12.Display Code Example 13.Question\Answers\Problems |
1.
TIMER TYPE
Use
the "Timer Type" drop down box to select the timer you wish to
calculate. There are three Timers associated with the 16F series Pics and each
one has different features. These features will appear as you select the
required timer.
2. OSCILLATOR FREQUENCY
Set
the "Oscillator frequency" by enetering the freq. in the box in
megahertz. Frequencies accepetd are 0.000001 Mhz (1 hz) up to 999 Mhz. This is so
that external clock frequencies of any value can calculated.
The
default setting is 4 Mhz.
3.TIMER OFFSET
The
3 timers,(Timer0, Timer1, Timer2) are all readable and writable timers. This
means that you can load or offset a timer with a preset ammount, making the
timer period shorter than default. i.e. timer 0 counts from 0 to 255, sets its
rollover flag (which must be cleared in software) and counts again from 0 to
255. If you set the offset to, for example 100, the timer would count from 100
to 255, sets its rollover flag, you then load the timer in software with the
offset and it counts from 100 again.The above example is for timer 0.Adjust the
offset amount by moving the slider up or down with the up/down arrows for fine
steps or the mouse.
4.LOW BYTE OFFSET / HIGH BYTE OFFSET
Timer
1 has two registers, low and high, making it a 16 bit timer. (counts from 0 to
65535). Both of these are readable and writable as per above in "Timer
offset". By adjusting these values, very fine adjustments can be made to
the timing algorithim. As above, these values have to be loaded in software.
Adjust the offset amount by moving the slider up or down with the up/down
arrows for fine steps or the mouse.
5. PRESCALER RATIO
All
three timers have a pre-scaler. With the prescaler set to off or 1:1 the timer
increments on every clock instruction cycle. With the prescaler set to, i.e.
4:1, the timer increments once for every 4 clock instruction cycles. This
increases the timer period. Adjust the prescaler setting by moving the slider
switch up or down.
6.POST SCALER RATIO
The
post scaler is only available on timer 2. The post scaler operates on a similar
principal to the above, but occurs after the timer has rolled over, and
"post scales" the rollovers to the timer flag section. With it set to
4:1 for example, 4 "rollovers" would occur before the timer flag was
set.This increases the timer period. Adjust the prescaler setting by moving the
slider switch up or down.
7. PR2 OFFSET
Timer
2 has an 8 bit period register that is adjustable from 0 to 255. You can set
this so that the timer counts up to the PR2 value, then rolls over.i.e. setting
this to 100 , the timer would count from 0 to 100, then rollover back to
0.Adjust the offset amount by moving the slider up or down.
8. INSTRUCT CYCLE TIME
This
displays the instruction cycle time and is dependant only on the Oscillator
Frequency. Higher the frequency, quicker the instruction cycle time.
9. TIMER PERIOD
This
displays the timer period result after setting/selecting the required
parameters. Occurs instantly so you can see the effects of changing the
register settings.
10. TIMER FREQUENCY
This
displays the number of times the timer "flags" or "rolls
over" per second. (i.e. hertz). This is usefull for working out accurate
timer durations while adjusting the values.
11. HELP
Displays
the help window with this text that you are reading now. Click again to hide
the help window.
12. DISPLAY CODE EXAMPLE
Displays
a sample of code that uses the settings that you have selected in the Pic Timer
Calculator. This code can be cut and pasted into your Proton compiler.
13. DISPLAY CODE SETTINGS
Displays
as code the settings that you have selected in the Pic Timer Calculator. This
code can be cut and pasted into your Proton compiler.
14. QUESTION\ANSWERS
Q.Timer
0 calculation is out by 2?
A.
This is correct. In 16F series Pics, Timer 0 has a 2 count delay if written to
or if the prescaler is changed. If this is a problem, adjust it by two in your
code. Timer 1 & 2, as far as I can see, dont have this problem.
Q.
The timers have different pre-scaler settings.Is this correct?
A.
Yes, this is correct (check data sheets for the device you are using)