Shop OBEX P1 Docs P2 Docs Learn Events
Sigma Delta-Interleaved with other code — Parallax Forums

Sigma Delta-Interleaved with other code

WurlitzerWurlitzer Posts: 237
edited 2009-04-10 00:40 in Propeller 1
I have a current program with all 8 cogs occupied but one·cog is lightly loaded.

I need to get 2 low resolution (7-8 bits) Analog values at a fairly low update rate of around·10-15 x per second.

I understand the concept of Sigma Delta but not how it is extracted from the counters as the samples I looked at all seemed to be stand alone loops and I do not understand if the read of the counter is critical other than not reading too fast for the required resolution.

Can I interleave this code with other code and just read the counter (A & B)·data at a time when the other processing permits in a single cog?

Thanks,
Craig

Comments

  • cgraceycgracey Posts: 14,255
    edited 2009-02-16 18:24
    Find a cog that isn't using its CTRs and you've got the resource you need. You'll just have to write a little code to configure them and keep them updated.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • WurlitzerWurlitzer Posts: 237
    edited 2009-02-16 18:39
    Thanks Chip! None of the cogs use the counters. I was just unsure of the relationship between the reading of the counter value in the timed loop.

    Craig
  • edited 2009-02-16 20:28
    Chip Gracey said...
    ...You'll just have to write a little code to configure them and keep them updated.
    Here is a Spin example of configuring the Counter Modules and keeping them updated.· Since it's Spin, it needs more clock ticks to make sure the loop in the·adc method repeats.· (2048 in this case, ASM can be much·tighter timing.)··The loop repeats twice just to make sure the timing is synchronized.· If you try just one rep, it'll be a different value, but anything greater than one rep gives you the same value for a given input voltage.··When sigma-delta ADC gets executed in a loop in another cog, we don't usually notice that first measurement.·

    ''Test ADC Interleaved.spin
    ''View results with Parallax Serial Terminal.
     
    CON
       
      _clkmode = xtal1 + pll8x                   ' Set system clock frequencey
      _xinfreq = 5_000_000
     
    OBJ                                          ' Object declarations
      ser : "FullDuplexSerial"
      
    PUB go | val                                 ' Go method with local variables
     
      ser.start(31, 30, 0, 9600)                 ' Start FullDuplexSerial
      waitcnt(clkfreq/10 + cnt)                  ' Time for PC to connect
     
      repeat                                     ' Loop
        ser.str(String(13, "val = "))            ' CR + "val = "
    
        val:= adc(8, 7, 2048)                    [b]' Call adc method
    [/b]    ser.dec(val)                             [b]' Display result[/b]
    
        waitcnt(clkfreq/4 + cnt)                 [b]' Time for doing other tasks
    [/b]                                             [b]' doesn't have to be constant[/b]
     
    PUB adc(pinFb, pinIn, ticks) :adcVal | t     ' Sigma-delta ADC method 
     
      dira[noparse][[/noparse]pinFb]~~                              ' Set feedback pin to output
      ctra := %01001<<26 + pinFb<<9 + pinIn      ' CTRA -> POS detector wi feedback
      frqa := 1                                  ' FRQA adds 1 to PHSA when pos detect
      phsa~                                      ' Clear PHSA for first measurement
                                        
      t := cnt                                   ' Get current cnt register value.           
        
      repeat 2                                   ' Sigma-delta ADC loop, 2 reps to sync
        waitcnt(t+=ticks)                        ' Wait for the measurement to complete
        adcVal := phsa~                          ' Copy phase accumulator to variable        
                                                 ' and then clear phase for next measurement.
    
    




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 2/16/2009 9:33:08 PM GMT
  • WurlitzerWurlitzer Posts: 237
    edited 2009-02-16 21:31
    Thanks Andy! Sure is great doing business with you people.
  • Will EyeamWill Eyeam Posts: 16
    edited 2009-04-03 16:25
    PUB go | val, val1, val2, val_ave            ' Go method with local variables
     
      ser.start(31, 30, 0, 9600)                 ' Start FullDuplexSerial
      waitcnt(clkfreq/10 + cnt)                  ' Time for PC to connect
      
      repeat                                     ' Loop
        ser.str(String(13, "val_ave = "))        ' CR + "val = "
        val:= adc(8, 12, 4000)
        waitcnt(clkfreq/40 + cnt)
        val1:=adc(8, 12, 4000)
        waitcnt(clkfreq/20 + cnt)
        val2:=adc(8, 12, 4000)
        val_ave:=((val+val1+val2)/3)             ' Call adc method
        ser.dec(val_ave)                         ' Display result
        waitcnt(clkfreq/4 + cnt) 
    

    I am trying the interleaved adc to analyze a signal from a function generator(10 kHz, square wave), but the values being displayed are varying a bit. Is there a way to average several values?(I tried to make an average value in the code above), but the the values still vary every 1 out of 4 values(three values of ~750, and then a reading of 670 for example). I am using a photodiode to produce the signal fed into the adc, and prefer precision because I plan on having 2 photodiodes(taos TSL12S: light-to-voltage)·with their outputs filtered to 10kHz and 20kHz, and I need to compare which photodiode has the bigger output. My final project will have 9 sensors, will I need to use 18 pins to utilize this adc?
  • Will EyeamWill Eyeam Posts: 16
    edited 2009-04-10 00:40
    Is there any way to take 4 readings, and save the greatest value of the 4?
Sign In or Register to comment.