News:

  • October 12, 2025, 07:18:10 PM

Login with username, password and session length

Author Topic: Referencing memory address  (Read 1638 times)

Kristjan

  • Sr. Member
  • ****
  • Posts: 67
    • Idnadartaekni ehf
Referencing memory address
« on: April 25, 2022, 11:15:33 AM »
I am scaling analog outputs in the same range and mapping from internal DLV to physical outputs WY.
Since I have many outputs I want to use a FOR-loop. I can use the index to reference the memory adress like DLV[V0] and even with offset like DLV[V0+1].
I am mapping from DLV4000..4007 to WY1..8 but the offset apparently can't be higher than 63.

This works:
FOR V0 0 7 1
  STR ST1
  SCALE DLV[V0+40] 0 4095 0 32767 WY[V0+1]
NEXT

But this doesn't work:
FOR V0 0 7 1
  STR ST1
  SCALE DLV[V0+4000] 0 4095 0 32767 WY[V0+1]
NEXT

Any neat solution to this?

MAEdwards

  • Sr. Member
  • ****
  • Posts: 56
Re: Referencing memory address
« Reply #1 on: April 25, 2022, 11:48:20 AM »
I am scaling analog outputs in the same range and mapping from internal DLV to physical outputs WY.
Since I have many outputs I want to use a FOR-loop. I can use the index to reference the memory adress like DLV[V0] and even with offset like DLV[V0+1].
I am mapping from DLV4000..4007 to WY1..8 but the offset apparently can't be higher than 63.

This works:
FOR V0 0 7 1
  STR ST1
  SCALE DLV[V0+40] 0 4095 0 32767 WY[V0+1]
NEXT

But this doesn't work:
FOR V0 0 7 1
  STR ST1
  SCALE DLV[V0+4000] 0 4095 0 32767 WY[V0+1]
NEXT

Any neat solution to this?

By default the DLV registers are have a block size of 2048 elements.  This allows for the octal addressing range of DLV0 to DLV3777.  If you go to System Configuration > Memory Configuration and select the DLV block, what is the size specified in your project?  Also, V registers, by default, range from V0 to V4095. Has this been adjusted in your Memory Configuration to accommodate your program?
« Last Edit: April 25, 2022, 11:53:22 AM by MAEdwards »

MAEdwards

  • Sr. Member
  • ****
  • Posts: 56
Re: Referencing memory address
« Reply #2 on: April 25, 2022, 12:14:50 PM »
Never mind.  I misinterpreted the parameters you called out.  I should having been paying closer attention to your code.  Ignore my post.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3761
    • Host Engineering
Re: Referencing memory address
« Reply #3 on: April 25, 2022, 12:35:39 PM »
Any neat solution to this?

Yes - use MATH instead of SCALE - do it by hand.

Since MATH supports expressions - it also supports ARRAY INDEX EXPRESSIONS, for BOTH  the Expression AND THE RESULT.

Here's the basic MATH forumul for SCALE

( ((Raw - Raw_Low) * (Scale_High - Scale_Low)) / (Raw_High - Raw_Low) ) + Scale_Low

Stick in the appropriate array index expressions and it should work as desired.

Kristjan

  • Sr. Member
  • ****
  • Posts: 67
    • Idnadartaekni ehf
Re: Referencing memory address
« Reply #4 on: April 26, 2022, 05:34:47 AM »
Great, thanks! This works fine.

Only thing is that DLV is octal adressed and WY is decimal adressed and I need to run separate FOR-loops for each 8 elements because the indexes will not follow the same sequence.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3761
    • Host Engineering
Re: Referencing memory address
« Reply #5 on: April 26, 2022, 09:41:01 AM »
There are no 8/9 addresses in octal.  The address after DLV7 is DLV10.  You add one to the index - it just works.

Octal constants start with 0, so 077 is the same as 63 decimal.

So, just do your FOR loop indexing the counts (note the leading 0 on the base DLV index 04000):

Code: [Select]
FOR V0 0 7 1
MATH DLV[04000 + V0] "( ((WY[V0 + 1] - Raw_Low) * (Scale_High - Scale_Low)) / (Raw_High - Raw_Low) ) + Scale_Low"
NEXT