Shop OBEX P1 Docs P2 Docs Learn Events
SIgmaDelta ADC — Parallax Forums

SIgmaDelta ADC

John BoardJohn Board Posts: 371
edited 2013-07-16 03:31 in Propeller 1
G'day,

I've been playing around with SigmaDeltas lately to read the voltages coming in from a sharp IR sensor. As I do not possess an ADC chip, nor have the time to buy one/figure out how it works, I'm sticking with SD's for now.

My problem is I have the code to read one sigma delta, but cores are precious, and this one takes up an entire core, for reading just 1 SigmaDelta. I need to have it reading 2 at the very least. Since I'm not brilliant at PASM and can't modify the library I'm using, I'm wondering if anyone knows of a SigmaDelta library that supports at least reading 4 SDs on 1 cog.

At the moment I'm using the builtin "ADC" library as provided with Propeller Tool.

Thanks for your help!

-John

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-12 19:23
    I'm pretty sure upping the number of DS calculations to two wouldn't be a problem since the other counter could be used. Even upping it to four channels should work but at a reduced sample rate.

    I'm too busy to take this on myself but any one doing so should be aware these lines of code:
                  movs      ctra,#SDI                       'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#SDF
    

    Will only work pins 0 through 9 because of the 9-bit limit of the source field. The pins for higher pin numbers will need to be stored as variable and referenced indirectly.
  • kuronekokuroneko Posts: 3,623
    edited 2013-07-12 19:32
    Duane Degn wrote: »
    I'm too busy to take this on myself but any one doing so should be aware these lines of code:
                  movs      ctra,#SDI                       'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#SDF
    
    Will only work pins 0 through 9 because of the 9-bit limit of the source field. The pins for higher pin numbers will need to be stored as variable and referenced indirectly.
    Counters take pin numbers (6bit) not masks.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-12 19:39
    kuroneko wrote: »
    Counters take pin numbers (6bit) not masks.

    Thank you. I should have thought of that.

    I'll have to rethink about why I had problems with the object using higher pin numbers.

    Edit:

    This is the culprit.
    asm_entry     mov       dira,#1<<SDF                    'make SDF pin an output
    
  • John BoardJohn Board Posts: 371
    edited 2013-07-12 20:53
    It's all french to me :P
  • John BoardJohn Board Posts: 371
    edited 2013-07-14 22:03
    G'day,

    I've been poking around some ASM tutorials, such as Potatohead's, and looking at the CTRA (and other register) tutorials, and it seems to be that I can only do 2 SigmaDeltas / core (using APIN and BPIN of CTRA and CTRB) in assembly. Is the way to boost this number to code your own POS w/ feedback code in assembly, while utilizing both CTRA and CTRB? Or is it by recalibrating CTRA and CTRB on the fly, for different pins, aka, take a reading using the first 2 pins, and then recalibrate the CTRx to use the second pin, take a reading, then repeat...?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-14 22:20
    John Board wrote: »
    Or is it by recalibrating CTRA and CTRB on the fly, for different pins, aka, take a reading using the first 2 pins, and then recalibrate the CTRx to use the second pin, take a reading, then repeat...?

    This is my guess of how it could be done.

    While it seems like a good idea to have a DS object with four channels, I'm betting you're project would be completed sooner if you used an ADC chip.
  • John BoardJohn Board Posts: 371
    edited 2013-07-15 01:46
    G'day,

    I finished it, seems to work fairly well, it basically keeps reconfiguring the registers. It currently reads 2 channels,but ultimatly can be configured to read X number of channels, although each channel added will of course slow down the entire loop. Fast enough for what I need though, so I'm happy. I'll chuck a profiler on it later today, and see how fast it's sampling at with ~4 channels.
    {{
    *****************************************
    * generic ADC driver v1.0               *
    * Author: Beau Schwabe                  *
    * Copyright (c) 2007 Parallax           *
    * See end of file for terms of use.     *
    *****************************************
    }}
    
    
    CON
        SDF1 = 6                     'sigma-delta feedback
        SDI1 = 7                     'sigma-delta input
        SDF2 = 4
        SDI2 = 5
    
    
    PUB SigmaDelta (sample)
        cognew(@asm_entry, sample)   'launch assembly program in a COG
    
    
    DAT
                  org
    
    
    asm_entry     mov r1,par
                  mov r2,par
                  add r2,#4     
    
    
                  
    :loop         mov       dira,#1<<SDF1                    'make SDF pin an output
    
    
                  movs      ctra,#SDI1                       'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#SDF1
                  movi      ctra,#%01001_000
                  mov       frqa,#1
    
    
                  mov       asm_c,cnt                       'prepare for WAITCNT loop
                  add       asm_c,asm_cycles
    
    
                  waitcnt   asm_c,asm_cycles                'wait for next CNT value
                                                            '(timing is determinant after WAITCNT)
    
    
                  mov       asm_new,phsa                    'capture PHSA
    
    
                  mov       asm_sample,asm_new              'compute sample from 'new' - 'old'
                  sub       asm_sample,asm_old
                  mov       asm_old,asm_new
                  
                  wrlong    asm_sample,r1                  'write sample back to Spin variable "sample" 
                                                            '(WRLONG introduces timing indeterminancy here..)
                                                            '(..since it must sync to the HUB)
    
    
                  mov       dira,#1<<SDF2                    'make SDF pin an output
    
    
                  movs      ctra,#SDI2                       'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#SDF2
                  movi      ctra,#%01001_000
                  mov       frqa,#1
    
    
                  mov       asm_c,cnt                       'prepare for WAITCNT loop
                  add       asm_c,asm_cycles
    
    
                  waitcnt   asm_c,asm_cycles                'wait for next CNT value
                                                            '(timing is determinant after WAITCNT)
    
    
                  mov       asm_new,phsa                    'capture PHSA
    
    
                  mov       asm_sample,asm_new              'compute sample from 'new' - 'old'
                  sub       asm_sample,asm_old
                  mov       asm_old,asm_new
                  
                  wrlong    asm_sample,r2                  'write sample back to Spin variable "sample" 
                                                            '(WRLONG introduces timing indeterminancy here..)
                                                            '(..since it must sync to the HUB)
                                                            
                  jmp       #:loop                          'wait for next sample
    
    
                  
    
    
    asm_cycles    long      $FFFF                           '(use $FFFF for 16-bit, $FFF for 12-bit, or $FF for 8-bit)
    
    
    asm_c         res       1                               'uninitialized variables follow emitted data
    asm_cnt       res       1
    asm_new       res       1
    asm_old       res       1
    asm_sample    res       1
    asm_temp      res       1
    r1            res       1
    r2            res       1
    
    
    DAT
    {{
    &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    &#9474;                                                   TERMS OF USE: MIT License                                                  &#9474;
    &#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
    &#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    &#9474;
    &#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    &#9474;
    &#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software&#9474;
    &#9474;is furnished to do so, subject to the following conditions:                                                                   &#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          &#9474;
    &#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         &#9474;
    &#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   &#9474;
    &#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         &#9474;
    &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    }}         
    

    I'll polish it up, and perhaps put it on the OBEX!

    -John
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-15 08:09
    Wow! That was quick.
    John Board wrote: »
    I'll polish it up, and perhaps put it on the OBEX!

    If you do, it would be nice if the Start method accepted the pin numbers as parameters. It would be also nice if the object could use pins above P9.

    If you use the second counter you should be able to read the two channels at once and not reduce the update rate (at least I think this would work).
  • pjvpjv Posts: 1,903
    edited 2013-07-15 08:35
    Hello John;

    I think you could make the loop a little faster by eliminating one instruction in the self-modifying code.......... if you combine the movd and movs for counterA into a single register and then use "mov ctra,dscombo",
    You are already overwriting the left end of the instruction with the movi that you have.

    Cheers,

    Peter (pjv)
  • Christof Eb.Christof Eb. Posts: 1,201
    edited 2013-07-16 03:31
    Hi John,
    the software together with the hardware tries to hold the voltage at the C at 3.3V/2. But just at/after the switch to the new channel the voltage will not be nearby this level. So each switching will bring some inaccuracy to the system. This is a difference to the single channel version. The counting should start only AFTER the first change of level of the output pin, I think.
    Christof
Sign In or Register to comment.