Shop OBEX P1 Docs P2 Docs Learn Events
Does Sigma-Delta ADC always require its own cog? — Parallax Forums

Does Sigma-Delta ADC always require its own cog?

LarryGLarryG Posts: 50
edited 2010-05-08 13:03 in Propeller 1
I have found several Sigma-Delta objects. But it seems each one requires its own cog. I just need a real simple way to read an analog voltage from an accelerometer. I just need to grab a reading about once a second or so, do not need continuous reading. Range is about 1v to 3v. I am out of cogs. Any ideas?

Thank you.

-Larry

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-08 00:49
    You can do the sigma-delta conversion in Spin if you have a counter to spare. The integration time will probably be longer than it would have been in assembly, but that shouldn't be a problem.

    -Phil
  • LarryGLarryG Posts: 50
    edited 2010-05-08 11:43
    Thanks Phil. I was reading "Programming, Customizing..." book page 162. It mentions an object called "SigmaDeltaADC(SPIN)". I checked the sticky-thread in the forum for the PE Kit Labs, but the object is nowhere to be found. I think it falls under the section titles "coming soon".

    If anyone has the object SigmaDeltaADC(SPIN) I would appreciate a copy.

    Thanks.

    -Larry
  • hover1hover1 Posts: 1,929
    edited 2010-05-08 12:34
  • LarryGLarryG Posts: 50
    edited 2010-05-08 12:43
    Wow, thanks Jim! I searched, Googled, etc. for about an hour for that.
  • ErNaErNa Posts: 1,752
    edited 2010-05-08 12:50
    This may help:

    Dat
    mADCIdx      long  0     ' Gemultiplexter ADC: von ADCInPin bis ADCPutPin-1
    mADC_MuxO                ' Number of counts to have zero result for grnd voltage on analog input
    mADC_MuxO0   long  537   ' Offset  first  input    
    mADC_MuxO1   long  514   ' Offset  second input  
    mADC_MuxO2   long  569   ' Offset  third  input 
    mADC_MuxO3   long  541   ' Offset  forth  input 
    mADC_MuxV
    mADC_MuxV0   long  0     ' counts  first  input  
    mADC_MuxV1   long  0     ' counts  second input  
    mADC_MuxV2   long  0     ' counts  third  input  
    mADC_MuxV3   long  0     ' counts  forth  input  
    mADC_Val
    mADC_Val0    long  0     ' normalized input value
    mADC_Val1    long  0     ' 
    mADC_Val2    long  0     ' 
    mADC_Val3    long  0     '
     
    ADC_Offs     long  ADC_def_Offs     ' ADC offset
    ADC_Valu     long  0     ' ADC counts 
    ADC_Norm     long  0     ' ADC value, normalized
    
    ADCRunTim    long  0     ' Runtime of last convertion
    
    con
      mADCOutPin = 26      ' Multiplexed ADC: compensation pulses
      mADCInPin  = 22      ' Pin 22 up to ADCOutPin: analog inputs
      mADC_Nmbr  =  4      ' Number of channels to scan  
      ADCOutPin  = 16      ' single measurement: compensation pulses
      ADCInPin   = 17      ' single measurement: analog inputs
      ScalF_ADC  = 1000    ' Scaling factor ADC
    PUB Main
      ' Enable muxed ADC
      DIRA[noparse][[/noparse]mADCOutPin]~~             ' Pin to output compensation pulses
      CTRA := %01001_000 << 23  +  mADCOutPin << 9  + mADCInPin + mADCIdx
      FRQA := 1                     ' mode: ADC
      ' Enable single ADC    
      DIRA[noparse][[/noparse]ADCOutPin]~~             ' Pin to output compensation pulses     
      CTRB := %01001_000 << 23  +  ADCOutPin << 9  + ADCInPin
      FRQB := 1                     ' mode: ADC
    
      ADCRunTim := cnt  ' First convertion
      ADC_Valu  := phsb 
    
      repeat
         MuxADC
    
    
    PRI MuxADC  'Multiplexed ADC and "normal" ADC
    {
    ADC is scanned 20 ms. Value from 0 - 4095 full scale
    This ADC measures non time critical voltages
    
      'MUX-AD-Converter: feedback Control Output mADCOutPin, Inputs: starting from mADCInPin
    
    
      These ADC's are handled in the main routine in poll-mode
    
      MuxADC is called, checks for elapsed time and reads next channel.
      The output value is counts/time, normalized to 12 bits
    
    
      ADCOutPin Output compensation pulses
      ADCInPin  Input, actively controlling output
      ADC_Nmbr  Number of multiplexed channels
      ADCIdx    actual index from 0 to ADC_Nmbr-1
      ADCMuxO   offset, the value determined at input voltage 0 (gnd)
    }
      if  cnt - ADCRunTim >  clkfreq/500 '   measure if more than 2 ms elapsed  ( if longer time: take care of shift operation: overflow!)
    
         ADC_Valu           := phsb - ADC_Valu
         mADC_MuxV[noparse][[/noparse]mADCIdx] := phsa - mADC_MuxV[noparse][[/noparse]mADCIdx]  ' number of counts during last sequence
         ADCRunTim          := cnt  - ADCRunTim           ' time elapsed
    
         ADC_Morm := ((ADC_Valu<<12 / ADCRunTim - ADC_Offs) * ScaF_ADC) ~>12    ' shift: possible overflow!
         
         mADC_Val[noparse][[/noparse]mADCIdx]  := ((mADC_MuxV[noparse][[/noparse]mADCIdx]<<12 / ADCRunTim ) - mADC_MuxO[noparse][[/noparse]mADCIdx]) <<12 / (4096- mADC_MuxO[noparse][[/noparse]mADCIdx])
    
         mADCIdx            := (mADCIdx+1) // ADC_Nmbr                      ' next index
         CTRA := %01001_000 << 23  +  mADCOutPin << 9  + mADCInPin+mADCIdx  ' Activate new control input
         ' optional: wait 100 µs to increase precision 
         mADC_Valu          := phsb 
         mADC_MuxV[noparse][[/noparse]mADCIdx] := phsa
         ADCRunTim          := cnt
    
    



    As the integration time influences the result, the tick count has to be normalized to the elapsed time. At full scale, the ticks are equal to clock cycles and therefor, to have a result >1 , the ticks have to be shifted. Also take into account, that 0V doesn't give zero counts.
    It is also shown, how to measure more inputs with a single counter. Just connect the compensation output to different compensation networks and dynamically switch the compensation input of the counter. It works quite well, determine the offset by grounding the input. The result is not depending on the actual cycle time, therefor the routine can be called more or less periodically, if only you take care of the overflow. As full input gives an overflow after 50 seconds, measuring less than 100 hz will create an overflow if the shift value is 12 bits.-

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cmapspublic3.ihmc.us:80/servlet/SBReadResourceServlet?rid=1181572927203_421963583_5511&partName=htmltext
    Hello Rest Of The World
    Hello Debris
    Install a propeller and blow them away wink.gif
  • LarryGLarryG Posts: 50
    edited 2010-05-08 13:03
    Thanks ErNa. I never would have thought to be able to essentially MUX for multiple ADC readings. This could be quite useful for my project. Looks like I will be adding yet more features to my "Ultimate Bike Computer".

    -Larry
Sign In or Register to comment.