News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Time Routines

Started by pjdenyer, Jul 01, 2021, 05:36 PM

Previous topic - Next topic

pjdenyer

Hi Guys,

I know this was on the old site, but I want to time routines and procedures, can anyone point me in the right direction.

TimB


I would run it in a VSM and look at the timing as you step through the code.

ISIS VSM used to be free in the compiler. Not sure if it still is.

RGV250

Hi,
This is what I use, you can use serial out as well.
Include "PROTON18_G20.INT" 'Proton 20MHz Graphics LCD
Dim TIMER1 As TMR1L.Word 'See help file
'DIM X AS FLOAT
'DIM Y AS FLOAT 'Dim some FLOATS
'DIM Z AS FLOAT

DelayMS 500 'Give PIC a chance to wake-up

Cls 'Clear the GLCD

'X = 1234.321 'Load 1234.321 into X FLOAT
'Y = 3.33 'Load 3.33 into Y FLOAT
Dim pressure As Float

Clear TIMER1 'Clear TIMER1
'#########################
T1CON = %00000001 'Enable the Timer

'Z = X * Y 'Code to calculate
pressure = (1023 * 0.04741) - 13.217

T1CON = %00000000 'Stop the Timer
'#########################

Print At 0,0,"cycles ",Dec TIMER1 'Print out the number of Cycles
Print At 2,0,"ANSWER ",Dec pressure 'Print out Answer
End

Include "FONT.INC" 'Include the font for GLCD
'--------------------------------------------------------------------------------
'Put the code you want to calculate the number of cycles
'between Enable Timer---Stop Timer

'Remember Timer1 on the 16F877 is 16 bits
'so 65535 is the max you can count before Timer overflows.

'In the above example 1234.321 is multiplied by 3.33
'Which gives an answer of 4110.289 and took 480 Cycles...


Bob

trastikata

To add to RGV250's excellent example, if you need really precise timing, you have to add 2 cycles for starting the timer and 1 cycle for stopping it.

John Drew

Would you have to add the two cycles to start as the count doesn't start until after the two cycles are complete?
John

RGV250

Hi,
QuoteTo add to RGV250's excellent example
I would just like to point out it was not my idea so I am not taking credit for it, I can't recall who wrote it in the first place.

I was thinking on the same lines as John, it is the count in between the timer start and stop so I don't think any addition is necessary but could be wrong. Either way it has worked for me. I have even added a rollover to get longer times in need be.

Regards,
Bob

trastikata

Quote from: John Drew on Jul 02, 2021, 12:01 AMWould you have to add the two cycles to start as the count doesn't start until after the two cycles are complete?
John

Good point John, I was thinking about interrupt overflow but RGV250's simply starting the timer. But we still have to add the stop cycle I think?

John Drew


RGV250

Hi,
I think if anything you would take the stop cycle off the count??

Bob