time taken by function High()

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

User avatar
Jan Lichtenbelt
Posts: 794
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 261 times
Contact:

time taken by function High()

Postby Jan Lichtenbelt » Wed Jan 09, 2013 2:09 pm

In assembler I meet the following codes:
MOVLW HIGH(gbl_FCV_A)
MOVLW LOW(gbl)FCV_A+D '0')
In general MOVLW takes one program step (time = 4/osc.frequency)
The question is if the HIGH() and LOW() will not change the time needed, or will this be increased? And yes, how many program steps?

Kind regards

Jan Lichtenbelt

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 64 times
Been thanked: 306 times
Contact:

Re: time taken by function High()

Postby JonnyW » Wed Jan 09, 2013 3:56 pm

Hi Jan.

I do not know the answer to this question, but if you wish to calculate, the attached program may help.

Add the code you want into the empty C icon and display the results best for your set-up.

I have left the timer as a default TMR0, and set the number of loops to 10,000,000. You may want to tweak this as you see fit. I hope this is useful.

Jonny

frame_rate_01.fcf
(10.12 KiB) Downloaded 503 times

User avatar
Benj
Matrix Staff
Posts: 14371
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4447 times
Been thanked: 4145 times
Contact:

Re: time taken by function High()

Postby Benj » Wed Jan 09, 2013 4:29 pm

Hello Jan,

I think a function call consumes a program cycle and any parameters will consume program cycles.

eg

high(byte, int)

will require 1 cycle for the function call, one cycle for the byte, two cycles for the int, then as many cycles as are in the function, finally 1 cycle for no return etc.

Might not be quite as straightforward as this but this can be used for wet finger estimates.

User avatar
Jan Lichtenbelt
Posts: 794
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 261 times
Contact:

Re: time taken by function High()

Postby Jan Lichtenbelt » Thu Jan 10, 2013 10:34 am

Hi Jonny and Ben,

Thanks for your reactions.

First I tried Jonny's solution. But that fails due to the unknown interrupt times (unknown number of interrupt program steps).
But you made me to find a solution to measure it.
1)I made in an endless while loop with alternating output high and low to output B0. This gave me and oscillator frequency on B0 of 223 449 Hz *), or a time period of 4.475 µsec.
2) I put the assembler code **) to be tested two times between the each output statement (two times to keep the on and off time equal).
MOVLW HIGH(gbl_FCV_TEXTIN)
MOVWF FSR0H
MOVLW LOW(gbl_FCV_TEXTIN+D'0')
MOVWF FSR0L
MOVF gbl_FCV_INDEX, W
ADDWF FSR0L, F
MOVF gbl_FCV_BITREAD, W
MOVWF INDF0
The oscillator frequency on B0 became 129365 Hz or 7.730 µsec. A difference of 3.255 µsec
3) I put 2 time 8 NOP's as assembler codes between each output statement.
The oscillator frequency on B0 became 129365 Hz or 7.730 µsec. A difference of 3.255 µsec

This shows that MOVLW HIGH(...) and MOVLW LOW(...) takes both just 1 program steps.
This is in agreement with the microchip oscillator frqeuency of 19660800 Hz or 0.05086 µsec. A program step is 4 times longer or 0.203 µsec and 2x8 program steps take 3.255 µsec, as messured.

Now stays the question for me what is the meaning of HIGH() and LOW()?

Kind regards

Jan Lichtenbelt

*) Note
Oscilator frequency measured with a very old Texas Instruments TM5003. It makes a lot of noise, but is very accurate.
**)
The flowcode is: textin[index] = bitread, with a string textin[34] and index and bitread a byte.

Added later:
In the meanwhile I found in the boostc manual the answer:
"To get address of a variable use the 'movlw' instruction:
asm movlw low(_a) ;copy low byte of address of variable a into W
asm movlw high(_a) ;copy low byte of address of variable a into W " (which should be probably the high byte address)