Shop OBEX P1 Docs P2 Docs Learn Events
More efficient serial — Parallax Forums

More efficient serial

lboucherlboucher Posts: 139
edited 2009-07-01 03:00 in General Discussion
HI All

So i wrote a peice of SX code at work.
My project works, but i am using like 95%+ of the space on the SX28. Which leaves little room for future expansion.

So two questions.
Is there a hardware solution to get more program and or data space?

second
Most of my program involves sending and receiving strings.
I cannot post the real program, but below is the gist of what i have done.
Can i make this more efficient?
(Note that the send and receives may be at different baud·and pin settings, thus why i made 4 sub functions.)

Thanks a bunch

DEVICE SX28, OSCHS2, TURBO, STACKX, OPTIONX

FREQ 50_000_000

'DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX

'DEVICE SX28, OSCHS2, TURBO, STACKX, OPTIONX

'FREQ 4_000_000

ID "Something"







' =========================================

PROGRAM Start

' =========================================



TX_COMMAND_BYTE SUB 1

RX_COMMAND_BYTE SUB 0

TX_DATA_BYTE SUB 1

RX_DATA_BYTE SUB 0

Start:



Main:

FOR idx = 0 TO 26

read monitor_log+idx,send_byte

TX_COMMAND_BYTE send_byte

NEXT

FOR idx = 0 TO 7

TX_DATA_BYTE up_or_down(idx)

NEXT



for idx=0 TO 7

if constant_log = 0 then

something_1(idx) = RX_DATA_BYTE

else

something_1(idx) = RX_COMMAND_BYTE

endif

next

GOTO Main

SUB TX_COMMAND_BYTE

SEROUT tx_commands, COMMAND_BAUD_RATE, __PARAM1 ' send the character

ENDSUB

SUB TX_DATA_BYTE

SEROUT tx_data, DATA_BAUD_RATE, __PARAM1 ' send the character

ENDSUB

SUB RX_COMMAND_BYTE

SERIN rx_monitor_pin, COMMAND_BAUD_RATE, subroutine_temp1,100,No_Data ' wait for serial input

RETURN subroutine_temp1 ' return to caller

ENDSUB

SUB RX_DATA_BYTE

SERIN rx_data_pin, DATA_BAUD_RATE, subroutine_temp1,100,No_Data ' wait for serial input

RETURN subroutine_temp1 ' return to caller

ENDSUB



monitor_log:

DATA "Something i cannot put here",13

Post Edited (lboucher) : 6/13/2009 2:49:11 AM GMT

Comments

  • lboucherlboucher Posts: 139
    edited 2009-06-15 03:21
    No ideas out there?
  • pjvpjv Posts: 1,903
    edited 2009-06-15 16:11
    Iboucher;

    It's hard for volunteers to help when details of what you are trying to do are not available, and no comments in the code. I'm a person who likes a challenge, but I expect the other party to do the work..... I try to give pointers so that they can learn.

    As far as filling up your program space..... without studying your code, and based on my experience, I would estimate what you are attempting to consume 256 bytes if written tightly in assembler, and 2 times that in SX/B.

    So look at the SX/B output listings, and see where all the space has gone, and make improvements accordingly.

    Cheers,

    Peter (pjv)
  • lboucherlboucher Posts: 139
    edited 2009-06-16 22:44
    Wish i could put details, but i really cannot cause of work.
    Sorry for the lack of comments, thought the code was generally self explanitory.
    Just trying to send and receive various length sequences of various characters.

    Really just wondering if there is a way to get rid of all the for loops, and make a biggers subfuction that handles the for loop.

    Lucas
  • lboucherlboucher Posts: 139
    edited 2009-06-17 00:52
    So ya,

    now that i drove home, sorry i wasn't completely clear.

    So let me try again
    Given this part of the main program


    FOR idx = 0 TO 7

    TX_DATA_BYTE monitor_log(idx)

    NEXT

    How do i move the FOR loop inside the sub function??????

    SUB TX_DATA_BYTE

    SEROUT tx_data, DATA_BAUD_RATE, __PARAM1 ' send the character

    ENDSUB

    And i am sending the data contained in the string monitor_log:

    monitor_log:

    DATA "Something i cannot put here",13

    And i cannot put the reference to monitor_log into the sub function because there would be several different strings stored in data. (Maybe i can get around this by simply an index, since i know all the different strings ahead of time, i just have to be careful not to repeat the serout functions. Hummmm.)

    Any help greatly appreciated.

    Thanks

    Lucas
  • lboucherlboucher Posts: 139
    edited 2009-06-17 01:06
    Ahh i got it

    Define the sub function with two variables.
    1 being string length
    1 being string reference number

    so

    TX_DATA_BYTE 1 7 (where 1 is string reference, and 7 is length.

    then the sub funtion

    SUB TX_DATA_BYTE

    for idx = 0 to __PARAM2
    if __PARAM1 = 1 then
    send_byte=monitor_log(idx)
    endif
    if __PARAM1 = 2 then
    send_byte=some_other_string(idx)
    endif

    SEROUT tx_data, DATA_BAUD_RATE, send_byte ' send the character

    next
    ENDSUB
  • lboucherlboucher Posts: 139
    edited 2009-06-17 01:35
    Hum looks like that saves only 2 instructions.
    Maybe if i assume the data is stored together i can simplify this more.

    Meaning

    if i have two strings

    string_1:
    DATA "STRING_1"
    string_2:
    DATA "STRING_2"

    then, i think
    string_1(9) = "S"

    then i can get rid of the if in the sub function
    i just have to pass a the start location and number of charaters to the sub function instead of an index and number of characters.

    Heck i quess i should just store all the strings in one long data entry.

    Cool
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-17 12:13
    Hi I have used the following which transmits a zero terminated string. It's not much different or efficient to what you have but it works well and its easy to use.
    Tx_String  sub 2       'declaration
    Tx_String @string_1    'usage
    Tx_String @string_2
        
    Tx_String:             'writes strings terminated with 0 
    Addr= __Wparam12       'Addr is a word value
    do
    READ Addr,char
    IF char=0 THEN EXIT
    inc Addr
    serout tx,baud,char 
    loop
    RETURN
    string_1:
    DATA "STRING_1",0
    string_2:
    DATA "STRING_2",0
    

    Jeff T.
  • PJMontyPJMonty Posts: 983
    edited 2009-06-18 23:55
    lboucher,

    You say you're using 95% of the EEPROM space, and that your app mainly involves involves sending and receiving strings. So. my question to you is how much of the EEPROM space is used to store strings currently? In other words, if you're using 80% of the EEPROM space just to store strings, then what you need to do is either shrink the size of your strings or move them to an external serial EEPROM.

    Thanks,
    PeterM
  • lboucherlboucher Posts: 139
    edited 2009-07-01 03:00
    Hi

    I have managed to shrink everything down to about 80% of the EEPROM. I don't have the code in front of me, but no more than 10-15% was stored strings. Most of the program was receiving strings and parsing data correctly. I have never added EEPROM before. If i get to that point i will have to give it a try.

    Lucas
Sign In or Register to comment.