Menu

Very Big Array

2019-09-20
2019-09-27
  • Giovanni Di Maria

    Hi.
    I must create an array of bytes of 7000 elements. Also constant of array is ok.
    I use the PIC 18F452.
    How can i store so much data with Great Cow Basic?
    Thank you very much.
    Giovanni

     
  • Anobium

    Anobium - 2019-09-20

    You create the array and access the elements.

    What have you tried? or, is this a 'how do I create an array?'

     
  • Giovanni Di Maria

    Hi.
    Thank you.

    I create the array with this:

    dim MyArray(7000) as byte
    MyArray(1)=120
    MyArray(2)=220
    MyArray(3)=40
    MyArray(4)=88
    MyArray(5)=12
    MyArray(6)=46
    MyArray(7)=87
    MyArray(8)=13
    MyArray(9)=77
    ......
    ......
    .......

    Of course, the error is:
    Error: The array MYARRAY is too large

    Thank you
    GIovanni

     
  • Anobium

    Anobium - 2019-09-20

    The 18F452 has 1536 bytes of RAM. Some of which will be used by varialbes and therefore it is not possible to use a dynanic array of 7000 elements in 1536 bytes.

    So, you need to use a different approach. You will have to use PROGMEM as your array memory. This is slower than RAM but can work on these small memory chips. You will need to use ProgramWrite (with ProgramErase) to create and update, and, use ProgramRead to read. You will need to create a 32 byte buffer to support this activity.

    BUT, what is the 7000 byte array doing? We may be able to advise if you tell us what you are up to.

    OR, you can simple buy a chip that works for you. You are aware that Microchip would not recommend the 18f452 for new projects. So, I would advise the PIC18F47K42 it has 8192 bytes of RAM and I am assuming that the other variables will be fit.

     
  • Giovanni Di Maria

    Ok. Anobium - Thank you very much for your suggestion.
    I will try it.
    I am storing the 7000 samples of a phrase to let to speech the PIC. This project of mine was published on the italian magazine "Fare Elettronica".
    I already done this but now i want to reproduce a longer phrase.
    Ok, thank you very much!!!!
    Giovanni

     
  • Giovanni Di Maria

    Hi
    I have solved with Lookup Table, in effect
    i must only read the values, not write them.

    ==========================

    Table Valori as Byte
    117
    127
    127
    23
    87
    3
    .......
    End Table

    dim k as word

    for k=1 to 7721
    ReadTable Valori, k, Letto
    portb=Letto
    wait 167 us
    next k

    ==========================
    Thank you to every body!!!
    Giovanni

     
  • mkstevo

    mkstevo - 2019-09-21

    Just a quick note which may be useful. It is possible to have your program report the size of the table for you. That way you wouldn't need to use a fixed value in your For...Next loop.

    Table Valori as Byte
    117
    127
    127
    23
    87
    3
    .......
    End Table
    
    
    dim k as word
    Dim TableLen As Word
    ReadTable Valori, 0, TableLen 'Get the length of the table
    for k=1 to TableLen
      ReadTable Valori, k, Letto
      portb=Letto
      wait 167 us
    next k
    

    If you added or removed items in the table, your code will automatically adjust to the new length of the table.

     

    Last edit: mkstevo 2019-09-21
    • Anobium

      Anobium - 2019-09-22

      @MKStevo - nice! Will add this to the FAQ!

       
  • bed

    bed - 2019-09-26

    A FAQ Entry needs a question
    Suggestions?
    Or how about a snippet Entry?

     
  • bed

    bed - 2019-09-27

    I published this:
    http://gcbasic.sourceforge.net/Typesetter/index.php/FAQ (Last Entry) Improvements, complaints? report to me :-)

     
    • Anobium

      Anobium - 2019-09-27

      :-) Love it.

       

Log in to post a comment.