Shop OBEX P1 Docs P2 Docs Learn Events
ADC sampling at fixed rate — Parallax Forums

ADC sampling at fixed rate

WeavWeav Posts: 2
edited 2009-10-24 22:21 in Propeller 1
Can anybody suggest a mod to the 3208 & family drivers, to sample at a fixed rate (I need 8 KHz)?
The driver itself seems to use both counters. so I can't immediately see how to nail down a 125 uS sampling interval.
Any thoughts?

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-24 18:04
    8KHz is slow enough so the timing can be done in Spin. Use one of the MCP3208 drivers. I looked at "MCP3208 fast ADC 12 bit 8 channel" which has an "in" method to get a sample. I'd just use WAITCNT to provide a 125us sampling interval.
    OBJ adcObj : "MCP3208_fast"
    PUB fillBuffer(bufferSize, bufferAddress, channel, delayTime) | i, waitTime
    '  Fills a supplied buffer with samples from an MCP3208 ADC at regular intervals.
    '  Note that adcObj.start needs to be called before calling this routine.
    '  See the comments in MCP3208_fast for how to call that.
    '
    '  bufferSize is the number of (word) entries in the buffer
    '  bufferAddress is the address of the start of the buffer
    '  channel is the number of the ADC channel to use
    '  delayTime is the time between samples in microseconds
    '
       delayTime *= clkfreq / 1_000_000     ' Convert from microseconds to clock ticks
       waitTime := cnt     ' Get a starting time
       repeat i from 0 to bufferSize-1     ' Repeat for specified number of samples
          waitcnt(waitTime += delayTime)     ' Wait for specified time (first interval is not used)
          word[noparse][[/noparse] bufferAddress ][noparse][[/noparse] i ] := adcObj.in(channel)     ' Read and store a 12 bit sample
    
  • WeavWeav Posts: 2
    edited 2009-10-24 22:21
    That looks like the thing. Thank you! If I need a sigma-delta DAC I can use a separate object.
Sign In or Register to comment.