Shop OBEX P1 Docs P2 Docs Learn Events
ADC using counters — Parallax Forums

ADC using counters

LitefireLitefire Posts: 108
edited 2007-08-08 05:55 in Propeller 1
Hey, i'm trying to perform ADC on the propeller using sigma-delta conversion via the counter modules.·

I know how to set up the circuit, but what would i need to do to program in this funciton?· and would this require a separate cog to run properly?

I assume that it is possible to use this with 5V+ devices?· any modifications that i would need to do to use this?

finally, what changes to the code do i need to perform to be able to use different pins in the program?

Thanks so much!

~~Brian

Post Edited (Litefire) : 4/13/2007 1:26:19 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-13 14:44
    There are some examples that come with the Propeller Tool that are intended for digitizing the microphone input. I believe the "coil demo" and "inductive sensor demo" in the Object Exchange also use the sigma-delta conversion routines which can use any pair of I/O pins.

    What do you mean by "use this with 5V+ devices"? The output is an analog signal from roughly zero to +3V. You can buffer this with an op-amp and, if the op-amp runs off some other power supply (+5V or +5V/-5V or +15V/-15V), you can amplify this to anything you want.

    Normally, you use a cog for each analog to digital channel. The ADC object takes care of launching this. The I/O pins used are set by a pair of named constants in the ADC object which just continually converts the analog input to a digital value in a location that the caller provides. Have a look at any of the examples mentioned.

    Post Edited (Mike Green) : 4/13/2007 2:53:01 PM GMT
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-04-13 16:13
    To have sigma-delta measure a voltage above 3.3 volts, you have to choose the input resistor such that the voltage at the Prop input pin would be less than or equal to 1.65 volts when the Prop output pin is at zero volts. Also, for safety sake, make the resistor large enough to limit the input current through the protection diodes to less than a few milliamps if the Prop happens to be turned off when the external source is on.

    This subject has come up many times here in the forum. Start at the good threads index sticky, and also search on ADC or analog. Here is one: http://forums.parallax.com/showthread.php?p=619937

    For best results the ADC requires its own cog, which could monitor two ADCs based on its two counters. The two pins used are chosen when specifying the count mode register. The count mode register specifies one pin to use for input and the other for output. The assembly language supervisor simply starts the counter going and reads it after a fixed time interval. The analog to digital result is a fraction, the number of counts accumulated by the counter module, divided by the total number of clock cycles in the sampling interval. You could do that in SPIN also without dedicating an assembly COG to it, but the result could not be quite as accurate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-13 16:15
    AN001 in the downloads page also contains some code to operate the sigma-delta conversion. I am currently doing a minor revision of the document, but that code example will stay the same.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • LitefireLitefire Posts: 108
    edited 2007-04-13 16:53
    okay, i realized i do have an extra cog floating around.

    my one question would be how to ask the ADC cog to scan two specified input pins. such that i could say:

    result := adc.scan(1, 5)

    where pin 1 is the fbpin and pin 5 is the adcpin from the example code in AN001.

    i need to be able to scan 4 of these (i have the pins and required components set up, i just need to be able to control them)...

    and mike, when i said if it was kosher with +5V devices i was trying to ask if it could translate a voltage that was at or greater than 5v.

    ~~Brian
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-04-13 17:37
    Brian,

    Suppose the resistor from Apin to Bpin is 100 kohms as shown in AN001. AN001 suggests using a 150kohm resistor for the input, for a full scale range to cover from 0 to 3.3 volts and a little beyond. If you have a higher input voltage, or a +/- larger range in fact, you will use a higher resistance at the input. For example, if the maximum input is 10 volts, choose the minimum resistor value from,
    R > (Vin / 1.65 - 1)* 100k)
    R > (10/1.65 - 1) * 100k = 506k
    



    You would actually choose a slightly higher resistor so that the ADC does not go too near saturation.


    I posted a circuit analysis (which should not be taken as authoritative!) in this thread:
    http://forums.parallax.com/showthread.php?p=633577

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • LitefireLitefire Posts: 108
    edited 2007-04-13 19:26
    Awesome, thanks Tracey.

    any hints on what to do to let me use one ADC object for multiple possible pairs of pins? essentially, i want the desired pins to be specified at call-time, so the assembler code should be updated to allow variables instead of the constants that are currently used as pin declarations. since i have zero assembler knowledge, anyone mind helping me out with that?

    thanks so much!

    ~~Brian
  • LitefireLitefire Posts: 108
    edited 2007-04-13 20:28
    also, in the adc program from the AN001 file it says not to use consecutive pins due to "Crosstalk"... how far apart should the pins be spaced to avoid such crosstalk? i have it right now on pins 21 and 23 (one pin in between), and i'm getting data that seems to hold at 128(when i put it to ground) and fluctuates between ~128 and ~170 when i put it up to 3.3v.

    could this be due to timing errors? the loop is constantly running, with the spin running the data output... perhaps the data is being outputted during a scan and is reading weird values. here's a sample of the data i got at 3.3v (Vdd).

    171
    170
    171
    168
    170
    169
    170
    168
    163
    148
    170
    170
    153
    150
    168
    169
    170
    138
    169

    so it is usually around 170 at Vdd, but it has some weird fluctuations... can anyone explain this?

    ~~Brian
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-13 20:35
    Brian,
    Here's a modified version of ADC.spin. I haven't tested it yet, but give it a try.
    Mike
  • LitefireLitefire Posts: 108
    edited 2007-04-14 07:57
    Hey all.

    Well, i've got MAJOR spread on my values... even when being held on ground it's got a spread of +/- 15 from around 120.

    This seems to be happening on all of my adcs (i've got four of them on the one DIP chip). I've checked all of the connections, and they're all solid, and leads are really short... how accurate can i expect this to be?

    ~~Brian
  • Tracy AllenTracy Allen Posts: 6,660
    edited 2007-04-14 14:50
    Describe the setup of the Propeller/DIP and the other components. It almost requires dead bug wiring with the components soldered directly to the pins with zero leads for best results at 80 mhz. Absolutely no white plugin breadboards.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • LitefireLitefire Posts: 108
    edited 2007-04-15 01:19
    it's mounted directly to the pins on the DIP. the two tiny ceramic capacitors and the resistor have leads less than 2mm long... i've followed the instructions, but it just doesn't seem to work.

    sadly, my robot did not qualify for the competition tomorrow... so i'm taking a little break from it... but i think i'm going to try to improve it to have a jump start on next year.

    this would be a huge help.

    ~~Brian
  • © Jonathan ©© Jonathan © Posts: 1
    edited 2007-08-08 05:55
    thanks for all this good information, my name is Jonathan and I am student of parallax Propeller in Argentina. Single I want to appear and to consult if somebody Spanish speech. greetings
Sign In or Register to comment.