Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | Optimizing

Discussion forum for the BasicX family of microcontroller chips.

Optimizing - limorgarcia - Nov 28 18:31:00 2003

syntax-wise, is it possible to optimize this part of my code?
sub litLed (byval byte1 as byte, byval byte2 as byte, byval byte3 as
byte, byval byte4 as byte, byval byte5 as byte, byval byte6 as byte,
byval byte7 as byte, byval byte8 as byte, byval byte9 as byte, byval
byte10 as byte, byval byte11 as byte, byval byte12 as byte, byval
byte13 as byte, byval byte14 as byte)', byval byte15 as byte, byval
byte16 as byte)
call putPin(16, 1)
call putPin(15, 0)
call putPin(14, 0)
call shiftOut(13, 15, 8, byte1)
call shiftOut(13, 15, 8, byte2)
call shiftOut(13, 15, 8, byte3)
call shiftOut(13, 15, 8, byte4)
call shiftOut(13, 15, 8, byte5)
call shiftOut(13, 15, 8, byte6)
call shiftOut(13, 15, 8, byte7)
call shiftOut(13, 15, 8, byte8)
call shiftOut(13, 15, 8, byte9)
call shiftOut(13, 15, 8, byte10)
call shiftOut(13, 15, 8, byte11)
call shiftOut(13, 15, 8, byte12)
call shiftOut(13, 15, 8, byte13)
call shiftOut(13, 15, 8, byte14)
call shiftOut(13, 15, 8, byte15)
call shiftOut(13, 15, 8, byte16) call putPin(14, 1)
end sub





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


Re: Optimizing - Frank Manning - Nov 28 21:31:00 2003

From: limorgarcia <>

> syntax-wise, is it possible to optimize this part
> of my code?

I suppose it depends on how you define optimum for this problem.
Do you want to minimize RAM? Maximize execution speed? Maximize
readability or maintainability?

> sub litLed (byval byte1 as byte, byval byte2 as byte,
> [...], byte13 as byte, byval byte14 as byte)',
> [...]
> call shiftOut(13, 15, 8, byte1)
> call shiftOut(13, 15, 8, byte2)
> [...]
> call shiftOut(13, 15, 8, byte15)
> call shiftOut(13, 15, 8, byte16)

I guess the obvious question is whether you can put the 14 (or 16)
bytes in an array. That way you need only pass the array by
reference, instead of copying 16 bytes as parameters.

-- Frank Manning
-- NetMedia, Inc.





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

Re: Optimizing - limorgarcia - Nov 28 21:45:00 2003

yes, i guess that's what i'm trying to do. put it all in an array to
be referenced.
I believe that the more lines in the code, the slower (or less
smooth) the program will function (or am i wrong?).
Arrays, as i gather, can encompass numbers (# to #), that's why i
can't understand how to fill it with different values (like byte1,
byte2, byte3 etc.)
thanks for your help.
limor

--- In , "Frank Manning" <fmanning@n...> wrote:
> From: limorgarcia <limorgarcia@y...>
>
> > syntax-wise, is it possible to optimize this part
> > of my code?
>
> I suppose it depends on how you define optimum for this problem.
> Do you want to minimize RAM? Maximize execution speed? Maximize
> readability or maintainability?
>
> > sub litLed (byval byte1 as byte, byval byte2 as byte,
> > [...], byte13 as byte, byval byte14 as byte)',
> > [...]
> > call shiftOut(13, 15, 8, byte1)
> > call shiftOut(13, 15, 8, byte2)
> > [...]
> > call shiftOut(13, 15, 8, byte15)
> > call shiftOut(13, 15, 8, byte16)
>
> I guess the obvious question is whether you can put the 14 (or 16)
> bytes in an array. That way you need only pass the array by
> reference, instead of copying 16 bytes as parameters.
>
> -- Frank Manning
> -- NetMedia, Inc.





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

Re: Re: Optimizing - Trevor Pinkney - Nov 28 23:55:00 2003

limorgarcia,

Your code is the PERFECT example of code that could be improved by an
array. You want to do something like this: Public shiftValues(1 to 16) As Byte 'Make the array accessible by all
functions in the program

Public Sub Main()

call InitShiftValues() ' a function that sets the values
call litLed()

End Sub

'a simple function that sets the values
Public Sub InitShiftValues()

shiftValues(1) = 0
shiftValues(2) = 1
shiftValues(3) = 233
shiftValues(4) = 232
shiftValues(5) = 0
'..
'..

End Sub

Public Sub litLed()

dim x as integer

' loop through each item in the array
for x = 1 to 16
call shiftOut(13, 15, 8, shiftValues(x))
next

End Sub -Trevor

At 02:45 AM 11/29/2003 +0000, you wrote:
>yes, i guess that's what i'm trying to do. put it all in an array to
>be referenced.
>I believe that the more lines in the code, the slower (or less
>smooth) the program will function (or am i wrong?).
>Arrays, as i gather, can encompass numbers (# to #), that's why i
>can't understand how to fill it with different values (like byte1,
>byte2, byte3 etc.)
>thanks for your help.
>limor
>
>--- In , "Frank Manning" <fmanning@n...> wrote:
> > From: limorgarcia <limorgarcia@y...>
> >
> > > syntax-wise, is it possible to optimize this part
> > > of my code?
> >
> > I suppose it depends on how you define optimum for this problem.
> > Do you want to minimize RAM? Maximize execution speed? Maximize
> > readability or maintainability?
> >
> > > sub litLed (byval byte1 as byte, byval byte2 as byte,
> > > [...], byte13 as byte, byval byte14 as byte)',
> > > [...]
> > > call shiftOut(13, 15, 8, byte1)
> > > call shiftOut(13, 15, 8, byte2)
> > > [...]
> > > call shiftOut(13, 15, 8, byte15)
> > > call shiftOut(13, 15, 8, byte16)
> >
> > I guess the obvious question is whether you can put the 14 (or 16)
> > bytes in an array. That way you need only pass the array by
> > reference, instead of copying 16 bytes as parameters.
> >
> > -- Frank Manning
> > -- NetMedia, Inc.





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

Re: Optimizing - limorgarcia - Nov 29 0:39:00 2003

hey Trevor,
thanks for your help.
I am trying to do what you suggested but the problem is that there
are values within the "litLED()" sub (in the parenthesis). it look
like that:
sub litLed (byval byte2 as byte, byval byte3 as byte, byval byte4 as
byte...)
and the 4th value inside the shiftout command refers to byte2,
byte3...
once I change it to be the X as integer shortcut an error msg comes
up telling me that the dimensions of actual parameter don't match
those of the formal parameter. and the first line of my "call
litLed" is highlighted (line below).
call litLed (arrayY(2), arrayX(1), arrayY(1), arrayX(5), arrayY(7),
arrayX(1), arrayY(1), arrayX(5), arrayY(1), arrayX(5), arrayY(2),
arrayX(5), arrayY(1), arrayX(1), arrayY(1), arrayX(1))

during this arrays process the "byval byte2 as byte, byval byte3 as
byte....." information in the "sub litLed" is omitted, and i believe
it is essential(?).

Limor
--- In , Trevor Pinkney <tpinkney@s...> wrote:
> limorgarcia,
>
> Your code is the PERFECT example of code that could be improved by
an
> array. You want to do something like this: > Public shiftValues(1 to 16) As Byte 'Make the array accessible by
all
> functions in the program
>
> Public Sub Main()
>
> call InitShiftValues() ' a function that sets the values
> call litLed()
>
> End Sub
>
> 'a simple function that sets the values
> Public Sub InitShiftValues()
>
> shiftValues(1) = 0
> shiftValues(2) = 1
> shiftValues(3) = 233
> shiftValues(4) = 232
> shiftValues(5) = 0
> '..
> '..
>
> End Sub
>
> Public Sub litLed()
>
> dim x as integer
>
> ' loop through each item in the array
> for x = 1 to 16
> call shiftOut(13, 15, 8, shiftValues(x))
> next
>
> End Sub > -Trevor
>
> At 02:45 AM 11/29/2003 +0000, you wrote:
> >yes, i guess that's what i'm trying to do. put it all in an array
to
> >be referenced.
> >I believe that the more lines in the code, the slower (or less
> >smooth) the program will function (or am i wrong?).
> >Arrays, as i gather, can encompass numbers (# to #), that's why i
> >can't understand how to fill it with different values (like byte1,
> >byte2, byte3 etc.)
> >thanks for your help.
> >limor
> >
> >--- In , "Frank Manning" <fmanning@n...>
wrote:
> > > From: limorgarcia <limorgarcia@y...>
> > >
> > > > syntax-wise, is it possible to optimize this part
> > > > of my code?
> > >
> > > I suppose it depends on how you define optimum for this
problem.
> > > Do you want to minimize RAM? Maximize execution speed? Maximize
> > > readability or maintainability?
> > >
> > > > sub litLed (byval byte1 as byte, byval byte2 as byte,
> > > > [...], byte13 as byte, byval byte14 as byte)',
> > > > [...]
> > > > call shiftOut(13, 15, 8, byte1)
> > > > call shiftOut(13, 15, 8, byte2)
> > > > [...]
> > > > call shiftOut(13, 15, 8, byte15)
> > > > call shiftOut(13, 15, 8, byte16)
> > >
> > > I guess the obvious question is whether you can put the 14 (or
16)
> > > bytes in an array. That way you need only pass the array by
> > > reference, instead of copying 16 bytes as parameters.
> > >
> > > -- Frank Manning
> > > -- NetMedia, Inc.
> >
> >
> >
> >
> >
>





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

Re: Re: Optimizing - Trevor Pinkney - Nov 29 11:50:00 2003

Hmmm,

You should still be able to use an array. Sounds like you need a global
array from 1 - 7 since there are only 7 bytes in your example and all 7
seem to be hardcoded so byte 2 will ALWAYS be shifted out first, followed
by byte1 etc.

Remove this line of code:
call litLed (arrayY(2), arrayX(1), arrayY(1), arrayX(5), arrayY(7),
arrayX(1), arrayY(1), arrayX(5), arrayY(1), arrayX(5), arrayY(2),
arrayX(5), arrayY(1), arrayX(1), arrayY(1), arrayX(1)) 'Add This
public shiftValues(1 to 7) As Byte

'In a function set the shift values... ie. shiftValues(1) = 1,
shiftValues(2)=80 etc.
'call litLed

public sub litLed()

call shiftOut(13, 15, 8, shiftValues(2))
call shiftOut(13, 15, 8, shiftValues(1))
call shiftOut(13, 15, 8, shiftValues(1))
call shiftOut(13, 15, 8, shiftValues(5))
call shiftOut(13, 15, 8, shiftValues(7))
call shiftOut(13, 15, 8, shiftValues(1))
[..]
call shiftOut(13, 15, 8, shiftValues(1))

end sub Hope this provides some additional incite. You should play around with
arrays and global variables. they take a while to get the hang of.

-Trevor

> functions in the program

At 05:39 AM 11/29/2003 +0000, you wrote:
>hey Trevor,
>thanks for your help.
>I am trying to do what you suggested but the problem is that there
>are values within the "litLED()" sub (in the parenthesis). it look
>like that:
>sub litLed (byval byte2 as byte, byval byte3 as byte, byval byte4 as
>byte...)
>and the 4th value inside the shiftout command refers to byte2,
>byte3...
>once I change it to be the X as integer shortcut an error msg comes
>up telling me that the dimensions of actual parameter don't match
>those of the formal parameter. and the first line of my "call
>litLed" is highlighted (line below).
>call litLed (arrayY(2), arrayX(1), arrayY(1), arrayX(5), arrayY(7),
>arrayX(1), arrayY(1), arrayX(5), arrayY(1), arrayX(5), arrayY(2),
>arrayX(5), arrayY(1), arrayX(1), arrayY(1), arrayX(1))
>
>during this arrays process the "byval byte2 as byte, byval byte3 as
>byte....." information in the "sub litLed" is omitted, and i believe
>it is essential(?).
>
>Limor >
>--- In , Trevor Pinkney <tpinkney@s...> wrote:
> > limorgarcia,
> >
> > Your code is the PERFECT example of code that could be improved by
>an
> > array. You want to do something like this:
> >
> >
> > Public shiftValues(1 to 16) As Byte 'Make the array accessible by
>all
> > functions in the program
> >
> > Public Sub Main()
> >
> > call InitShiftValues() ' a function that sets the values
> > call litLed()
> >
> > End Sub
> >
> > 'a simple function that sets the values
> > Public Sub InitShiftValues()
> >
> > shiftValues(1) = 0
> > shiftValues(2) = 1
> > shiftValues(3) = 233
> > shiftValues(4) = 232
> > shiftValues(5) = 0
> > '..
> > '..
> >
> > End Sub
> >
> > Public Sub litLed()
> >
> > dim x as integer
> >
> > ' loop through each item in the array
> > for x = 1 to 16
> > call shiftOut(13, 15, 8, shiftValues(x))
> > next
> >
> > End Sub
> >
> >
> > -Trevor
> >
> > At 02:45 AM 11/29/2003 +0000, you wrote:
> > >yes, i guess that's what i'm trying to do. put it all in an array
>to
> > >be referenced.
> > >I believe that the more lines in the code, the slower (or less
> > >smooth) the program will function (or am i wrong?).
> > >Arrays, as i gather, can encompass numbers (# to #), that's why i
> > >can't understand how to fill it with different values (like byte1,
> > >byte2, byte3 etc.)
> > >thanks for your help.
> > >limor
> > >
> > >--- In , "Frank Manning" <fmanning@n...>
>wrote:
> > > > From: limorgarcia <limorgarcia@y...>
> > > >
> > > > > syntax-wise, is it possible to optimize this part
> > > > > of my code?
> > > >
> > > > I suppose it depends on how you define optimum for this
>problem.
> > > > Do you want to minimize RAM? Maximize execution speed? Maximize
> > > > readability or maintainability?
> > > >
> > > > > sub litLed (byval byte1 as byte, byval byte2 as byte,
> > > > > [...], byte13 as byte, byval byte14 as byte)',
> > > > > [...]
> > > > > call shiftOut(13, 15, 8, byte1)
> > > > > call shiftOut(13, 15, 8, byte2)
> > > > > [...]
> > > > > call shiftOut(13, 15, 8, byte15)
> > > > > call shiftOut(13, 15, 8, byte16)
> > > >
> > > > I guess the obvious question is whether you can put the 14 (or
>16)
> > > > bytes in an array. That way you need only pass the array by
> > > > reference, instead of copying 16 bytes as parameters.
> > > >
> > > > -- Frank Manning
> > > > -- NetMedia, Inc.
> > >
> > >
> > >
> > >
> > >
> >





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

Re: Optimizing - limorgarcia - Nov 29 18:03:00 2003

thanks trevor
I have a feeling that 2d array should take place here.
I'll try that.

--- In , Trevor Pinkney <tpinkney@s...> wrote:
> Hmmm,
>
> You should still be able to use an array. Sounds like you need a
global
> array from 1 - 7 since there are only 7 bytes in your example and
all 7
> seem to be hardcoded so byte 2 will ALWAYS be shifted out first,
followed
> by byte1 etc.
>
> Remove this line of code:
> call litLed (arrayY(2), arrayX(1), arrayY(1), arrayX(5), arrayY(7),
> arrayX(1), arrayY(1), arrayX(5), arrayY(1), arrayX(5), arrayY(2),
> arrayX(5), arrayY(1), arrayX(1), arrayY(1), arrayX(1)) > 'Add This
> public shiftValues(1 to 7) As Byte
>
> 'In a function set the shift values... ie. shiftValues(1) = 1,
> shiftValues(2)=80 etc.
> 'call litLed
>
> public sub litLed()
>
> call shiftOut(13, 15, 8, shiftValues(2))
> call shiftOut(13, 15, 8, shiftValues(1))
> call shiftOut(13, 15, 8, shiftValues(1))
> call shiftOut(13, 15, 8, shiftValues(5))
> call shiftOut(13, 15, 8, shiftValues(7))
> call shiftOut(13, 15, 8, shiftValues(1))
> [..]
> call shiftOut(13, 15, 8, shiftValues(1))
>
> end sub > Hope this provides some additional incite. You should play around
with
> arrays and global variables. they take a while to get the hang of.
>
> -Trevor >
>
> > functions in the program
>
> At 05:39 AM 11/29/2003 +0000, you wrote:
> >hey Trevor,
> >thanks for your help.
> >I am trying to do what you suggested but the problem is that there
> >are values within the "litLED()" sub (in the parenthesis). it look
> >like that:
> >sub litLed (byval byte2 as byte, byval byte3 as byte, byval byte4
as
> >byte...)
> >and the 4th value inside the shiftout command refers to byte2,
> >byte3...
> >once I change it to be the X as integer shortcut an error msg
comes
> >up telling me that the dimensions of actual parameter don't match
> >those of the formal parameter. and the first line of my "call
> >litLed" is highlighted (line below).
> >call litLed (arrayY(2), arrayX(1), arrayY(1), arrayX(5), arrayY
(7),
> >arrayX(1), arrayY(1), arrayX(5), arrayY(1), arrayX(5), arrayY(2),
> >arrayX(5), arrayY(1), arrayX(1), arrayY(1), arrayX(1))
> >
> >during this arrays process the "byval byte2 as byte, byval byte3
as
> >byte....." information in the "sub litLed" is omitted, and i
believe
> >it is essential(?).
> >
> >Limor
> >
> >
> >
> >
> >
> >
> >--- In , Trevor Pinkney <tpinkney@s...>
wrote:
> > > limorgarcia,
> > >
> > > Your code is the PERFECT example of code that could be
improved by
> >an
> > > array. You want to do something like this:
> > >
> > >
> > > Public shiftValues(1 to 16) As Byte 'Make the array
accessible by
> >all
> > > functions in the program
> > >
> > > Public Sub Main()
> > >
> > > call InitShiftValues() ' a function that sets the
values
> > > call litLed()
> > >
> > > End Sub
> > >
> > > 'a simple function that sets the values
> > > Public Sub InitShiftValues()
> > >
> > > shiftValues(1) = 0
> > > shiftValues(2) = 1
> > > shiftValues(3) = 233
> > > shiftValues(4) = 232
> > > shiftValues(5) = 0
> > > '..
> > > '..
> > >
> > > End Sub
> > >
> > > Public Sub litLed()
> > >
> > > dim x as integer
> > >
> > > ' loop through each item in the array
> > > for x = 1 to 16
> > > call shiftOut(13, 15, 8, shiftValues(x))
> > > next
> > >
> > > End Sub
> > >
> > >
> > > -Trevor
> > >
> > > At 02:45 AM 11/29/2003 +0000, you wrote:
> > > >yes, i guess that's what i'm trying to do. put it all in an
array
> >to
> > > >be referenced.
> > > >I believe that the more lines in the code, the slower (or less
> > > >smooth) the program will function (or am i wrong?).
> > > >Arrays, as i gather, can encompass numbers (# to #), that's
why i
> > > >can't understand how to fill it with different values (like
byte1,
> > > >byte2, byte3 etc.)
> > > >thanks for your help.
> > > >limor
> > > >
> > > >--- In , "Frank Manning" <fmanning@n...>
> >wrote:
> > > > > From: limorgarcia <limorgarcia@y...>
> > > > >
> > > > > > syntax-wise, is it possible to optimize this part
> > > > > > of my code?
> > > > >
> > > > > I suppose it depends on how you define optimum for this
> >problem.
> > > > > Do you want to minimize RAM? Maximize execution speed?
Maximize
> > > > > readability or maintainability?
> > > > >
> > > > > > sub litLed (byval byte1 as byte, byval byte2 as byte,
> > > > > > [...], byte13 as byte, byval byte14 as byte)',
> > > > > > [...]
> > > > > > call shiftOut(13, 15, 8, byte1)
> > > > > > call shiftOut(13, 15, 8, byte2)
> > > > > > [...]
> > > > > > call shiftOut(13, 15, 8, byte15)
> > > > > > call shiftOut(13, 15, 8, byte16)
> > > > >
> > > > > I guess the obvious question is whether you can put the 14
(or
> >16)
> > > > > bytes in an array. That way you need only pass the array by
> > > > > reference, instead of copying 16 bytes as parameters.
> > > > >
> > > > > -- Frank Manning
> > > > > -- NetMedia, Inc.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> >
> >
> >
> >
> >
>




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