Shop OBEX P1 Docs P2 Docs Learn Events
copy or fill a range of cogram — Parallax Forums

copy or fill a range of cogram

I need a buffer for ADC samples of multiple pins. Then I have to do some complex calculations on them. Because the calculations take some time and I don't want the samples to be overwritten before I'm done I have to use double buffering. New samples are added into the buffer values for averaging. So I have to clear the buffer before it's re-used.

Is there a trick to copy a range of cogram registers to another range or to fill multiple registers with zeroes? At the moment I'm using setq+wrlong/rdlong to/from an intermediate buffer in hub ram. This takes about the same time as a loop with ALTS/D indexing but is much simpler.

Is there a more elegant way, maybe with the streamer? Or a more clever way of indexing?

Comments

  • cgraceycgracey Posts: 14,153
    There is no more economical shortcut than SETQ+RD/WRLONG. I've struggled with the same thing. And you can do 'SETQ+WRLONG #0,addr' to clear a section of hub RAM before loading it into registers to clear them.
  • Ok, thanks, Chip.

    BTW, your ADC and DAC tutorials were really informative. And using the P2 as scope to visualize or debug it's own output is really brilliant.
  • Untested, but this should fill cog memory with zeroes, if the documentation isn't lying and the unmapped RAM area indeed reads zeroes:
    SETQ #how_much
    RDLONG where,##$80000
    
  • cgraceycgracey Posts: 14,153
    Wuerfel_21 wrote: »
    Untested, but this should fill cog memory with zeroes, if the documentation isn't lying and the unmapped RAM area indeed reads zeroes:
    SETQ #how_much
    RDLONG where,##$80000
    

    Yes! That would work.
  • Cluso99Cluso99 Posts: 18,069
    Nice one. BTW Tested and works!
    I'm adding it to the tricks and traps thread.
Sign In or Register to comment.