Page 1 of 3

PIC Timer Calculator - free - Betatesting

Posted: 03 Jul 2008 21:53
by Kia
Hi, i've made a tool for calculating timer offsets and so. Maybe somebody can check it and give some feedback.
If postive feedback i can enable more features.

Image

Please mail me for any hint or error.

Free Download at: http://pictimer.picbingo.com

Posted: 03 Jul 2008 22:12
by Jan Rune
Una idea muy buena Kia :!:
That is a excellent way to understand how the timers work. And it is a useful tool for ppl that just need to configure their timers. I will give it a try soon :D

Posted: 03 Jul 2008 23:18
by Raslan
Well done.
Suggestion:
It is good idea to include list of oscillator options like:
HS = Freq/4 (as you have implemented this one)
PLL-HS = Fre x 4
and so on

Br,
Raslan

Posted: 04 Jul 2008 10:20
by Dany
Wow!
Very nice, very usefull! :D
Saves a lot of calculation work and reduces very much the # errors with timers.

Thanks! :D

Posted: 04 Jul 2008 11:52
by AjK
great Work :)

Posted: 04 Jul 2008 12:45
by Acetronics
Hi,

The downloaded last release shows " not a valid win 32 app" :? ... normal ???

only works "on line" ...

Suggestion: TMR1 with 32768 Hz Xtal as a source for RTC applications ...

Alain

Posted: 04 Jul 2008 14:46
by Kia
Thx for reply.

Maybe there is some confusion: You can enter any valid frequency in the frequency field. I've updated the selection fields with a new "Other" option. Also, you can disable Fosc.
The downloaded last release shows " not a valid win 32 app" ... normal ???
Don't know where the problem is. Use the Setup.exe.

Regards
Ronald

Posted: 04 Jul 2008 14:52
by Acetronics
Hi,

"Setup" runs fine ... but it's a very older release with much less features ! ( V1.0.8 ) no language options nor core options ...

Alain

Posted: 04 Jul 2008 16:05
by janni
Very good work, indeed :D .

Nice touch with the Timer0 two instruction cycles count inhibit. It should take into account the prescaler, though. And Timer 1 and 3 also have their pecularities if reloaded 'on the fly'.

Usually, it's better to stop the timer while reloading it in ISR. You could implement the "dead time" for timer update in ISR (like in Mister E's PicMultiCalc http://www.mister-e.org/pages/utilitiespag.html).

Another problem is the ISR overhead. If one simply reloads a timer, instead of adding to it, the interrupt frequency will be reduced because of the overhead caused by interrupt latency and all the code between the start of ISR and the place where timer is actually reloaded. This overhead could also have an editable field in your program.

BDW, what is the "Search interrupt configuration" for?

Posted: 04 Jul 2008 21:03
by KM6VV
Not really following all your calcs.

I have a PIC18F4620, 40Mhz HSPLL, my interrupt frequency is 2500 uS.

Code: Select all

	    /* Initialize TRM0 (in T0CON) */
TMR0ON = 1;   /* Timer0 1 = on */
T08BIT = 1;     /* Timer0 8 bit  = 1 */
T0CS   = 0;	/* Timer0 0= internal clock, 1= T0CKI pin */
T0SE   = 0;	/* Timer0 1=inc on H to L transision, 0= L to H */
PSA    = 0;	/* Timer0 prescaler asigned	*/
T0PS2  = 1;    /* 3 bits for prescale, 111 = 256 prescale */
T0PS1  = 1;
T0PS0  = 1;
You'll see that PSA =0.

What is interrupt every 4.096 mS?

Interrupt frequency at 402 Hz = my 2500 uS

Nice idea, I try to build calculations into my header file to do this stuff.

Code: Select all

#define XTAL                   40000000	/* crystal frequency - 40MHz  */
#define RECIPRICAL_uS 	1000000	/* RECIPRICAL of 1 uS period */
#define ICLK		       (XTAL/4)	/* crystal is divided by four */
#define INT_PERIOD        2500	    /* period of T0 interrupt in uS */

#define	PRELOAD_TMR0 (256 - ((INT_PERIOD * (ICLK / RECIPRICAL_uS) / SCALE)))
PRELOAD_TMR0 = 159

16 bit timer works something like this:

Code: Select all

#define PRELOAD_TMR0 (65536 - (INT_PERIOD * ICLK / SCALE / RECIPRICAL_uS) + 2)
#define PRELOAD_TMR0L (PRELOAD_TMR0 & 0xFF)
#define PRELOAD_TMR0H (PRELOAD_TMR0 >> 8)
A little more to it then that to build for multiple clock speeds and uP, but you get the idea. I'm still working on it.

Nice idea, 'tho. Hope you can get it ironed out, it would be very useful.

Alan KM6VV

Posted: 05 Jul 2008 23:48
by Kia
Hi,
KM6VV wrote:
Nice idea, 'tho. Hope you can get it ironed out, it would be very useful.
thanks for the hint. Error is fixed and other minor things.
(picture updated)
Usually, it's better to stop the timer while reloading it in ISR. You could implement the "dead time" for timer update in ISR (like in Mister E's PicMultiCalc http://www.mister-e.org/pages/utilitiespag.html).

Another problem is the ISR overhead. If one simply reloads a timer, instead of adding to it, the interrupt frequency will be reduced because of the overhead caused by interrupt latency and all the code between the start of ISR and the place where timer is actually reloaded. This overhead could also have an editable field in your program.
*Implemented - good idea :D

And i made a new installer (easy setup)
Now i'm working on the source code examples. Hope they will soon finished.

Thanks to all.

Ronald

Posted: 10 Jul 2008 20:51
by Dany
Hi,
In the version 0.1.20 Beta the toggling of "TMR0 Adjust" has a somewhat odd behaviour (I think):
- it toggles from 0 --> 0 --> 2 --> 2 --> 4 --> 2 --> 4 --> ...
- it can not be toggled when Timer0 is chosen and "TMR0 Preload" is set to zero

Otherwise: superb! :D

Posted: 04 Aug 2008 11:38
by Dany
Hi, I think I have detected a few problems with the "TMR0 Adjust" feature in the PIC Timer Calculator (I think :oops: ), v0.9.0.

1. If one activates this feature then the TMR0 "preload" value is decremented by 2. I think it should be incremented by 2 in stead. The reason is that 2 cycles are skipped by timer0, resulting in a longer delay to next rollover. To compensate for this the preload value should be 2 higher than normal.

Extract from the "MID Range Manual", section Timer0:
Any write to the TMR0 register will cause a 2 instruction cycle (2TCY) inhibit. That is, after the
TMR0 register has been written with the new value, TMR0 will not be incremented until the third
instruction cycle later (Figure 11-2).
and (from the "Design tips"):
When writing to TMR0, two instruction clock cycles are lost. Often you have a specific time period you want to count, say 100 decimal. In that case you might put 156 into TMR0 (256 - 100 = 156). However, since two instruction cycles are lost when you write to TMR0 (for internal logic synchronization), you should actually write 158 to the timer.
2. The correction in the "preload" value does not take into account if the prescaler is used. The correction in this preload value should be multiplied by the division caused by the prescaler (so, if the prescaler is at 1:4, then the correction should be 4 times 2 units).

Extract from the "MID Range Manual", section Timer0:
When the prescaler is assigned to the Timer0 module, any
write to the TMR0 register will immediately update the TMR0 register and clear the prescaler. The
incrementing of Timer0 (TMR0 and Prescaler) will also be inhibited 2 instruction cycles (TCY). So
if the prescaler is configured as 2, then after a write to the TMR0 register TMR0 will not increment
for 4 Timer0 clocks (Figure 11-3). After that, TMR0 will increment every prescaler number of
clocks later.

By the way: GREAT TOOL! :D

Correction (2008-11-22): Problem 2 seems to be no problem at all, see http://www.mikroe.com/forum/viewtopic.p ... highlight=

Posted: 05 Aug 2008 15:42
by Mancrius
Very nice tool !!!! congratulations !!!!!!

I'm not a expert on this subject and it's helping me a lot !!!

the only suggestion is that on Basic the end of commands has not

Code: Select all

;

Posted: 22 Nov 2008 09:39
by Dany
Hi, it seems that problem 1 stated in the quote below (see also 2 posts back) has not been solved yet (v 0.9.2 now already). The existance of the problem has been confirmed in http://www.mikroe.com/forum/viewtopic.p ... highlight=.
Problem 2 stated in the quote below seems to be no problem at al, see also http://www.mikroe.com/forum/viewtopic.p ... highlight=.

It is a pitty that such a usefull tool is not adapted for this issue. :cry:
Thanks in advance. :D
Dany wrote:Hi, I think I have detected a few problems with the "TMR0 Adjust" feature in the PIC Timer Calculator (I think :oops: ), v0.9.0.

1. If one activates this feature then the TMR0 "preload" value is decremented by 2. I think it should be incremented by 2 in stead. The reason is that 2 cycles are skipped by timer0, resulting in a longer delay to next rollover. To compensate for this the preload value should be 2 higher than normal.

Extract from the "MID Range Manual", section Timer0:
Any write to the TMR0 register will cause a 2 instruction cycle (2TCY) inhibit. That is, after the
TMR0 register has been written with the new value, TMR0 will not be incremented until the third
instruction cycle later (Figure 11-2).
and (from the "Design tips"):
When writing to TMR0, two instruction clock cycles are lost. Often you have a specific time period you want to count, say 100 decimal. In that case you might put 156 into TMR0 (256 - 100 = 156). However, since two instruction cycles are lost when you write to TMR0 (for internal logic synchronization), you should actually write 158 to the timer.
2. The correction in the "preload" value does not take into account if the prescaler is used. The correction in this preload value should be multiplied by the division caused by the prescaler (so, if the prescaler is at 1:4, then the correction should be 4 times 2 units).

Extract from the "MID Range Manual", section Timer0:
When the prescaler is assigned to the Timer0 module, any
write to the TMR0 register will immediately update the TMR0 register and clear the prescaler. The
incrementing of Timer0 (TMR0 and Prescaler) will also be inhibited 2 instruction cycles (TCY). So
if the prescaler is configured as 2, then after a write to the TMR0 register TMR0 will not increment
for 4 Timer0 clocks (Figure 11-3). After that, TMR0 will increment every prescaler number of
clocks later.

By the way: GREAT TOOL! :D