This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Fast way to zero out an array

Other Parts Discussed in Thread: CONTROLSUITE

Hello! So I have several buffers that i am periodically having to set all the values in the array to zero, and sometimes having to only set half of the array to zero. Is there a really fast way of doing this besides just using a for loop or by individually setting all the values to zero in line? I was hoping there might be a way to set a couple pages in ram to all have a value of zero or something. Anyways, thanks for any suggestions!

Also, i'm using the F28069. Thanks!

-Greg w.

  • Greg,

    Unfortunately there isn't any hardware feature which clears memory for you (it would be nice if there was) so it's a matter of doing it the long way in code.

    In case it helps, there are some routines in the Digital Controller Library which I find useful for array management.  The library is in controlSUITE at:

    C:\ti\controlSUITE\libs\control\DCL\v1_00_00_00\docs

    Regards,

    Richard

  • Hello Gregory,

    You could use the DMA to clear the memory. Just fill a separate RAM area with zero immediately after the program starts. Then, whenever you need to clear the buffer, just start aDMA transfer of those zeros to the buffer area.

    The advantages of using the DMA to clear the buffers are as follows:
    1. 4 cycles to complete transfers, which is quite fast (at 90MHz, that's 44ns for every transfer).
    2. Transfers 32 bits at a time, so if you data is 16bit data the transfer would be twice as fast.
    3. The transfer is done in the background.

    Stephen

  • Thanks for the DMA suggestions! I'll try to give that a shot. There is an exampled called "DMA ram to ram". I'm assuming i can look here as a first approach to clearing my ram this way, right? Thanks again!
  • Greg,

    When you configure your DMA, you do not need to allocate an equal size zeroed-out memory block. Just point to a single  zeroed-out 32-biit (or 16-bit) register, you can then. You would then set your DMA source to loop and wrap back to that single location. 

    This should save you some memory space if its already at a premium.

    -Mark

  • Hello Greg,

    Yes, you can use that example.  If my post helped, please click verify.

    Thanks,

    Stephen