Timing, clock ....

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
louis4sun
Posts: 3
Joined: 07 Aug 2009 09:48

Timing, clock ....

#1 Post by louis4sun » 13 Aug 2009 17:45

Hello
I am new to dsPIC communauty and I am on my learning curve.
I have the dsPICPro4 dev. hardware + mikroBasic from mikroe

MCU is the stock dsPIC30F6014-PT + Xt(?) M10.000A8D component

After several examples tested and re-edited for my understanding ..
I have written a little program in MikroBasic to lear about time delays for different statements.
T1CON = $8000 ' for 1/1 Prescaler (or other prescalers)
I am using two successive calls
Time0 = TMR1
Statements, Delays or loops .... or trigonometric functions
Time1 = TMR1
Display : Time1- Time0 on the LCD 4 bits of dsPICPro4

Questions:
1) When I display "Clock_kHz", longint is 14464 , is it normal ?
2) Is it possible to change FOSC register bits to play with ? in mikroBasic ?
3) Is there inside some document the number of clocks taken for different functions (cos, sin, acos, atan2, log ....) after compiling in MikroBasic ?
4) what is the minimum time necessary to go to a Timer Interrupt routine (on TMR1 and PR1) and to return to the main ?

Regards
Louis

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#2 Post by p.erasmus » 16 Aug 2009 16:08

Using Timers will teach you nothing about the cycles any statments need to excecute, to understand this you have to analyse the asm code
and have a vary good understanding of asm and the controller
It also depens highly on the type of data you put through the statement

The closes you can get to the real senario is by using the simulator and the stop wacth to get a time were Time / Tcy = number of cycles used by statement .
In general knowing these type of technical detail about the compiler helps you as progrmmer nothing as you can not change it well you can but then you need to write your own asm files
to do a cetrain statement which make no sense because then you can actually write the whole aplication code in asm you do not need the compiler then.

In any programming Basic ,C and asm it is beneficial not to use float and real numbers unnecessarily aviod it and use fixed point or interger math speed up execution and save code size.
certainly there are cases where you can not avoid it and then have to use it,
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

Skyline
Posts: 267
Joined: 10 Jan 2006 09:35

#3 Post by Skyline » 16 Aug 2009 16:30

Hi,

1) If you set the clock to 15 MHz in either the "view project setup ..." or the "project edit project ..." panel, then the longint of Clock_kHz would display 15000. I assume that you set the clock to 14.464 MHz, thus you get longint of 14464 for Clock_kHz.

2) Go to "project edit project ..." menu command or the "edit project" icon command, and use the checkboxes to change FOSC register bits.

3) For timings of statements, functions, etc, use the debugger stopwatch feature. Very important feature of the IDE.

4) Minimum time to enter interrupt is about 20 instruction cycles, to return from interrupt is also about 20 instruction cycles. Forty instructions cycles take about 1.3 usecs at maximum 6014 speed.

All working registers are context saved on interrupts even if the interrupt routine does not use all the working registers. Newer MikroE compilers seem to allow selective register saving, reducing the interrupt latencies.

louis4sun
Posts: 3
Joined: 07 Aug 2009 09:48

#4 Post by louis4sun » 16 Aug 2009 17:27

Hi
Thanks for your answers
I have found my mistake (conversion before display on LCD)
Now it works Clocl_kHz is "80000" for 80 MHz (Xt 10 MHz and PLL 8x)
I continue on my learning
Louis

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”