Shop OBEX P1 Docs P2 Docs Learn Events
Exchange AD samples between cogs — Parallax Forums

Exchange AD samples between cogs

kgrgbgkgrgbg Posts: 4
edited 2014-01-06 16:57 in Propeller 1
Hi,

I am totally new to Propeller programming and have the following thing to resolve:
sample sound with one cog and then apply a FFT with another cog and then displatch a series of WS2812 LED bytes with a 3rd COG.

I am about to base my program on the microphone to headphones sample delivered with the propeller tool which does the sampling in assembler.
As a first thing I am working on separating the sampling and the audio output which requires to move the data from one cog to another cog.

However, I am currently stuck with the question how I can forward any sampled data from the AD cog to the other one that would do processing on the data.
As far as I have understood the Propeller this is a hub action and would require to sync with the hub memory access window and this would mean that my audio sampling is interrupted for a short period of time.

So it seems to me that it does not make any sense to move every sample over to global RAM but fill a cog buffer with some audio, maybe 512 bytes and then batch move that to the hub.
But still my sampling would get interrupted for a bunch of cycles.

Is there any DMA thing that would transfer in the background?

Thanks and regards,
Conny

Comments

  • JonnyMacJonnyMac Posts: 9,108
    edited 2014-01-04 17:45
    No DMA. The only way to exchange values between cogs is to have those values in the hub. Don't move the values to the hub, just use the hub in your code. Each hub access cycle allows the cog to read or write one long. If you need to read/write more than that before another cog has access, you'll need to use a lock.
  • kgrgbgkgrgbg Posts: 4
    edited 2014-01-04 17:48
    Thanks for the quick answer.

    Ok, not moving the data does make total sense to me.
    Does that mean if I apply a lock I can access that memory area of the hub any time?
    Then I could have to buffers in the hub RAM for my sampler and always fill one (with lock), the other one being read by the other cog processing the data?
  • JonnyMacJonnyMac Posts: 9,108
    edited 2014-01-05 10:05
    Keep in mind that looks are voluntary. Your "producer" cog would set a lock before writing new data to the hub. Any "consumer" cog would check that lock before reading. Again, this is only necessary if your producer cog needs to write more than one long before the data is accessed by consumer cogs.
  • kgrgbgkgrgbg Posts: 4
    edited 2014-01-05 16:34
    Hi Jonny,
    that doesn't exactly answer my question.
    The key concern I have is that there is a delay due to the hub sync when transferring the data to to the "consumer" cog.
    When sending each samples byte I will hardly be able to keep my sample rate. When batch transferring the data to the global ram I have an interruption in my sampling for the time I am transferring the data. Suppose the sync is the smaller issue in the latter case.
    I am even thinking about the idea to use the IO pins to transfer each byte to another cog - producer cog sets 8 or 12 GPIOs accordingly, plus one that signals new data, consumer cog polls the signal line and reads the value.
    Pretty hacky, though. Is there any shared registers or something I could use for the same thing?
    Regards,
    Conny
  • kgrgbgkgrgbg Posts: 4
    edited 2014-01-05 17:02
    Mmh, just finding that with a Propeller running at 80 Mhz and a sample rate of 20 kHz each sample has a window of 4.000 clock cycles.
    So I should be able to add the storing of one sample to global RAM into the waiting for the next sample time.
    I could do my transfer of the value to global RAM before the WAITCNT instruction and should then be fine.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2014-01-06 16:57
    Which ADC are you using? I have used an MCP3201 running at a 100khz sample rate. In the object I posted (admittedly rather crude compared to where it was going when I had to back burner it) the sample was being shifted to use the pins I wanted to feed into a homebuilt 12 bit r2r DAC. The ADC was using 5v supply to allow for maximum clockrate. There are screen shots from my 2247A scope on a couple threads. Also the source of my current avatar. Google "fun deviation into ADC/DAC"
Sign In or Register to comment.