Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Kristjan 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?
-
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?
-
Never mind. I misinterpreted the parameters you called out. I should having been paying closer attention to your code. Ignore my post.
-
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.
-
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.
-
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):
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