Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Lookup() - number of CPU cycles to execute seems high at 40
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
guyadams

Bascom Member



Joined: 22 Nov 2006
Posts: 26

uk.gif
PostPosted: Mon Feb 19, 2024 1:07 pm    Post subject: Lookup() - number of CPU cycles to execute seems high at 40 Reply with quote

Hi,

I am using Lookup() to read values stored in an array in Flash. Using the simulator it reports that it takes 40 cycles to execute the instruction. Is this correct and is there a faster method?

Just edited to make clearer Smile

Thanks
Guy

Code:


$regfile = "m8535.dat"                                      
                                                           
$baud = 19200
$crystal = 16000000

Dim Cycle_count As Byte
Dim Dh As Byte
Dim Dl As Byte



Do
For Cycle_count = 0 To 255

   'First cycle - MAIN Phase (Master/unshifted) to include output etc

   'Get 16 bit sine wave value from table


    Dh = Lookup(cycle_count , Sineh)                        'Get High Byte


    Dl = Lookup(cycle_count , Sinel)                        'Get Low Byte

Next
Loop


End

'Here is the sine table - split into upper byte and lower.
'Must ensure that the compiler treats this as contiguous - use simulator memory window to do a compare
'with the source data after compilation
'This table has an offset and slightly reduced amplitude (to avoid max and min DAC values/clipping)
'High Byte Data Array

Sineh:
Data &H82 , &H85 , &H88 , &H8B , &H8E , &H90 , &H93 , &H96 ,
Data &H99 , &H9B , &H9E , &HA1 , &HA4 , &HA6 , &HA9 , &HAC ,
Data &HAE , &HB1 , &HB3 , &HB6 , &HB8 , &HBB , &HBD , &HC0 ,
Data &HC2 , &HC4 , &HC6 , &HC9 , &HCB , &HCD , &HCF , &HD1 ,
Data &HD3 , &HD5 , &HD7 , &HD9 , &HDA , &HDC , &HDE , &HDF ,
Data &HE1 , &HE2 , &HE4 , &HE5 , &HE6 , &HE8 , &HE9 , &HEA ,
Data &HEB , &HEC , &HED , &HEE , &HEF , &HEF , &HF0 , &HF0 ,
Data &HF1 , &HF1 , &HF2 , &HF2 , &HF2 , &HF3 , &HF3 , &HF3 ,
Data &HF3 , &HF3 , &HF2 , &HF2 , &HF2 , &HF1 , &HF1 , &HF0 ,
Data &HF0 , &HEF , &HEF , &HEE , &HED , &HEC , &HEB , &HEA ,
Data &HE9 , &HE8 , &HE6 , &HE5 , &HE4 , &HE2 , &HE1 , &HDF ,
Data &HDE , &HDC , &HDA , &HD9 , &HD7 , &HD5 , &HD3 , &HD1 ,
Data &HCF , &HCD , &HCB , &HC9 , &HC6 , &HC4 , &HC2 , &HC0 ,
Data &HBD , &HBB , &HB8 , &HB6 , &HB3 , &HB1 , &HAE , &HAC ,
Data &HA9 , &HA6 , &HA4 , &HA1 , &H9E , &H9B , &H99 , &H96 ,
Data &H93 , &H90 , &H8E , &H8B , &H88 , &H85 , &H82 , &H80 ,
Data &H7D , &H7A , &H77 , &H74 , &H71 , &H6F , &H6C , &H69 ,
Data &H66 , &H64 , &H61 , &H5E , &H5B , &H59 , &H56 , &H53 ,
Data &H51 , &H4E , &H4C , &H49 , &H47 , &H44 , &H42 , &H3F ,
Data &H3D , &H3B , &H39 , &H36 , &H34 , &H32 , &H30 , &H2E ,
Data &H2C , &H2A , &H28 , &H26 , &H25 , &H23 , &H21 , &H20 ,
Data &H1E , &H1D , &H1B , &H1A , &H19 , &H17 , &H16 , &H15 ,
Data &H14 , &H13 , &H12 , &H11 , &H10 , &H10 , &H0F , &H0F ,
Data &H0E , &H0E , &H0D , &H0D , &H0D , &H0C , &H0C , &H0C ,
Data &H0C , &H0C , &H0D , &H0D , &H0D , &H0E , &H0E , &H0F ,
Data &H0F , &H10 , &H10 , &H11 , &H12 , &H13 , &H14 , &H15 ,
Data &H16 , &H17 , &H19 , &H1A , &H1B , &H1D , &H1E , &H20 ,
Data &H21 , &H23 , &H25 , &H26 , &H28 , &H2A , &H2C , &H2E ,
Data &H30 , &H32 , &H34 , &H36 , &H39 , &H3B , &H3D , &H3F ,
Data &H42 , &H44 , &H47 , &H49 , &H4C , &H4E , &H51 , &H53 ,
Data &H56 , &H59 , &H5B , &H5E , &H61 , &H64 , &H66 , &H69 ,
Data &H6C , &H6F , &H71 , &H74 , &H77 , &H7A , &H7D , &H7F ,

'Low Byte Data Array
Sinel:
Data &HD3 , &HA7 , &H79 , &H4A , &H1A , &HE7 , &HB1 , &H79 ,
Data &H3D , &HFD , &HB9 , &H70 , &H22 , &HCF , &H75 , &H15 ,
Data &HAE , &H41 , &HCB , &H4D , &HC8 , &H39 , &HA1 , &H00 ,
Data &H55 , &H9F , &HDF , &H14 , &H3E , &H5C , &H6F , &H75 ,
Data &H6E , &H5B , &H3A , &H0C , &HD1 , &H87 , &H2F , &HC8 ,
Data &H53 , &HCF , &H3B , &H98 , &HE6 , &H23 , &H50 , &H6E ,
Data &H7A , &H77 , &H62 , &H3D , &H06 , &HBF , &H66 , &HFC ,
Data &H80 , &HF3 , &H55 , &HA4 , &HE3 , &H0F , &H2A , &H33 ,
Data &H2A , &H0F , &HE3 , &HA4 , &H55 , &HF3 , &H80 , &HFC ,
Data &H66 , &HBF , &H06 , &H3D , &H62 , &H77 , &H7A , &H6E ,
Data &H50 , &H23 , &HE6 , &H98 , &H3B , &HCF , &H53 , &HC8 ,
Data &H2F , &H87 , &HD1 , &H0C , &H3A , &H5B , &H6E , &H75 ,
Data &H6F , &H5C , &H3E , &H14 , &HDF , &H9F , &H55 , &H00 ,
Data &HA1 , &H39 , &HC8 , &H4D , &HCB , &H41 , &HAE , &H15 ,
Data &H75 , &HCF , &H22 , &H70 , &HB9 , &HFD , &H3D , &H79 ,
Data &HB1 , &HE7 , &H1A , &H4A , &H79 , &HA7 , &HD3 , &H00 ,
Data &H2C , &H58 , &H86 , &HB5 , &HE5 , &H18 , &H4E , &H86 ,
Data &HC2 , &H02 , &H46 , &H8F , &HDD , &H30 , &H8A , &HEA ,
Data &H51 , &HBE , &H34 , &HB2 , &H37 , &HC6 , &H5E , &HFF ,
Data &HAA , &H60 , &H20 , &HEB , &HC1 , &HA3 , &H90 , &H8A ,
Data &H91 , &HA4 , &HC5 , &HF3 , &H2E , &H78 , &HD0 , &H37 ,
Data &HAC , &H30 , &HC4 , &H67 , &H19 , &HDC , &HAF , &H91 ,
Data &H85 , &H88 , &H9D , &HC2 , &HF9 , &H40 , &H99 , &H03 ,
Data &H7F , &H0C , &HAA , &H5B , &H1C , &HF0 , &HD5 , &HCD ,
Data &HD5 , &HF0 , &H1C , &H5B , &HAA , &H0C , &H7F , &H03 ,
Data &H99 , &H40 , &HF9 , &HC2 , &H9D , &H88 , &H85 , &H91 ,
Data &HAF , &HDC , &H19 , &H67 , &HC4 , &H30 , &HAC , &H37 ,
Data &HD0 , &H78 , &H2E , &HF3 , &HC5 , &HA4 , &H91 , &H8A ,
Data &H90 , &HA3 , &HC1 , &HEB , &H20 , &H60 , &HAA , &HFF ,
Data &H5E , &HC6 , &H37 , &HB2 , &H34 , &HBE , &H51 , &HEA ,
Data &H8A , &H30 , &HDD , &H8F , &H46 , &H02 , &HC2 , &H86 ,
Data &H4E , &H18 , &HE5 , &HB5 , &H86 , &H58 , &H2C , &HFF ,


 


(BASCOM-AVR version : 2.0.8.6 )


Last edited by guyadams on Mon Feb 19, 2024 1:41 pm; edited 4 times in total
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Mon Feb 19, 2024 1:12 pm    Post subject: Reply with quote

you should include the used processor. best way is $regfile with the value.
also, it is best to shrink the code to the essential part.

what is important : the used processor. the data type of the used variables.
in general : a small as possible program that can be compiled but demos the problem or question.

40 is right when i assume some things. it can be made quicker but that depends on the used processor.

_________________
Mark
Back to top
View user's profile Visit poster's website
guyadams

Bascom Member



Joined: 22 Nov 2006
Posts: 26

uk.gif
PostPosted: Mon Feb 19, 2024 1:47 pm    Post subject: Reply with quote

Thanks Mark - have tidied the code example so it can be cut & pasted.

I have not thought about the operations needed - 40 seemed high and there are 8 Lookup() in the real code loop which equates to 320 cpu cycles...... I could migrate to an ATMega328PB with enough SRAM to copy the table into at startup if this is going to be faster?

Cheers
Guy
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Mon Feb 19, 2024 2:48 pm    Post subject: Reply with quote

i explain how lookup works. for your micro that is.
- the address is needed for the start of the table. either in flash or ram. that requires 2 LDI instructions.
- an offset need to be added so in any case, 2 add instructions are required
- this offset need to be loaded from the used variable in order to save it to the regs used for adding
- with this info the lookup is called which will use LPM to restore the data from flash
- the data is stored to the variable of your choice.

you use 2 look ups. it would be simpler to use 1 lookup and change the table.
when you store the low and high value after each other, you can lookup a word and this safes the overhead of addressing.
when you use overlay you also have this info in byte form

dim bL as byte, bH as byte
dim W as word at BL overlay

the table data must have the form ;
data &Habcd% the % for indicating integer/word data

so this will safe a lot of cycles already.
when cycle_count increases, and is not random, you could go a step further.
that would require some asm to store the pointers.
this has the benefit that you do not need to add the offset each time.

when you want to go that route you best show (again simple) how the other lookup calls come into play.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Feb 19, 2024 3:29 pm    Post subject: Reply with quote

One quart of the flash usage is sufficient, as a complete sinus can be mirrored from one quadrant.
This applies also for using SRam.

To split the table in upper and lower word makes no sense and only slows the code down.

For having speed, use ASM and a global read pointer, R8/R9 is a good choice, as it is used by the data pointer for Read()
Advance the read pointer by 32 bytes each and you have 8 support points.

If you don't like ASM, you can try with Read(), as it keeps track of its current read-position. andn does not need to calculate every time again an absolute read address.
By reading a word with Read(), it advances the read-pointer one word = 2 bytes. For addressing the next support point, you need to advance (lptr) R8 & (hptr) R9 by 14.
Only for the first quadrant of course, for the other three quadrants some calculations are required.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Feb 19, 2024 3:31 pm    Post subject: Reply with quote

In the simple words: take the first of your Sineh data &H82 and then join it with the first Sinel data &HD3 so it becomes a &H82D3%
The procent sign describe it as two byte variable.
Do it same till the end of those 200B two tables means to the value &H7FFF%
Code:
Data &H82D3% ..... &H7FFF%


It will be more quicker but indeed load it into the SRAM will be improvement. 400B needed for this have a lot of chips now and they can be cheaper than old one.

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
guyadams

Bascom Member



Joined: 22 Nov 2006
Posts: 26

uk.gif
PostPosted: Mon Feb 19, 2024 3:38 pm    Post subject: Reply with quote

Hi Mark,

Thanks - tried it, but it seems to only save two cycles 80 -> 78. Maybe I have misunderstood something.....

Cheers
Guy

Code:

$regfile = "m8535.dat"

$baud = 19200
$crystal = 16000000

Dim Cycle_count As Byte
Dim Dh As Byte
Dim Dl As Byte
Dim D16 As Word





Do
For Cycle_count = 0 To 255

   'First cycle - MAIN Phase (Master/unshifted) to include output etc

   'Get 16 bit sine wave value from table


    D16 = Lookup(cycle_count , Sine)                        'Get 16bit value


   'Get high and low bytes
    Dh = High(D16)
    Dl = Low(D16)


Next
Loop
End

'Here is the sine table - 16 bit values


Sine:
Data &H82D3% , &H85A7% , &H8879% , &H8B4A% , &H8E1A% , &H90E7% , &H93B1% , &H9679% ,
Data &H993D% , &H9BFD% , &H9EB9% , &HA170% , &HA422% , &HA6CF% , &HA975% , &HAC15% ,
Data &HAEAE% , &HB141% , &HB3CB% , &HB64D% , &HB8C8% , &HBB39% , &HBDA1% , &HC000% ,
Data &HC255% , &HC49F% , &HC6DF% , &HC914% , &HCB3E% , &HCD5C% , &HCF6F% , &HD175% ,
Data &HD36E% , &HD55B% , &HD73A% , &HD90C% , &HDAD1% , &HDC87% , &HDE2F% , &HDFC8% ,
Data &HE153% , &HE2CF% , &HE43B% , &HE598% , &HE6E6% , &HE823% , &HE950% , &HEA6E% ,
Data &HEB7A% , &HEC77% , &HED62% , &HEE3D% , &HEF06% , &HEFBF% , &HF066% , &HF0FC% ,
Data &HF180% , &HF1F3% , &HF255% , &HF2A4% , &HF2E3% , &HF30F% , &HF32A% , &HF333% ,
Data &HF32A% , &HF30F% , &HF2E3% , &HF2A4% , &HF255% , &HF1F3% , &HF180% , &HF0FC% ,
Data &HF066% , &HEFBF% , &HEF06% , &HEE3D% , &HED62% , &HEC77% , &HEB7A% , &HEA6E% ,
Data &HE950% , &HE823% , &HE6E6% , &HE598% , &HE43B% , &HE2CF% , &HE153% , &HDFC8% ,
Data &HDE2F% , &HDC87% , &HDAD1% , &HD90C% , &HD73A% , &HD55B% , &HD36E% , &HD175% ,
Data &HCF6F% , &HCD5C% , &HCB3E% , &HC914% , &HC6DF% , &HC49F% , &HC255% , &HC000% ,
Data &HBDA1% , &HBB39% , &HB8C8% , &HB64D% , &HB3CB% , &HB141% , &HAEAE% , &HAC15% ,
Data &HA975% , &HA6CF% , &HA422% , &HA170% , &H9EB9% , &H9BFD% , &H993D% , &H9679% ,
Data &H93B1% , &H90E7% , &H8E1A% , &H8B4A% , &H8879% , &H85A7% , &H82D3% , &H8000% ,
Data &H7D2C% , &H7A58% , &H7786% , &H74B5% , &H71E5% , &H6F18% , &H6C4E% , &H6986% ,
Data &H66C2% , &H6402% , &H6146% , &H5E8F% , &H5BDD% , &H5930% , &H568A% , &H53EA% ,
Data &H5151% , &H4EBE% , &H4C34% , &H49B2% , &H4737% , &H44C6% , &H425E% , &H3FFF% ,
Data &H3DAA% , &H3B60% , &H3920% , &H36EB% , &H34C1% , &H32A3% , &H3090% , &H2E8A% ,
Data &H2C91% , &H2AA4% , &H28C5% , &H26F3% , &H252E% , &H2378% , &H21D0% , &H2037% ,
Data &H1EAC% , &H1D30% , &H1BC4% , &H1A67% , &H1919% , &H17DC% , &H16AF% , &H1591% ,
Data &H1485% , &H1388% , &H129D% , &H11C2% , &H10F9% , &H1040% , &H0F99% , &H0F03% ,
Data &H0E7F% , &H0E0C% , &H0DAA% , &H0D5B% , &H0D1C% , &H0CF0% , &H0CD5% , &H0CCD% ,
Data &H0CD5% , &H0CF0% , &H0D1C% , &H0D5B% , &H0DAA% , &H0E0C% , &H0E7F% , &H0F03% ,
Data &H0F99% , &H1040% , &H10F9% , &H11C2% , &H129D% , &H1388% , &H1485% , &H1591% ,
Data &H16AF% , &H17DC% , &H1919% , &H1A67% , &H1BC4% , &H1D30% , &H1EAC% , &H2037% ,
Data &H21D0% , &H2378% , &H252E% , &H26F3% , &H28C5% , &H2AA4% , &H2C91% , &H2E8A% ,
Data &H3090% , &H32A3% , &H34C1% , &H36EB% , &H3920% , &H3B60% , &H3DAA% , &H3FFF% ,
Data &H425E% , &H44C6% , &H4737% , &H49B2% , &H4C34% , &H4EBE% , &H5151% , &H53EA% ,
Data &H568A% , &H5930% , &H5BDD% , &H5E8F% , &H6146% , &H6402% , &H66C2% , &H6986% ,
Data &H6C4E% , &H6F18% , &H71E5% , &H74B5% , &H7786% , &H7A58% , &H7D2C% , &H7FFF% ,
 
Back to top
View user's profile
guyadams

Bascom Member



Joined: 22 Nov 2006
Posts: 26

uk.gif
PostPosted: Mon Feb 19, 2024 3:44 pm    Post subject: Reply with quote

MWS wrote:
One quart of the flash usage is sufficient, as a complete sinus can be mirrored from one quadrant.
This applies also for using SRam.

To split the table in upper and lower word makes no sense and only slows the code down.

For having speed, use ASM and a global read pointer, R8/R9 is a good choice, as it is used by the data pointer for Read()
Advance the read pointer by 32 bytes each and you have 8 support points.

If you don't like ASM, you can try with Read(), as it keeps track of its current read-position. andn does not need to calculate every time again an absolute read address.
By reading a word with Read(), it advances the read-pointer one word = 2 bytes. For addressing the next support point, you need to advance (lptr) R8 & (hptr) R9 by 14.
Only for the first quadrant of course, for the other three quadrants some calculations are required.


Thanks - I will look into ASM (I have it elsewhere for timing critical operations). I know what you say about using 1/4 of the points, however to reproduce a precise sine wave which requires every DAC update to occur at the right time I decided the calculations for other quadrants would make it hard to keep timing consistent for every value - hence a full table (which is really easy in Excel to generate).
Cheers
Guy
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Feb 19, 2024 3:56 pm    Post subject: Reply with quote

This is how it can be measured. Simply insert into your code the "nop" instruction before you want to measure something. Then run Simulator and "Run to this place" then zeros the counter by double click on it. Only then run to the next nop.



I dont think that 61 instructions at 16_000_000 Hz is a critical value here.

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
guyadams

Bascom Member



Joined: 22 Nov 2006
Posts: 26

uk.gif
PostPosted: Mon Feb 19, 2024 4:04 pm    Post subject: Reply with quote

MWS wrote:
One quart of the flash usage is sufficient, as a complete sinus can be mirrored from one quadrant.
This applies also for using SRam.

To split the table in upper and lower word makes no sense and only slows the code down.

For having speed, use ASM and a global read pointer, R8/R9 is a good choice, as it is used by the data pointer for Read()
Advance the read pointer by 32 bytes each and you have 8 support points.

If you don't like ASM, you can try with Read(), as it keeps track of its current read-position. andn does not need to calculate every time again an absolute read address.
By reading a word with Read(), it advances the read-pointer one word = 2 bytes. For addressing the next support point, you need to advance (lptr) R8 & (hptr) R9 by 14.
Only for the first quadrant of course, for the other three quadrants some calculations are required.


Hi,

I tried the Read() but again it takes a long time - 65 cycles (Plus 10 and 8) =83 to get the two bytes on a like for like basis.

Code:
$regfile = "m8535.dat"

$baud = 19200
$crystal = 16000000

Dim Cycle_count As Byte
Dim Dh As Byte
Dim Dl As Byte
Dim D16 As Word


Restore Sine                                               'point to stored data


Do
For Cycle_count = 0 To 255

   'First cycle - MAIN Phase (Master/unshifted) to include output etc

   'Get 16 bit sine wave value from table


'    D16 = Lookup(cycle_count , Sine)                        'Get 16bit value


    Read D16    'alternative way to get value




   'Get high and low bytes
    Dh = High(D16)
    Dl = Low(D16)


Next
Loop
End

'Here is the sine table - 16 bit values


Sine:
Data &H82D3% , &H85A7% , &H8879% , &H8B4A% , &H8E1A% , &H90E7% , &H93B1% , &H9679% ,
Data &H993D% , &H9BFD% , &H9EB9% , &HA170% , &HA422% , &HA6CF% , &HA975% , &HAC15% ,
Data &HAEAE% , &HB141% , &HB3CB% , &HB64D% , &HB8C8% , &HBB39% , &HBDA1% , &HC000% ,
Data &HC255% , &HC49F% , &HC6DF% , &HC914% , &HCB3E% , &HCD5C% , &HCF6F% , &HD175% ,
Data &HD36E% , &HD55B% , &HD73A% , &HD90C% , &HDAD1% , &HDC87% , &HDE2F% , &HDFC8% ,
Data &HE153% , &HE2CF% , &HE43B% , &HE598% , &HE6E6% , &HE823% , &HE950% , &HEA6E% ,
Data &HEB7A% , &HEC77% , &HED62% , &HEE3D% , &HEF06% , &HEFBF% , &HF066% , &HF0FC% ,
Data &HF180% , &HF1F3% , &HF255% , &HF2A4% , &HF2E3% , &HF30F% , &HF32A% , &HF333% ,
Data &HF32A% , &HF30F% , &HF2E3% , &HF2A4% , &HF255% , &HF1F3% , &HF180% , &HF0FC% ,
Data &HF066% , &HEFBF% , &HEF06% , &HEE3D% , &HED62% , &HEC77% , &HEB7A% , &HEA6E% ,
Data &HE950% , &HE823% , &HE6E6% , &HE598% , &HE43B% , &HE2CF% , &HE153% , &HDFC8% ,
Data &HDE2F% , &HDC87% , &HDAD1% , &HD90C% , &HD73A% , &HD55B% , &HD36E% , &HD175% ,
Data &HCF6F% , &HCD5C% , &HCB3E% , &HC914% , &HC6DF% , &HC49F% , &HC255% , &HC000% ,
Data &HBDA1% , &HBB39% , &HB8C8% , &HB64D% , &HB3CB% , &HB141% , &HAEAE% , &HAC15% ,
Data &HA975% , &HA6CF% , &HA422% , &HA170% , &H9EB9% , &H9BFD% , &H993D% , &H9679% ,
Data &H93B1% , &H90E7% , &H8E1A% , &H8B4A% , &H8879% , &H85A7% , &H82D3% , &H8000% ,
Data &H7D2C% , &H7A58% , &H7786% , &H74B5% , &H71E5% , &H6F18% , &H6C4E% , &H6986% ,
Data &H66C2% , &H6402% , &H6146% , &H5E8F% , &H5BDD% , &H5930% , &H568A% , &H53EA% ,
Data &H5151% , &H4EBE% , &H4C34% , &H49B2% , &H4737% , &H44C6% , &H425E% , &H3FFF% ,
Data &H3DAA% , &H3B60% , &H3920% , &H36EB% , &H34C1% , &H32A3% , &H3090% , &H2E8A% ,
Data &H2C91% , &H2AA4% , &H28C5% , &H26F3% , &H252E% , &H2378% , &H21D0% , &H2037% ,
Data &H1EAC% , &H1D30% , &H1BC4% , &H1A67% , &H1919% , &H17DC% , &H16AF% , &H1591% ,
Data &H1485% , &H1388% , &H129D% , &H11C2% , &H10F9% , &H1040% , &H0F99% , &H0F03% ,
Data &H0E7F% , &H0E0C% , &H0DAA% , &H0D5B% , &H0D1C% , &H0CF0% , &H0CD5% , &H0CCD% ,
Data &H0CD5% , &H0CF0% , &H0D1C% , &H0D5B% , &H0DAA% , &H0E0C% , &H0E7F% , &H0F03% ,
Data &H0F99% , &H1040% , &H10F9% , &H11C2% , &H129D% , &H1388% , &H1485% , &H1591% ,
Data &H16AF% , &H17DC% , &H1919% , &H1A67% , &H1BC4% , &H1D30% , &H1EAC% , &H2037% ,
Data &H21D0% , &H2378% , &H252E% , &H26F3% , &H28C5% , &H2AA4% , &H2C91% , &H2E8A% ,
Data &H3090% , &H32A3% , &H34C1% , &H36EB% , &H3920% , &H3B60% , &H3DAA% , &H3FFF% ,
Data &H425E% , &H44C6% , &H4737% , &H49B2% , &H4C34% , &H4EBE% , &H5151% , &H53EA% ,
Data &H568A% , &H5930% , &H5BDD% , &H5E8F% , &H6146% , &H6402% , &H66C2% , &H6986% ,
Data &H6C4E% , &H6F18% , &H71E5% , &H74B5% , &H7786% , &H7A58% , &H7D2C% , &H7FFF% ,
 
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Feb 19, 2024 4:16 pm    Post subject: Reply with quote

0.0038ms I round up into 0.004ms. It means 4us.
If this slows down your code then Im curious how fast is rest of it because it means 250 KHz!

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Feb 19, 2024 4:17 pm    Post subject: Reply with quote

Code:
Dim D16 As Word
Dim Dh As Byte At D16 + 1 Overlay
Dim Dl As Byte At D16 Overlay

Spares some cycles.

Without the explicit conversion into Dl, Dh I get 80 cycles loop time, which is not a big improvement vs. Lookup()
Back to top
View user's profile
guyadams

Bascom Member



Joined: 22 Nov 2006
Posts: 26

uk.gif
PostPosted: Mon Feb 19, 2024 4:18 pm    Post subject: Reply with quote

Quote:

I dont think that 61 instructions at 16_000_000 Hz is a critical value here.


Thanks - unfortunately for this application it is. Getting the sine value occurs 4 times as I need a master phase and then 3 other phases (i.e. different indexes - not fixed). Also it is 61 cycles plus the byte separation to send to the DAC so add 18 to 61 = 79 only 1 cycle shorter than looking up 2 bytes as original code. Also the sine is reconstructed from 256 discrete values so the period of the waveform is T/256 which in my case is 34mS/246 = 114uS = 1840 cycles. There is a fair chunk of other functions going on like A/D inputs to trim the frequency, adjust phase, send serial to a display etc. so I was hoping to speed up sections that were repetitive and thirsty on cpu cycles.....

Cheers
Guy
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Feb 19, 2024 4:32 pm    Post subject: Reply with quote

Now we're talking Very Happy

This is how it looks like with SRAM
[/code]

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
guyadams

Bascom Member



Joined: 22 Nov 2006
Posts: 26

uk.gif
PostPosted: Mon Feb 19, 2024 4:42 pm    Post subject: Reply with quote

MWS wrote:
Code:
Dim D16 As Word
Dim Dh As Byte At D16 + 1 Overlay
Dim Dl As Byte At D16 Overlay

Spares some cycles.

Without the explicit conversion into Dl, Dh I get 80 cycles loop time, which is not a big improvement vs. Lookup()


Thanks - I get 60 cycles for the execution of the Lookup of a Sine Word and the high and low bytes are available, so this is quicker than the 80. (Yes the loop takes a bit longer.....)

Cheers
Guy
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum