PDA

View Full Version : Creating a dynamic array


cwkoehler
10-17-06, 07:21 PM
Hello,

I need to dynamically create an array based on a number of ADC0 analogin U. values returned during a short time period (approx 1 second). The method I am currently using only gives me 30-35 readings within my application and I realize that the PC C# code is the root of the problem. However, I can get around this by temporarily storing the ADC values in an array on the ISOPODX and then retrieving when prompted. The code below provides the serial TX of the ADC0 values that I need while the ADC1 values dictates the start and stop of the data collection. Any insight into how to create the dynamic array within the following code structure would be greatly appreciated. Thanks in advance for your reply.

SCRUB
HEX

HERE 80 4 + ALLOT CONSTANT RBUFF EEWORD
RBUFF 80 4 + SCI0 RXBUFFER

HERE 256 4 + ALLOT CONSTANT TBUFF EEWORD
TBUFF 256 4 + SCI0 TXBUFFER

VARIABLE MTR-STOP EEWORD

: TURNOFF
PWMA0 OFF
PA0 OFF
; EEWORD

: EXTEND
BEGIN
CCCC PWMA0 PWM-OUT
PA0 OFF

( I need to create the array here - the array index for the storage of ADC0
(values will increment by 1 until the the ADC1 shutoff value is reached

ADC0 ANALOGIN U.
ADC1 ANALOGIN 4200 > UNTIL
TURNOFF
41 SCI0 TX ;

: RETRACT
BEGIN
3333 PWMA0 PWM-OUT
PA0 ON
ADC1 ANALOGIN 100 = UNTIL
TURNOFF
41 SCI0 TX ;

: START
PWMA0 INDEPENDENT
4E2 PWMA0 PWM-PERIOD
; EEWORD


Thanks again

Chris

Dave
10-18-06, 05:21 PM
I had been recently shown a mehtod of creating an array variable. Perhaps this can be of help, though it requires setting up a section of memory ahead of use.


VARIABLE CH EEWORD

: ARRAY#VAR
<BUILDS HERE P, 3 ALLOT DOES> P@ CH @ +
; EEWORD

ARRAY#VAR ADC0-VAL EEWORD

: CH1 0 CH ! ; EEWORD
: CH2 1 CH ! ; EEWORD
: CH3 2 CH ! ; EEWORD


What this does is create 3 positions in memory that change when CH is changed. When ADC0-VAL @ . is used to see what is stored in that variable, it looks at CH first to see which position to check, for the contents to be displayed. Typing first
CH1
then use
ADC0 ANALOGIN ADC0-VAL !
to store what has been retrieved by the ANALOGIN word in the current memory position.
Going to the next memory position, use
CH2
or simply store 1 into the CH variable. Change the 3 in the above ARRAY#VAR to reflect the number of values that need to be stored.

cwkoehler
10-19-06, 07:25 PM
Dave,

Thanks for your reply. I've have decided to solve my problem from the PC side. However, what you have shared will help me in my quest to understand

Thanks again


chris

Dave
10-20-06, 10:06 AM
I just noticed that part of the WORD did not get printed, even with code tags around :

VARIABLE CH EEWORD

: ARRAY#VAR
< BUILDS HERE P, 3 ALLOT DOES > P@ CH @ +
; EEWORD


ARRAY#VAR ADC0-VAL EEWORD


: CH1 0 CH ! ; EEWORD
: CH2 1 CH ! ; EEWORD
: CH3 2 CH ! ; EEWORD


Here I've added a space between the less than < and BUILDS
and also between DOES and greater than > so that it would be visible.

That part is important in making this type of array variable.