Fix the state (as buffer) of the variables into data memory by code.

Help
cosmok82
2013-11-24
2013-11-28
  • cosmok82

    cosmok82 - 2013-11-24

    Hi, I have this problem.
    After some nested FOR loops I set the 8 components of an array, that I want it be my memory buffer.

    But I hit its state, because it's result cicle after cicle clean (that is every component fixed to zero). This, obviously, compromise any effort to fix a memory buffer into data memory!

    Is there a method to specify the location of variable into data memory? with no changes of destination in memory running?

    The prefix "At" (in definition) seems not working...

     
  • cosmok82

    cosmok82 - 2013-11-25

    Into ram memory for me it's the same, as long as I can store at least 8 components array (not overwritable on runtime)!

     
  • Anobium

    Anobium - 2013-11-25

    Are you trying to achieve? What code do you have as your starting point?

    I am not sure I understand what you need? Are you trying to create a buffer (volatile) in non-program memory space? or, write static info to eeprom? or, something else?

    And regarding 8 components. Do you mean 8 elements?

     
    Last edit: Anobium 2013-11-25
  • cosmok82

    cosmok82 - 2013-11-25

    Not, no eeprom. I type an array like this into code:

    Dim LineOut(8)
    



    Where I'm going to store some data after a calculation.

    Back to writing subroutine, all data stored into it seem swept out! I didn't find a cause, but I think that the addressing of ram memory is dinamic into code compiled, so It could be caused from the space with no fixed addressing.

    So, I'm searching a method to fix the destination about memory space of specified array, that will be my buffer when the program will be in execution.

    A buffer that only changes if a subrutine have to access to it and with no change with on going subrutines.

    That's all.

    I don't know if I got it across.

     
  • Anobium

    Anobium - 2013-11-26

    Please post your code.

    I have used array extensively. I know of no issues.

     
  • cosmok82

    cosmok82 - 2013-11-26
    ;Variables
    Dim line As byte
    Dim index As byte
    Dim LineOut(8)
    Dim state As byte
    ...
    
    ;Data tables
    Table pixA
     b'.....'
     b'.....'
     b'.....'
     b'.....'
    End Table
    
    Sub ScrollIt
        For state = 5 To 0
            For index = 1 To 4
                ReadTable pixA, index, line
                Repeat state
                    line = line/2
                End Repeat
                SPIwrite index, LineOut(index) + line.1
                LineOut(index) = LineOut(index)*2
            Next
            Wait 200 ms
        Next
    End Sub
    



    The function ScrollIt create a scrolling text (on display) from left to right, but it writes only the first 6 components of the array LineOut. The result, instead, after the first call of ScrollIt is just the same animation, as if it were the first calling!

    Here's an example:

    00111110
    00100010
    00100010
    00111110



    then the result (after 6 cycles)...

    00111110
    00100010
    00100010
    00111110



    But it should be...

    00111110
    00100010
    00100010
    00111110


    01111101
    01000101
    01000101
    01111101


    11111011
    10001010
    10001010
    11111011


    11110111
    00010100
    00010100
    11110111


    11101111
    00101000
    00101000
    11101111


    11011111
    01010001
    01010001
    11011111


    10111110
    10100010
    10100010
    10111110



    Etc... etc...

     
    Last edit: cosmok82 2013-11-26
  • Anobium

    Anobium - 2013-11-26

    I have edited the code so that I can help. I have added the serial output so I can see the output prior to sending to the SPI device.

    I am not sure what chip you have, so, I am using 16f1937. The code you posted is incomplete so I guessed the missing pieces.

    My results are different from your expectations. I get the result shown at the bottom of this posting.

      ' This code depends on a clock frequency of 40 MHz (I use a 10 MHz crystal and
      ' the PLL.  If you are using a slower clock, then you must change the SPI and
      ' UART rates, as well as the delay lengths in delays.c
      #chip 16F1937, 32
      #config Osc = intOSC, MCLRE_ON, PLLEN_ON, VCAPEN_OFF
    
      #include "D:\Others\GCB@Syn\GreatCowBasic\include\outputserial.h"
      #include "D:\Others\GCB@Syn\GreatCowBasic\include\utils.h"
    
      ' Works via Max232.  Blue cable for in, Yellow cable for out.
      #define SendAHigh Set PORTa.5 Off
      #define SendALow Set PORTa.5 On
      #define RecAHigh PORTa.4 OFf
      #define RecALow PORTa.4 On
    
      Dir PORTa.5 Out
      Dir PORTa.4 In
    
      #define SerSendDelayms 5
      'Set up serial connection
      InitSer 1, r9600, 1+128, 8, 1, none, invert
    
      wait SerSendDelayms ms
      sersend 1,0x55
    
      ANSIERASECREEN_SW
      ANSI_SW ( 0,0)
      SerPrint 1, "Array Issue 001":crlf
    
      ;Variables
      Dim line As byte
      Dim index As byte
      Dim LineOut(8)
      Dim state As byte
    
      ScrollIt
    
      end
    
      'Data tables
      Table pixA
      1
      2
      3
      4
      End Table
    
      Sub ScrollIt
        For state = 5 To 0
            For index = 1 To 4
                ReadTable pixA, index, line
                Repeat state
                    line = line/2
                End Repeat
      '            SPIwrite index, LineOut(index) + line.1
                 outval = LineOut(index) + line.1
                 SerPrint 1, str(index)
                 SerSend  1, 9
                 ' Print out the values in binary
                  OutBin ( index )
                 crlf
                LineOut(index) = LineOut(index)*2
            Next
            Wait 200 ms
        Next
      End Sub
    
      Sub OutBin ( In realval )
    
        for lcount = 0 to 7
            if realval.7 = 1 then
               SerPrint 1, "1"
            else
               SerPrint 1, "0"
            end if
            rotate realval left simple
        next
    
      end Sub
    

    Results:

    Array Issue 001
    1 00000001
    2 00000010
    3 00000011
    4 00000100
    1 00000001
    2 00000010
    3 00000011
    4 00000100
    1 00000001
    2 00000010
    3 00000011
    4 00000100
    1 00000001
    2 00000010
    3 00000011
    4 00000100
    1 00000001
    2 00000010
    3 00000011
    4 00000100
    1 00000001
    2 00000010
    3 00000011
    4 00000100
    ~~~~~

    You need to correct this code please as I cannot. :-)

     
    • cosmok82

      cosmok82 - 2013-11-26

      I think you have my same problem Anobium, also my code isn't able to remember the pre-state from which it's started after first loading and it continues to re-propose the same array.

       
  • Anobium

    Anobium - 2013-11-26

    The results are as I expected as I am re-reading the table each iteration.

    I am still not sure I understand what you are trying achieve. The results are as I expected because currently you are re-reading the table which WILL reset it.

    Be patient with me. Can you give me more insights into what you are trying to achieve. Tell me what you want to achieve not the issues you are having with coding.

    Anobium

     
  • cosmok82

    cosmok82 - 2013-11-26

    All passes are:
    Read one Table -> charge it into array components -> write all array components, just one at time, over SPI.

    If I follow this procedure with a subrutine/function the next iteration not report the remainder of previous iteration into array, but the array results be wiped.

    So, I say to you in advance that I found a solution. It requires to set up the eeprom memory to host the contents of all data tables or buffer variables if necessary, but I don't know if the .hex file could host the eeprom memory state to be written (of if the compiler can do it).

    So, could you tell if it's possible?

     
  • kent_twt4

    kent_twt4 - 2013-11-27

    Going forward these inquiries should be in the HELP section of the forum. That is unless their is indeed a problem with the compiler.

    I have done animation or scrolling with a GLCD before. The beginnings of the code are correct by loading a buffer variable from a TableRead. The actual scroll code looks a bit off, so here is some helper code that compiles and works with the 12f683.

    The animation routine will work continuously. Please ignore the soft serial routines, I think you can spot them :).

    EDIT: i.e. compiles with my own soft serial subs which have been omitted for space reasons.

    ;Chip Settings
    #chip 12F683,8
    #config OSC=INTRC_OSC_NOCLKOUT
    dim row(4)
    
    Wait 2 s
    
    Ser_Init
    
    for rows = 1 to 4
        ReadTable pixA, rows, row(rows)
    next
    'wait 1 s
    start:
    for animate = 1 to 8
        for scroll = 1 to 4
            bin2ascii row(scroll)
            wait 30 ms
            Xmit_RS232 10, 13
            wait 30 ms
            rotate row(scroll) Left Simple
        next
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
    wait 2 s
    next
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
    wait 5 s
    goto start
    
    Table pixA
     b'00000001'
     2
     4
     8
    end table
    
     
    Last edit: kent_twt4 2013-11-27
    • cosmok82

      cosmok82 - 2013-11-27

      The approach of Kent it's as mine (if you read previously). But the array (buffer array) works with execution on going (FOR cycle), not when the program iterate ITSELF AGAIN.

      That's for me, at any rate.

      So, at least, if you want to use the array as buffer! That is if you want to find again the last initializing it wrote with FOR cycle! Do you understand? That's what I mean!! (and what I want...)

      I think a good solution should be write to eeprom on going. And, put there all my data arrays it's a good idea if I can't aliased the Tables on program memory.

      Or, do you know a method to aliased the Tables in program memory? (just like a multi-array...)

      So, don't wander off the points, they are:
      - create an alias for a Table, an indexed alias (like tab[index]), to re-call it
      - put data in eeprom through compiler (or to put better a .hex with eeprom data attached)

      This two methods are good (for me) to make a scalable animation with datas. Just one should be enough!

       
      Last edit: cosmok82 2013-11-27
  • Anobium

    Anobium - 2013-11-27

    I would agree with Kent. Stick with the table approach.

    I have also moved this to the Help Forum.

     
    Last edit: Anobium 2013-11-27
    • cosmok82

      cosmok82 - 2013-11-27

      Please, read you previously first!

       
  • Anobium

    Anobium - 2013-11-27

    I did, and I changed my point of view after reading Kent posting. I may have been confused for that I am sorry.

    There is a method to simple method to write to the device eeprom. See below. I really hope that this is what you are looking for.

    If you have any issues with the code, please ensure you have the latest version of GCB that supports this across a greater number of devices. GCB after 7/2013.

     #chip 16F628
    
     'Read table item
     'Must use ReadTable and a variable for the index, or the table won't
     'be downloaded to the EEPROM within the device.
     TableLoc = 2
     ReadTable TestDataSource, TableLoc, SomeVar
    
     'Write to table (example, can change)
     EPWrite 1, 45
    
     'Table of values to write to EEPROM
     'EEPROM location 0 will store length of table
     'Subsequent locations will each store a value
     Table TestDataSource Store Data
        12
        24
        36
        48
        60
        72
     End Table
    
     
    • cosmok82

      cosmok82 - 2013-11-27

      I have updated to the last version 1.0 21/9/2013. I'm hoping it works...

      I didn't know the method "Store Data" for Tables. It's interesting! Thanks Anobium.

      I compiled the code and the state of eeprom is:

      00 0x06 0x0C 0x18 0x24 0x30 0x3C 0x48

      What I don't understand is the "0x06" at beginning of eeprom memory (for the Table) after compiling, which is?

      At the end, Is the name of Table indexable? Maybe with an alias...
      It's a good idea if I want to write operations in sequence. Is it possible?


      Ok, found it, 0x06 is the number of records...

       
      Last edit: cosmok82 2013-11-27
      • Anobium

        Anobium - 2013-11-27

        Post the code you are using, please.

        my guess. you have a table of six numbers, 12, 24, 36, 48, 60 and 72. The 0x06 is the length of the table. But, the 00 at the start. No idea.

        So, a table has a length (its first number), the numbers to the specified length.

         
  • kent_twt4

    kent_twt4 - 2013-11-27

    Sticking with comok82 Table method, and indexing the buffer for the different tables thru the select case flow control. Using the buffer allows the most options in terms of mixing the tables up in any sequence you would like.

    So, building on my previous code:

    ;Chip Settings
    #chip 12F683,8
    #config OSC=INTRC_OSC_NOCLKOUT
    dim row(4)
    dim tab(3)
    tab = 1, 3, 2
    Wait 2 s
    
    Ser_Init
    
            'for rows = 1 to 4
            '   ReadTable pixA, rows, row(rows)
            'next
            'wait 1 s
    
            'tab = 0
    start:
    for index = 1 to 3
            'tab = tab(index)
            'tab += 1
            'If tab = 4 then tab = 1 
    Select Case tab(index)
        Case 1
            for rows = 1 to 4
                ReadTable pixA, rows, row(rows)
            next
            Call animate_table
        Case 2
            for rows = 1 to 4
                ReadTable pixB, rows, row(rows)
            next
            Call animate_table
        Case 3
            for rows = 1 to 4
                ReadTable pixC, rows, row(rows)
            next
            Call animate_table
    end select
    wait 2 s
    next
    goto start
    
    sub animate_table
    for animate = 1 to 8
        for scroll = 1 to 4
            bin2ascii row(scroll)
            wait 30 ms
            Xmit_RS232 10, 13
            wait 30 ms
            rotate row(scroll) Left Simple
        next
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
    wait 30 ms
    next
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
            Xmit_RS232 10, 13
    'wait 2 s
    end sub
    
     
    • cosmok82

      cosmok82 - 2013-11-27

      Of course kent_twt4, but the Case Statement isn't the very best!

       
      • kent_twt4

        kent_twt4 - 2013-11-27

        It works :). Should have pulled the "Call animate_table" outside the Select Case statement. I anxiously await the very best! I'm done for now.

         
  • Marcoos

    Marcoos - 2013-11-28

    Sorry for the out of tread, but I'm confused, Anobium here above says to use the latest version of the compiler, while Syn_write reports:
    btw:
    I got a pm from user Anobium That the latest compiler update (Version 0.9 09/22/2013) Suggested he is buggy and not to use it for the GCB @ Syn. I know the actual CGB@Syn.ZIP download contains the previous GCB-compiler again (Version 0.9 04/21/2013).

    regards
    Steini

    other reports post:
    I have updated to the last version 1.0 09/21/2013. I'm hoping it works ...

    I do not find this version, I think the last one is the 0.9 of 22/09/2013.
    you clarify please?

     
  • Anobium

    Anobium - 2013-11-28

    The version in the Syn@ is 0.9 22/9/2013. See https://sourceforge.net/p/gcbasic/discussion/629990/thread/56f698f5/#519d . To my knowledge this is the latest available release. As always, I am ready to be corrected.

    And yes you are correct, there was an issue in an early September release.

    I am personally running 0.9 6/10/2013 to test one or two fixes that Hugh has fixed, which I have been using on test.

     
    Last edit: Anobium 2013-11-28
  • Marcoos

    Marcoos - 2013-11-28

    Ok
    Thank you very much for the clarification, I download the version indicated awaiting the release of the one you are in beta testing.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks