Shop OBEX P1 Docs P2 Docs Learn Events
having trouble reading sigma delta circuit — Parallax Forums

having trouble reading sigma delta circuit

Project5kProject5k Posts: 58
edited 2011-07-27 10:30 in Propeller 1
I have my 4 line LCD up and working, and i can write to it, reset it, turn its backlight on and off, but after hooking up a sigma delta circuit to pins 6-7 and using the ADC.spin obj, i'm not getting what i think i should be as a result...

I'm brand new to coding, so please, any help would be great....

i'm getting Here We Go!!! on line 1 of the lcd, and then on line 2 i'm getting 43690.
i have 100k between pins 6 and 7, and then 150k between pin 7 and the output of my LM34. Feeding the LM34 from the 5V on my proto USB board...

what i would really like is to just display(and be able to do some basic math functions) with the value i "expect" to get, which is just the mV of the output of the LM34... if i could get the thing to show me 78 and then be able to work with that # i think i can do all i need to do... the other thing that i know i need to do is that i'm gonna wanna read more than one of these, can i just name a couple of the ADC objects, like ADC1, ADC2 and so forth, and change the pin assignments in each, and then call each when i need them? Otherwise how do i go about calling for different measurements from the same ADC obj with the pins set inside?

[edit] after sitting here and reading more, and just letting the thing run for a bit, i started noticing the lcd display change, from 43689 to 43690... I'm sure its just "splitting a step" in the ADC, but at least now i know that its not just harvesting that # from some fixed point... and the change is not predictable, and increasing the temp on the LM34 seems to have NO EFFECT on the # displayed, even tho i can measure a V change with my DMM{/edit]
{
Project5k 
READING LM34 ON PINS 6-7 SIGMA DELTA

}
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  TX_PIN        = 0
  BAUD          = 19_200

OBJ
  LCD : "FullDuplexSerial"
  adc : "ADC"
  
Var
LONG adcsample
  
PUB main
LCD.start(TX_PIN, TX_PIN, %1000, 19_200)
  waitcnt(clkfreq / 100 + cnt)
  



repeat
  lcdgo
  adc.SigmaDelta(@adcsample)
  
 
  
  

pub lcdgo

  
  waitcnt(clkfreq / 2 + cnt)
  LCD.str(string(12))
  waitcnt(clkfreq / 100 + cnt)
  LCD.str(string(17))

  waitcnt(clkfreq / 2 + cnt)
  LCD.str(string(22))
  LCD.str(string("Here We GO!!!",148))
  LCD.dec(adcsample)
{{
*****************************************
* generic ADC driver v1.0               *
* Author: Beau Schwabe                  *
* Copyright (c) 2007 Parallax           *
* See end of file for terms of use.     *
*****************************************
}}
CON
    SDF = 6                     'sigma-delta feedback
    SDI = 7                     'sigma-delta input

PUB SigmaDelta (sample)
    cognew(@asm_entry, sample)   'launch assembly program in a COG

DAT
              org

asm_entry     mov       dira,#1<<SDF                    'make SDF pin an output

              movs      ctra,#SDI                       'POS W/FEEDBACK mode for CTRA
              movd      ctra,#SDF
              movi      ctra,#%01001_000
              mov       frqa,#1

              mov       asm_c,cnt                       'prepare for WAITCNT loop
              add       asm_c,asm_cycles

              
:loop         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,par                  '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

DAT
{{

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-25 17:02
    attachment.php?attachmentid=78421&d=1297987572

    Please edit your post.

    Thanks,
    -Phil
  • Project5kProject5k Posts: 58
    edited 2011-07-25 18:46
    thanks for the tip!
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-07-25 18:47
    Project5k,

    Take the line that starts the ADC out of the repeat loop, and put it in your initialization of your PUB main.
    adc.SigmaDelta(@adcsample)

    Once the ADC is started, it simply sits there and autonomously updates your variable, adcsample. So you just have to print it to the LCD, not ask the ADC for it. The number that comes back will be between 0 and 65535 at the ends of the scale. Once you see the number moving in response to the voltage changes, you will have to do some calibration to get it as a temperature value.

    You didn't mention having capacitors at the input pin. It's there, right? The performance of the sigma-delta is sensitive to circuit layout.
  • Project5kProject5k Posts: 58
    edited 2011-07-26 05:32
    i see your point about not repeating things i dont need to... i cleaned up the rest of my code and this is what i ended up with...
    please review:
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      TX_PIN        = 0
      BAUD          = 19_200
    
    OBJ
      LCD : "FullDuplexSerial"
      adc : "ADC"
      
    Var
    LONG adcsample
      
    PUB main
    adc.SigmaDelta(@adcsample)
    
    LCD.start(TX_PIN, TX_PIN, %1000, 19_200)
      waitcnt(clkfreq / 2 + cnt)
      
    lcdgetready  
    
    repeat
      lcdupdate
      waitcnt (clkfreq / 4 + cnt)
        
    pub lcdupdate
             
      LCD.dec(adcsample)
      LCD.str(string(148))
    
    pub lcdgetready
      LCD.str(string(17))
        waitcnt(clkfreq / 2 + cnt)
      LCD.str(string(22))
        waitcnt(clkfreq / 2 + cnt)
      LCD.str(string(12))
      waitcnt(clkfreq / 2 + cnt)  
      LCD.str(string(128))
      LCD.str(string("Here We GO!!!",148))
    


    now when run, the display still has the here we go, but it toggeles between 32767 and 32768... waitcnt added to slow display down to about 2-3 updates a second, give or take... at least you can see it now... without the wait, it moved so fast it was just a blur...

    no change from increasing the temp(mV input) by .2V

    caps, no i didnt have them, but i do now. one is from vdd, 3.3v to pin 7 and the other goes from p7 to vdd (ground), wasnt sure about values, so i started with a couple .001uF mylars...

    no change in the output of the circuit...

    just a thought... its been said that this is a sensitive circuit... is working on a 3m solderless breadboard an issue?
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-07-26 10:31
    Solderless breadboards do have issues with sigma-delta, due to the long wires and the extra uncontrolled impedance. If you read back through old threads here on sigma-delta, you will see what people have tried. The most success comes from having surface mount Rs and Cs soldered close up to the propeller pins. Do you get movement in your LCD display when you connect the input (where the LM34 signal goes in) directly to Vdd and Vss?

    The number 32768 is interesting, because that is exactly half scale. That is the number you expect if the input is disconnected.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-07-26 13:34
    If you look into the sourcecode of ADC.spin there is a small schematic mentioning the capacity of 1nF = 1 nanoFarad = 0,001µF. 1nF is pretty small and effects like wires more than 1/2 inch long or breadboards with it's own capacity and impedance
    has an noticable effect on the sigma-delta-measuring because it switches the IO-pin at really high frequencies. There is even an effect of crosstalking if you use two IO-pins laying next to each other.

    If you don't mind adding another chip I recommend the MCP3208. Needs three IO-Pins to connect to the propeller and provides 8 ADC-channels at 12 bit resolution.
    Drivercode is ready to use in the OBEX and lots of forum members are using them.

    keep the questions coming
    best regards

    Stefan
  • Project5kProject5k Posts: 58
    edited 2011-07-26 15:12
    Mcp 3204 and 3208 are both chips I've looked at. I was trying to do this with as few parts as possible, and with what I have on hand.

    I've called all the local electronics parts shops I can find and none of them have either. Guess I'll have to get together an order for Digikey.

    I will loose the breadboard and solder it up shortly. Also haven't tried putting full 3v or gnd to the input. That'll get done as well. Results to come...

    am i missing something? i think i have the caps your saying i should have.. right?
    i'll go check the docs...
  • Project5kProject5k Posts: 58
    edited 2011-07-26 16:31
    B I N G O !!

    we have readings that make sence....

    soldered it all up on a little radioshack copperclad i had, and bingo, shes responding to temperature changes!

    alrighty, now... how do i "calibrate" it?(get a mV #) lets see, lemme think... full scale voltage, devided by the total number of divisions, then times the reading i'm getting, right?

    [edit] wait, dont i remember reading somewhere that i can change the # in the adc part, so that its got the right # of divisions? i think i remember changing something like the #fff, to $0CE4... ideas?

    seems to me if i use 330 total divisions, then each one would be worth 10mV, right? then the # i would get is the mV reading, and thus is my temp?

    well i tried using 14a and it didnt work... hmmm

    Thanks so much everybody... it'd probably taken me weeks to figure out that one!!!
  • Project5kProject5k Posts: 58
    edited 2011-07-27 07:26
    still trying to locate the 3208's that i think are ultamately going to be needed, running into a bi and ci varriant.. and not finding the differences in the data sheets... any one know what the dif is? which is better?
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-07-27 09:23
    -bi is marginally better quality (more $) than -ci. It has to do with the nonlinearity of the transfer function of input voltage to output bits. The -bi variant has 1 bit of INL (integral non linearity), while -ci is 2 bits. You probably won't notice! The letter i stands for industrial temperature range (-40 to +85 °C).

    Changing the sigma-delta factor from $FFFF to $0CE4 does not change the full-scale range. It only affects the resolution (making it courser) and the speed (making it faster). The scale factor is set by your choice of resistors, 100k and 150k. There are several analog variables involved, including the exact resistance values and the exact switching threshold of your Propeller chip. To calibrate, it may be best to record the binary counts returned as you stick the temperature sensor (insulated) into an ice bath and into a high temperature reference. Then compute from that.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-07-27 09:48
    simply check it with a second thermometer.

    take the ADC-value of 3.3V and the one for 0.0V and maybe a third inbetween.
    Then you can calculate the factors. By the way what kind of temperature sensor do you use?
    keep the questions coming
    best regards

    Stefan
  • Project5kProject5k Posts: 58
    edited 2011-07-27 10:30
    I'm using the lm34's i got from Parallax when i ordered my prop proto usb... come to find out the website had the temp specs listed incorrectly for that part... i was shipped the "D" version and the specs listed were for the "A" version, 32f -210f vs -50f - 300f... so called em up, spoke with them, and they fixed the website, and are taking very good care of me to fix the issue...

    BEST CUSTOMER SERVICE EVER! its not that we had a problem, that happens, but its how you recover from the problem... gotta say, Parallax takes care of thier customers! I even ordered up another prop proto usb... solar tracking and pv charge controller... hehehe but thats down the road...

    so i have my mcp3208's on the way.... after looking at the specs, yea a couple bits arent gonna matter for my application... ... if i can get mV resolution, thats good enough... that'd be tenths of a degree...

    kinda feel bad going through all this to get the sigma delta going and then i'm just gonna change gears to the 3208's... but hey, i learned some stuff, had fun doing it, and now i know for when i get my next board here... if nothing else, i learned about re-organizing my code and making it more efficient!!!

    thanks again ya'll!
Sign In or Register to comment.