Shop OBEX P1 Docs P2 Docs Learn Events
Looking for help reading in a low voltage input for a proximity detector — Parallax Forums

Looking for help reading in a low voltage input for a proximity detector

Dan EDan E Posts: 61
edited 2011-01-24 06:03 in Propeller 1
With the combination of a Maxbotix ultrasonic rangefinder and a piezo buzzer, I am trying to make a proximity detector as a component for a school project.

It seems in order to make this happen, I need to have the varying PWM input of the rangefinder vary the time delay of an on/off beeping sequence of a piezo buzzer.

The voltage from the rangefinder will most likely be varying from about 200mV to 500mV, so I would have to write an equation to scale those values to a set of increments that made sense.

Is it possible to take the magnitude of the PWM input and have it be the varying factor of a 'waitcnt' ??

Can the Propeller pick up readings that low in voltage as in input?

Any suggestions?

Thanks,
Dan

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2011-01-21 10:15
    Hi Dan,

    regardless of some hundred millivolts or some volts you have to do ADC (Analog Digital Conversion)

    This can be done with the sigma-delta adc-circuit or with any kind of external ADC-chip.
    I would recommend the MCP3208 as it has 12 bit resolution and because there is code in the object-exchange for
    reading in the values into the prop-chip. The delta-sigma-circuit works NOT very good with a DIP40-housing of the propeller
    and even worse if the resistors and capacitors are more than 10mm away from the prop-pin.

    A PWM-signal from a voltage point of view is totally OFF or totally ON 0% / 100%
    from a point of view over TIME, the ON-TIME of the signal varies between 0% and 100% in small steps.

    the prop can do it all
    making a piezo-buzzer buzzing fast or slow or a speaker beeping high or low or even sound like a sirene what ever you want.

    I assume that the projects target is to gain experience in different ways especially in solving problems ON YOUR OWN.
    So next step from you is to find, download read the datasheets of the rangefinder and the piezo buzzer.
    What does the signal look like?
    what are the specs of the piezo buzzer type of the buzzer
    connect voltage makes him buzz at on frequency or another way then voltage current impedance minimal and maximal frequency.

    Make a try about the things mentioned above and if you can't go on come back and ask concrete questions

    best regards

    Stefan
  • LeonLeon Posts: 7,620
    edited 2011-01-21 10:16
    Amplify the signal with an op amp, and use an ADC.
  • Dan EDan E Posts: 61
    edited 2011-01-21 13:46
    Thank for the help, I'll go pick up an ADC. The programming component of my project is an extra, I am an EE student with little knowledge of programming due to the fact only 1 introductory class was required. The electrical component of my project has already been satisfied. Now I am just trying to make this complete with all the bells and whistles I can to make this as appropriate as possible for the end users, before I need to turn it in next week. I will try to make any further questions more concrete and exclusively about the propeller.

    Dan
  • Dan EDan E Posts: 61
    edited 2011-01-21 22:39
    The store I tried today only had 1 ADC model, it was a NTE 2050. After reading itsdatasheet i was still quite confused about its operation. It has 40 pins and is unspefic about which ones to use for its many applications, and could not find any articles about others using it on the web either.

    I decided to try the Sigma-Delta ADC circuit. In the propeller app notes under propeller counters, there is a circuit diagram and sample code for ADC. So I modified some of that the code given, some other code that others have given to help, and pieced together what I think could be a solution for what I am trying to acomplish.

    I made sure that the components in the Sigma-Delta circuit are all within less than an inch away from the input (APIN) pin, and all leads are snipped.

    I ran the code, and received a beeping response as expected, but it did not vary, so I checked the voltage going to the input pin, behind the ADC circuit, and it was a constant 1.46v regardless of the varying signal going into the ADC circuit. The voltage from the rangefinder was from 120mV to 390mV similar to before since I used the same range.

    So at this point I'm not sure how the digital input will be able to vary, since the PWM signal is so fast it is probably always gonna be read as high.

    Also in the same propeller app notes, there was a sample program for a frequency counting application, could that maybe be a more suitable program to accomplish what I am trying to do??

    I attached the various code I compiled together from others, and modified it to test this applcation.

    ADC Input and counter - Archive [Date 2011.01.22 Time 01.33].zip

    Thanks,
    Dan
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-01-22 00:34
    Dan E.,

    A simple Current mirror(See attached) to bias your signal might be all you need instead of an Op-Amp.

    That 40 pin ADC seems a bit overkill, there are 8 pin solutions that would work just fine.

    What you describe of the Sigma delta ADC is accurate. The whole objective of the mechanism or 'state machine' in a Sigma Delta ADC is to keep the I/O pin right at the threshold of where it triggers to be a logic 1 or a logic 0. 1.46v is right where it should be for the Propeller. Ideally it should be exactly 1/2 of Vdd which would make it 1.65v but there was a mis-calculation with the transistor drive strength when the Propeller was designed causing it to be slightly off. The idea still hold true as far as Sigma Delta. Imagine that your input voltage is about 1/2 Vdd, then you would expect the I/O or feedback pin of the Sigma Delta ADC to read a "0" 50% of the time and a "1" 50% of the other time. Now if you sample the feedback I/O 3thousand, 3 hundred times and add a 1 to an accumulator every time that you read a "1" on the feedback pin you would expect a over all count of 1650. You can sample the ADC as many times as you want, but sampling 3300 times is a convenient way to directly obtain your result in milli volts. Now Imagine that that the Sigma Delta ADC is held to ground through a resistor. Now the ratio of "0" to "1" that ends up on the feedback I/O is persuaded more towards "0" as a result the accumulator wont be able to count as high, indicating a lower voltage on the input. The opposite is true if the ADC input pin is held HIGH.

    That said, the Sigma delta ADC is typically AC coupled to the input with a capacitor, meaning that it works best for detecting things like a microphone and helps keep Vdd/2 at the feedback I/O, however you can operate the Sigma Delta ADC in DC mode by removing the front end capacitor on the input. The two capacitors tied to Vdd and GND still remain. That's probably why you didn't see any noticeable change.

    Note: Any time you amplify a signal to observe it's value you are also amplifying noise. Nyquist dictates that you should sample at least twice, but for better signal to noise ratio you should sample at least 4 times. Sampling 4 times increases the signal to noise ratio by a factor of two.
    1024 x 521 - 66K
  • RS_JimRS_Jim Posts: 1,768
    edited 2011-01-22 04:42
    Dan,
    I have a dumb question. If the input of the rangefinder is a pwm signal, does thae width of the pulse vary with the range? If so, why not measure the pulse width not the amplitude of the intigrated pulse?
    RS_Jim
  • Dan EDan E Posts: 61
    edited 2011-01-22 09:08
    Beau, Thanks for the information, I will start building the current mirror. When I built the Sigma-Delta circuit I wasn't sure if the component marked with the asterisk should have been the capacitor or the 150K resistor (AC or DC) so I guessed and went with resistor. Should that have been AC? I'm not aware of how each one affects the input pin.

    Also, the app notes have a selection of suggestions for the amount of sample bits to use and the corresponding sample rate. How can I determine the amount that corresponds to 3300 times?


    RS_JIM, Your right, the pulsewidth should vary with the range, but I don't have the use of an oscilloscope to measure the pulsewidth or software to do so, so I have just been using my multimeter to detect the varying voltage level.

    Thanks,
    Dan
  • RS_JimRS_Jim Posts: 1,768
    edited 2011-01-22 09:39
    Ok, so use the prop to measure the pulse widths, There are a variety of objects in OBEX for measuring pulse width. You don't need a scope. For example as I remember, the Ping outputs varying widths of pulses depending upon the distance. Use a ping object and recalibrate it for your device and forget all of the complications of taking a digital signal, making it analog and reading it with an A/D converter. Your long range accuracy should be greater doing it that way.
    RS_Jim
  • Dan EDan E Posts: 61
    edited 2011-01-22 10:29
    Thanks, the Ping Demo object seems easy enough to modify, I will give that a shot later on. Basically I need a value returned that corresponds to the range, so that I can vary the piezo's beeping respectively. Using this object seems like an accurate path forward.

    Dan
  • RS_JimRS_Jim Posts: 1,768
    edited 2011-01-22 10:57
    That should be relitively easy to do. The ping.spin returns either millimeters or inches. Should be easy to write a spin code that varies the number of output pulses depending upon the distance returned from ping.
    RS_Jim
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-01-22 12:31
    Dan,

    Sounds like reading the PWM is the way to go.

    In answer to your question, if you had a 12-Bit ADC, the full range of 0 to 3.3V would be from 0 to 4095 since 2^12 = 4096. in a sense counting to 4095 with the Sigma Delta ADC. It's just that if you wanted something that was more 'human readable' you would need to scale the 0-4095 so that when the ADC actually returned a 2482, you'd know what it was. If you counted to 3300 instead which correlates to your 3.3V ref or MAX, you would see 2000 instead of the 2482.... 2000 is much easier to translate into 2 Volts without needing to do any overhead calculations.

    BTW, using the example above and assuming that the Ref Voltage is 3.3V, you'd need to do this to convert it into 'human readable' form...

    (2482 x Ref Voltage) / 4095 = 2V
  • Dan EDan E Posts: 61
    edited 2011-01-22 16:57
    Thanks for the feedback and affirmation, it was really helpful. I only had to modify a few lines of the previous code I was using to incorporate the Ping object, and it works great!

    The beeping is right in sync with the distance read from the rangefinder. I need to modity the delay equation to make it decrease the closer an object is, but thats the easy part. Bottom line is it works now as a proximity detecter.

    I attached the code I used.

    Rangefinder - Archive [Date 2011.01.22 Time 19.52].zip

    Dan
  • RS_JimRS_Jim Posts: 1,768
    edited 2011-01-24 06:03
    Glad to have helped!
    RS_Jim
Sign In or Register to comment.