Page 1 of 1

time taken by function High()

Posted: Wed Jan 09, 2013 2:09 pm
by Jan Lichtenbelt
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

Re: time taken by function High()

Posted: Wed Jan 09, 2013 3:56 pm
by JonnyW
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 722 times

Re: time taken by function High()

Posted: Wed Jan 09, 2013 4:29 pm
by Benj
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.

Re: time taken by function High()

Posted: Thu Jan 10, 2013 10:34 am
by Jan Lichtenbelt
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)