Discussion forum for the BasicX family of microcontroller chips.
Can you use variables in arrays - maxvtol - Jul 9 18:10:15 2007
I'm trying to capture some pulses from a model RC receiver. I want to
capture the number of transitions with CountTransitions (to figure out
the number of channels the receiver is picking up). Then dimension the
array in InputCapture using the # of transitions from CountTransitions.
When I Dim the array for InputCapture
"Dim PulseTrain(1 to NumberOfICPulses) as New UnsignedInteger"
I get "Constant Expected" . I even tried to set a constant equal to the
variable, but that gives "Unknown Identifier..".
Is there any way to use a variable to dimension an array?
Thanks.
Joe

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )
Re: Can you use variables in arrays - Tom Becker - Jul 9 19:41:49 2007
const NumberOfICEdges as byte = 12 ' 6 pulses
Dim PulseTrain(1 to NumberOfICEdges) as New UnsignedInteger
works here. Interestingly, though,
Public PulseTrain(1 to NumberOfICEdges) as New UnsignedInteger
does not.
Tom

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )
Re: Can you use variables in arrays - maxvtol - Jul 9 20:22:50 2007
Tom,
Thanks for your quick reply. The 12 in your trial is the variable I
want the CountTransitions function to set. This way I could use a 7
channel or a 9 channel transmitter without having to go into the code
to change it.
Is there any code or function that can be used to change a variable,
once the value is determined, to a constant without doing it manually?
--- In b...@yahoogroups.com, Tom Becker
wrote:
>
> const NumberOfICEdges as byte = 12 ' 6 pulses
> Dim PulseTrain(1 to NumberOfICEdges) as New UnsignedInteger
>
> works here. Interestingly, though,
>
> Public PulseTrain(1 to NumberOfICEdges) as New UnsignedInteger
>
> does not.
> Tom
>

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )Re: Re: Can you use variables in arrays - Tom Becker - Jul 9 21:01:51 2007
> ... I could use a 7 channel or a 9 channel transmitter...
Ah. Do you mean you want to assign the Dim length at run time after
sampling input data? In the normal sense, you can't do that; the array
space is assigned at compile time. You can, of course, make the array
as large as the worst case; you'll ultimately need to use that much RAM
when your device encounters that transmitter, anyway.
A parameter you can change with the CountTransitions result is the
subsequent InputCapture "pulsecount" (actually, the transition or edge
count); something like, for example,
dim uiPulsePeriods(1 to 18)as new unsigned integer
dim iEdgeCount as integer
const sdT as single = 0.020 ' 50Hz
iEdgeCount = cint(CountTransitions(pin, sdT)
call InputCapture(uiPulsePeriods, iEdgeCount, 1) ' starts on rise
I think you'll probably need a loop or two to sync with the transmitter,
too. You might find
http://tech.groups.yahoo.com/group/basicx/message/22191 thread useful;
it shows how I did something similar.
Tom

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )
Re: Can you use variables in arrays - maxvtol - Jul 9 21:52:22 2007
Thanks ever so much Tom,
That's exactly what I was trying to do. Your suggestion worked. I
didn't realize the array size was set at compile time.
Joe
PS Thanks for the link to your code. That will come in handy.
--- In b...@yahoogroups.com, Tom Becker
wrote:
>
> > ... I could use a 7 channel or a 9 channel transmitter...
>
> Ah. Do you mean you want to assign the Dim length at run time
after
> sampling input data? In the normal sense, you can't do that; the
array
> space is assigned at compile time. You can, of course, make the
array
> as large as the worst case; you'll ultimately need to use that much
RAM
> when your device encounters that transmitter, anyway.
>
> A parameter you can change with the CountTransitions result is the
> subsequent InputCapture "pulsecount" (actually, the transition or
edge
> count); something like, for example,
>
> dim uiPulsePeriods(1 to 18)as new unsigned integer
> dim iEdgeCount as integer
> const sdT as single = 0.020 ' 50Hz
> iEdgeCount = cint(CountTransitions(pin, sdT)
> call InputCapture(uiPulsePeriods, iEdgeCount, 1) ' starts on rise
>
> I think you'll probably need a loop or two to sync with the
transmitter,
> too. You might find
> http://tech.groups.yahoo.com/group/basicx/message/22191 thread
useful;
> it shows how I did something similar.
> Tom
>

(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )