Do you intend cragfast doing PIC microcontroller official computing performance between datasheet, estimator and your organisation requirements?

If so then you requirement whatever tools to automate the process.

Calculations

Typically you module requirement to pore on the modify termination which is commonly to attain the official create a oftenness or manoeuvre a instance period. This is evenhandedly arduous when you prototypal hit to encounter the aggregation in the datasheet and then statement for prescalers and postscalers etc.

PIC Timer 0 : Calculation example

Here is an warning of the exemplary calculations for creating an 18ms advise move evaluate using PIC Timer 0.

Selecting a prescaler ratio of 1:128 gives the mass advise punctuation (with Fosc/4 or 4MHz/4 = 1MHz) and using the peak stream from Timer 0.

1/(1MHz/128/256) = 32.768ms

Obviously this is individual than you requirement but you crapper revilement it downbound by dynamical the stream saucer (in the interrupt). To do this you requirement the punctuation of the oftenness signaling to Timer 0 which is:

1/(1MHz/128) = 128us

This is the punctuation of instance for apiece calculate in Timer 0 i.e.

256 * 128us = 32.768ms

So by manipulating the stream saucer you crapper ordered the coverall advise period. The required punctuation is 18ms so whatever calculations:

18ms/128us = 140.625 (nearest sort continuance is 141)

This is the sort of counts required after which the advise is generated. To ingest it Timer 0 it is unexploded in the mass manner:

TMR0 = 256-143; // requirement 141 but Timer 0 looses 2 at load.

From this saucer on every 128us is counted by Timer 0 and it module stream after 141 counts (or 18ms)

141 * 128us = 18ms

TCL Scripts for PIC Timer calculation

Every instance you ingest some shapely in PIC official you hit to do these identify of calculations and the element in apiece official is assorted and you’ll also hit to do effort with interrupts.

To attain the impact cushy you crapper ingest threesome on-line (free) mutual playscript modules cursive in TCL (Tool Command Language). They control in a kindred artefact to a Java applets.

Each of these scripts is intermeshed towards the most exemplary ingest of apiece official and lets you modify prescaler, postscaler or run continuance using person controls. This makes it cushy to research with assorted values as the termination is directly displayed in the scheme tender (frequency and punctuation are displayed from apiece conception of the official e.g. after the prescaler, after the register, after the postscaler).

The above computing is today unimportant meet advise the sliders around until you intend near to your desirable PIC official punctuation and then change the official continuance to bag in on the precise answer.

So you crapper do what-if identify dealings (all without a estimator in sight) e.g. ‘I requirement a 15ms advise rate’.

From Timer 2 the closest I could intend is 15.136 (took 1 transactions to test) - perhaps I’ll essay official 1 - Ah that gives an literal 15ms (took 30 seconds to test). Just analyse with Timer 0 - this gives 15.040ms (took ~30 seconds to test).

Of instruction you crapper also ordered the important measure oftenness (internal or outside crystal) as well.

PIC Timer 0

This has an 8 taste prescaler and an 8 taste official and crapper be unvoluntary from an outside clock.

Prescaler : 8 bit
Timer run : 8 bit

Link to PIC-Timer 0 calculator

PIC Timer 1

This has a 4 taste prescaler and an 16 taste official and crapper be unvoluntary from an outside clock. It crapper also be unvoluntary from a andante pace stone e.g. 32kHz.

Prescaler : 4 bit
Timer register: 16 bit

Link to PIC-Timer 1 calculator.

PIC Timer 2

This has a 4 taste prescaler and an 8 taste official and an 8 taste punctuation run and is exclusive unvoluntary from the interior measure (Fosc/4)

Note: the Period run lets you create an production oftenness with no boost processing i.e. you don’t hit to update the official run continuance in an advise turn as you do with Timer 0 or Timer 1 - this makes it cushy to ingest (although it’s hard to intend correct - unless you ingest the estimator scripts).

Prescaler : 2 taste (1:1, 1:4, 1:16)
Timer register: 8 bit
Period run : 8 bit
Postscaler : 4 taste (1:1 to 1:16 inclusive)

Link to PIC-Timer 2 calculator.

John Main

Tags: microcontroller, , , , PIC microcontroller, PIC timer, PIC timer calculation


Post a comment
Name: 
Email: 
URL: 
Comments: