Scope and MAIN

Questions about the BASICtools and MakeItC
Post Reply
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Scope and MAIN

Post by YahooArchive »

It wasn't clear (to me) that #includes must be inside a routine's block to be in
scope. In the below:

#include
MAIN:
CONST N = 256
DIM LUT(N)
FOR i =0 TO N-1
LUT(i) = SIN((i*2*128)/N)
NEXT i

The SIN() function is not in the scope of MAIN, but it doesn't throw an error
either, just zero values.
So more clarification of scope might be nice! Maybe I was used to having
#includes be global - the behavior is actually more like Python's.

Nice project page I saw here too BTW
http://wiki.ironwoodlabs.com/Coridium_A ... d_Computer

Ray



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Scope and MAIN

Post by YahooArchive »

> It wasn't clear (to me) that #includes must be inside a routine's block to be
in scope. In the below:
>
> #include
> MAIN:
> CONST N = 256
> DIM LUT(N)
> FOR i =0 TO N-1
> LUT(i) = SIN((i*2*128)/N)
> NEXT i
>
> The SIN() function is not in the scope of MAIN, but it doesn't throw an error
either, just zero values.
> So more clarification of scope might be nice! Maybe I was used to having
#includes be global - the behavior is actually more like Python's.

Actually its not a scope issue, as BASIC has only global and local within
SUB/FUNCT scopes (no nesting). Remember BASIC is a primitive language.

But you had me scratching my head on this one. Turns out to be a bug in
FREQOUT.bas. Basically it either needs to be run inline (no MAIN:) or what will
be added is an INIT_FREQOUT call which sets up the sin_val array used by sin_tbl
FUNCTION which is what the pre-processor does with SIN(x)

To fix it insert a

INIT_FREQOUT:

before sin_val = ...

and add a

RETURN

before goto jumpAroundFreqout

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Scope and MAIN

Post by YahooArchive »

> > But you had me scratching my head on this one. Turns out to be a bug in
FREQOUT.bas. Basically it either needs to be run inline (no MAIN:) or what will
be added is an INIT_FREQOUT call which sets up the sin_val array used by sin_tbl
FUNCTION which is what the pre-processor does with SIN(x)

I've uploaded a zip file of the BASIC libraries that fixes FREQOUT by adding an
INIT_FREQOUT SUB.

This also has the 2 versions of HWPWM.bas which allow different cycle times on
the 3 groups of channels.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: Scope and MAIN

Post by YahooArchive »

>from the help line
>the following code is not enabling the repetitive interrupt
> ' Repetitive Interrupt Testing Program 7/17/12 DG
>
> #include "LPC17xx.bas"
>
> RI_COMPVAL = 10000
> RI_MASK = 0
> RICTRL = 12
> RI_COUNER = 0
>
> DIM TestMe As Integer
> DIM N As Integer
>
> INTERRUPT SUB RIT_IRQ
>
> TestMe = TestMe + 1
>
> ENDSUB
>
>
> SUB INIT
>
> RIT_ISR = ADDRESSOF RIT_IRQ + 1
>
> ENDSUB
>
> MAIN:
> INIT
>
> MAINLOOP:
>
> Print TestMe
> FOR N = 0 to 1000000
> Next N
>
> Goto MAINLOOP
>
> END

While the statements before the MAIN can be used to define variables, they are
NOT executed (execution starts at MAIN). So the setting of the RI timer
registers NEVER happened. So move those into the INIT sub. Also check the
spelling of RICTRL.

Post Reply