PIC Timer Calculator - free - Betatesting

General discussion on mikroBasic.
Author
Message
Kia
Posts: 4
Joined: 16 May 2007 14:18
Location: Spain, Alicante

PIC Timer Calculator - free - Betatesting

#1 Post by Kia » 03 Jul 2008 21:53

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
Last edited by Kia on 30 Jul 2008 08:04, edited 1 time in total.
EasyPIC4 & microBasic Owner

Jan Rune
Posts: 416
Joined: 21 Oct 2005 23:04
Location: Oslo, Norway

#2 Post by Jan Rune » 03 Jul 2008 22:12

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

Raslan
Posts: 758
Joined: 02 Jul 2006 12:31
Location: Syria & Finland
Contact:

#3 Post by Raslan » 03 Jul 2008 23:18

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
I am learning in this forum a lot from the others' problems and experinces...
"Give me a fish, I eat for a day. Teach me how to fish, I eat for a life time."

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#4 Post by Dany » 04 Jul 2008 10:20

Wow!
Very nice, very usefull! :D
Saves a lot of calculation work and reduces very much the # errors with timers.

Thanks! :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

AjK
Posts: 16
Joined: 11 Jun 2008 23:32
Location: Italy

#5 Post by AjK » 04 Jul 2008 11:52

great Work :)
.:: The _ AjK ::.

Acetronics
Posts: 715
Joined: 27 Dec 2006 14:33
Location: Le Tréport , FRANCE

#6 Post by Acetronics » 04 Jul 2008 12:45

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

Kia
Posts: 4
Joined: 16 May 2007 14:18
Location: Spain, Alicante

#7 Post by Kia » 04 Jul 2008 14:46

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
EasyPIC4 & microBasic Owner

Acetronics
Posts: 715
Joined: 27 Dec 2006 14:33
Location: Le Tréport , FRANCE

#8 Post by Acetronics » 04 Jul 2008 14:52

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

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#9 Post by janni » 04 Jul 2008 16:05

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?

KM6VV
Posts: 6
Joined: 10 Jun 2008 03:18

#10 Post by KM6VV » 04 Jul 2008 21:03

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
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/

Kia
Posts: 4
Joined: 16 May 2007 14:18
Location: Spain, Alicante

#11 Post by Kia » 05 Jul 2008 23:48

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
EasyPIC4 & microBasic Owner

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#12 Post by Dany » 10 Jul 2008 20:51

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
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#13 Post by Dany » 04 Aug 2008 11:38

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=
Last edited by Dany on 22 Nov 2008 09:41, edited 1 time in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Mancrius
Posts: 54
Joined: 13 Jul 2008 16:38

#14 Post by Mancrius » 05 Aug 2008 15:42

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

;

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#15 Post by Dany » 22 Nov 2008 09:39

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
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroBasic General”