Shop OBEX P1 Docs P2 Docs Learn Events
Advice needed on multiple analog inputs to PC — Parallax Forums

Advice needed on multiple analog inputs to PC

Joshua SiegelJoshua Siegel Posts: 51
edited 2006-08-09 02:46 in General Discussion
Hi everybody,
I just bought a large quantity of analog sensors for a robotics project. They output from 0-2.54V in 10mV incriments. I also have some 5V sensors that I'd like to use on the same board.
The total number of inputs is 21 (though I can make it work with 20). The resolution needed isn't that great, maybe 8-bit? Even that could be overkill. The max expected refresh rate is 50-60Hz.
I'd love a USB interface, but serial works too.

What can I buy for a reasonable price that can handle 20-24 analog inputs at 60Hz and interface easily with a PC? I've considered stamps, but they all have 8 analog lines max, and some don't seem to enjoy reading voltages.
I'm currently using Phidgets interface kits, but would like to minimize my hardware (I'd need three $90 boards due to the 8 input limit).
Thanks for the input (what a bad pun - but it was necesary!)
Josh

Comments

  • pjvpjv Posts: 1,903
    edited 2006-07-08 04:05
    Hi Josh;

    If you are a "mimimalist" kind of guy, you can do all this with a single SX48 chip plus two resistors and one small capacitor per channel. The (Virtual) A/D converters function mostly in software, and that chip will easily handle the speed and the resolution you specified.

    Communication with a PC is also readily handled by the same chip, again, mostly in software as a Virtual UART.

    The chip has 36 I/O pins, and 2 are needed for the comms, leaving the rest (34) for analog channels. Perhaps a couple of LEDs, so 32 analogs is good.

    Total cost for the "channels" 32 times 5 cents..... about a buck and a half!! The SX48, power supply, RS232 etc is on top of that of course.

    Sounds like a good candidate for one of the Parallax project boards...... around 10 bucks if I recall?

    I'll help you if you're interested...... should be a hoot!

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-09 02:35
    That sounds like it might work, but if I were able to get PWM out from the sensor (Maxbotix sonar) or serial (probably PWM), would that make it easier? Could I use a traditional BOE and a basic stamp?
    I'd have 12 pwm lines and 8 analog in (from my IR). I'd still like to be able to read simultaneously instead of sequentially, or at the very least, update around 50-75Hz. I would be firing all the sensors simultaneously from a digital out to their trigger pins in order to avoid interference.
    This way, I could also impliment a compass module and have that fed over serial to avoid needing a specific board for that.
    Thoughts?
    Thanks!

    edit: I'd still need one more input for my potentiometer... Would one of the 40 pin stamps work? What type of board/etc would I need to buy (assume I have nothing).
    Serial cable, chip, board...
  • kjennejohnkjennejohn Posts: 171
    edited 2006-07-09 06:30
    Well, there's this page at Maxim that has different I2C (2 pins, no waiting) multi-channel ADCs (less then $2!) and app notes:

    www.maxim-ic.com/products/i2c/

    And this Phillips (the people who invented I2C) I2C brochure. First items covered are ADCs:

    www.semiconductors.philips.com/acrobat_download/various/philips_i2c_handbook.pdf

    You should find their PCF8591 of particular interest. It is available at DigiKey, P/N 568-1087-5-ND, $3.49 each/singles. 8-bits, 4-multiplexing channels in single-ended mode, two in differential. This also includes an 8-bit DAC! Very ooh-ooh-ahh-ahh! The data sheet is at:

    www.semiconductors.philips.com/acrobat_download/datasheets/PCF8591_6.pdf

    All you have to do now is implement this simple serial protocol in the SX. Doesn't SX/B have I2C yet?

    Hope this helps!
    kenjj
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-07-09 15:23
    The new product, The Propeller will do quite a bit of your juggling for you. It can create its own ADCs too. It is a 3.3v device, but your analog devices are 2.54volts -- not a bad fit.

    Since it has 8 processors in parallel, it might be a better sensor management concept. There are 32 I/O pins, so it would only achieve 30ADC lines without ADC chips when leaving two pins for communications to the outside.

    Pjv,· how does one get one channel per pin on the SX-48 and/or the Propeller.· My impression was that the 2 pins were dedicated to one ADC.· Your count seems to imply another scheme is available.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

    Post Edited (Kramer) : 7/9/2006 3:32:46 PM GMT
  • pjvpjv Posts: 1,903
    edited 2006-07-09 19:07
    Hi All;

    Josh, I give up!

    You pose a question/problem, and are given a totally applicable solution, then you change your needs so that the solution requires a slightly different answer. Now I don't know what you really ARE looking for! The Maxbotix sonar provides all three, analog, PWM and serial output, and your I/R, I don't know. So if you want to use something different, drop some of the 32 analogs I suggested.

    All analog readings would very nearly be at the same time.

    I just can't understand why anyone would opt for a more expensive and more complicated solution by using external A/Ds.

    The virtual A/D software really IS simpler than any communication to external devices, and the price per channel is 5 cents.

    To boot, you can choose the resolution you want, anywhere from 2 to 12 bits (all the same 5 cents); in some cases I have even managed 14 bits, but now the layout becomes important (as it would with any 14 and up bit A/D).

    And using one I/O pin pin over 2 pins per channel only degrades the performance slightly. For 8 to 10 bits?, No Problem.

    As I don't have a BOE, nor own any STAMP, I have no idea as to their capability. All you would need is a Parallax SX48 proto board for $10, and an SX-Key. You could write your application in SX/B, and because the A/D software is very time critical, I'd be happy to write the assembly virtual A/D program to mesh with that.

    Kramer: The typical way for virtual A/D with an SX is 2 port pins. For lower speed applications (say up to 100 samples/sec) you can get away with 1 port pin per A/D with a slight degradation in performance; I have not measured it, but I expect 0.1% to 0.5%.

    Cheers,

    Peter (pjv)
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-07-09 19:25
    pjv,
    If you would be so kind as to refer me to a schematic for the 'one pin' ADC, it would be quite helpful.

    I just abandoned a project because I thought I didn't have enough I/O pins for the ADC. The resolution is quite minimal and I DO UNDERSTAND that both the amount of programing and the cost are very small.

    I looked into an 8X ADC and it is just plain hell to program via synchonous serial. It takes a huge space in your EEPROM, requires more RAM buffers, and will occupy your mind for a week or so.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • pjvpjv Posts: 1,903
    edited 2006-07-09 20:28
    Hi Kramer;

    Be happy to.

    Since I don't have a drawing/schematic package at home, I'll try to use the new Propeller character set to create it. I believe that means you need to install that too in order to display it.

    I'll experiment with that, so please be patient through my trials.

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-09 23:33
    Thanks so much Peter and Kramer!
    Peter - I really didn't mean to step on toes or disregard your earlier suggestion, so I apologize if I came off as blowing you off. I just realized that I was offered other forms of output from the sensor, and that it might make it simpler to interface in the long run, especially since I've used stamps before, but never the Parallax SX series. I really do sincerely appreciate all the help I can get, and the last thing I want to do is make people question why they should be offering me advice.

    If your offer still stands, I'd be willing to place the order early tomorrow. I'd just need to know what hardware to get, as far as resistors and capacitors. I'd also like it if you would make sure I order the right stuff from Parallax for an SX-newbie to get set up properly.

    If I understand correctly, I'd be ordering:
    SX tech kit (comes with SX-key, serial cable, tech board) and a protoboard (or two) which would be about $100.
    or, I could be a bit cheaper and order
    SX-Blitz + cable + protoboard = $60. Is the kit worth the price difference? I'm on a tight budget to stay within the confines of my grant, but I dont want to buy something only to replace it a month later when I fall in love with this chip (Parallax has a way with me [noparse]:)[/noparse]). I'm sure I could use the tech board for other projects, and I think I've just answered my own question...

    Either would need a power supply - can I use a 7.2V battery for it?

    Thanks again,
    Josh

    edit:
    I guess the final verdict is that I'd be using
    12 2.54V sensors in 10mV incriments
    8 5V infrared sensors in about the same - previously, I had been using 12 bits of resolution, but anything over 8 should be reasonable.
    1 5V potentiometer

    now I just need to find out how to use a compass over serial, i guess - though this can come at a later date

    Post Edited (Joshua Siegel) : 7/9/2006 11:36:39 PM GMT
  • pjvpjv Posts: 1,903
    edited 2006-07-10 00:32
    Hi Josh;

    First and foremost, I was not offended, just a little frustrated.

    Secondly, the ONLY programmer to buy is the SX-Key. The Blitz is fine for programming ONLY; it won't let you debug and single step through your program. I'm 100% sure this is something you will want (and need) to do.

    Which kit you purchase is up to you, as long as it contains an SX-Key. My reccommendation for convenience would be the SX Tech board (SX28) for easy prototyping, and the SX Proto board (SX48) for your final project.

    The SX48 proto board will be a perfect starting point, and only 10 bucks.

    Resistors and capacitors I'll advise you on later..... some are not critical.

    Buy a 9 or so volt "wall wart", center pin positive, if that is not included in the kit.

    Could you please specify the output impedance of the other (non Maxbotix) analogs. Or if you don't know tell us what they are, and we can find it or make an educated guess.

    We'll have a blast!

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-10 01:16
    I just placed an order, I'm excited to get this underway! [noparse]:D[/noparse]
    The other sensors are the Sharp analog sensors. I have the datasheet here somewhere, so I'll see if I can find out what the output impedance is.
    Actually, here it is:
    http://www.junun.org/MarkIII/datasheets/GP2Y0A02YK.pdf

    I don't see it in there. Does it go by another name?
  • pjvpjv Posts: 1,903
    edited 2006-07-10 04:29
    Hi Josh;

    Yup, a pretty incomplete set of specifications..... but we'll take a stab.

    What do you have in the way of test equipment: oscilloscope, digital volt meter, selection of electronic components, resistors, capacitors, transistors, that kind of thing?

    I want you to learn through this process, so I'll be pointing you in the right direction, and let you discover the wonderful world of SX with only as much guidance as you need. So, I'll be asking you to make some measurements on the IR unit.

    Also, just so we don't embarrass each other, how experienced are you in electronics and microprocessor programming?

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-10 22:24
    Hi Peter,
    I always appreciate learning rather than simply being given a solution [noparse]:)[/noparse].
    I have a multimeter, some components laying about (though most are in projects now), and I just bought a 2 channel Tektronix oscilliscope from a local junk haven (the price was right and I couldn't resist). It needs probes, but I can order some later this week from MPJA or some other surplus house.
    As for experience, I understand circuits and logic well. I've done plenty of "basic" projects from 555 timer circuits operating relays to H-bridges to various other function generators, etc. I can read schematics and diagram circuits (but not PCB's), and I've even touched on SMD (but can't say I did well with it). My experience level is probably on a par with what most high school students would have after a course or two in electronics, though I've honestly never taken a real "course" myself.
    My microprocessor experience is null - I've worked with high level chips in basic, java, and C, but never down to assembly code. I'm always willing to learn, though.
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-19 03:51
    I got my parts today, and should have a probe for the scope tomorrow. My multimeter is ready to go, and I'd love to get started!
    What's the first thing I should do? I've been reading through a bit of "Programming the SX Microcontroller," but some code ideas or schematics would help.
    I guess what I'd like the final 'product' to do is output (serially) a string of the values from each input, perhaps
    XXXAXXBXXXXC
    with A as sensor 1, B as sensor 2, and so on - unless you can suggest a better output method. This seems by far the easiest to parse in Java on the computer, making the sensors usable by many different languages.
    It would also be nice to use the SX to trigger the sonar pulses, and it seems like this is a possibility. I'd just use one of the pins as an output, right? Set it high once per loop and trigger the readings?
  • pjvpjv Posts: 1,903
    edited 2006-07-19 15:09
    Hi Joshua;

    Good, I'm ready to guide you in your quest for knowledge..... I'll point you in what I think is the right direction, and help only as little as you need, so that you can discover as much as possible on your own. That way you will retain the information much better.

    As a stater, please read the App notes on the Parallax website pertaining to (virtual) A to Ds.

    Then the next thing we will do is build a software D/A converter; this is the basis of making an A/D converter.

    So you will need 2 resistors of the same value (ony one for the D/A, but the second resistor when we implement the A/D) of 10,000 Ohms, and a small capacitor of 0.01 uF. The restor values are not critical per-se, but do need to be of equal value, in fact as identical as possible, including temperature coefficients. So any two "out of the same batch" will be just fine. Thecapacitor value is also not critical.... it depends somewhat on the speed of the signal you are expecting to measure.

    Please devour the App notes.

    More later.

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-20 21:02
    I was only able to find the Sigma-Delta A/D converter source code on the Parallax website. I read it over, but being new to the S/X, "its all Greek to me."
    I did, however, find this link on SX-list:
    http://www.bytecraft.com/addaconv.html
    Would this be the schematic for the circuit you're describing? One capacitor and two resistors per sensor. I've read it over several times and it makes a bit of sense, but as of now, I have no way to impliment it. Step by step would probably be best, I suppose, if you can point me to some more basic reading on the subject.
    Thanks,
    Josh
  • pjvpjv Posts: 1,903
    edited 2006-07-20 23:22
    Josh;

    Time is very tight for me just now (wife's birthday), so I won't be able to do much until the weekend.

    I have not looked at the SXList site, but it sounds like the right animal.

    We'll start by making a "pulse density modulated" (just a special form of PWM) D/A converter as that is what is needed to make, and understand the A/D converter.

    Please confirm that you bought an SXTech board and an SX-Key.

    You will need to have the resistors/capacitor available to proceed with testing. Your oscilloscope will be VERY beneficial. Do you have the probes yet?

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-21 00:56
    Of course, family always comes first! Please take your time; I can busy myself with other code and finding little projects to sidetrack me.

    I'll see if I can find and PDM/PWM sites and read what I can to get a feel for that.

    I have the SXTech board, an SX-Key, the cable, power adapter, and the SX48 proto board for the final product. I've been thumbing through the books to see what I can figure out.

    I'll grab some resistors and capacitors from R/S tomorrow, and maybe place an order from allelectronics to beef up my collection - what I though I had has been reduced to several LEDs and a few misc. components, but nothing that useful.

    As for the scope, I have a probe but no trace yet. I've been troubleshooting for the past hour or so, and think it may be time to buy a manual [noparse];)[/noparse] - unless, of course, I bought a broken scope, which is a real possibility for the price I paid. I've gone through the millitary manual and the setup procedure from the normal operators manual with no trace. It triggers fine and the CRT lights, but even the 'beam find' button wont work. Two other people have suggested a shorted capacitor, but I have no clue what I should look for, and don't feel all that comfortable with HV circuits.

    edit: found a copy of the service manual - its a Tektronix 7603

    Josh

    Post Edited (Joshua Siegel) : 7/21/2006 3:27:14 AM GMT
  • pjvpjv Posts: 1,903
    edited 2006-07-25 02:02
    Hi Joshua;

    I'm sorry to be so tardy, but things just keep piling up on me; I have only a little time to dedicate to the forum just now.

    I happen to see Bean's current post in the SX thread under the topic "SX/B v1.51 Questions", and his reference to the SX LIST, http://www.sxlist.com/techref/scenix/lib/io/adc_vp.htm, is exactly what you are looking for, and a better explanation than I would have time for to boot! The artice is written by Chip Gracey, no less, circa 1997.

    I'm not going to abandon you, but this reference is probably all you need, at least for now. I know that you want to get the data into a PC; that should be a simple matter through a serial port.

    Eventhough I'm really tied up, I still can sneak a quick peek at the forums every day, so I'll notice if you're hollerin'

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-07-30 16:03
    I've read that over and printed out a few Wikipedia entries on PDM/PWM/DAC/ADC/ and so on (I know, Wikipedia, but it works...).
    I haven't had much luck with converting their code, for the two line with interrupt, to a one IO pin setup. I'm learning a lot about SX/B and a little about assembly, though. My one question for this part would be, do I really need an output pin?
    Right now, I guess my primary goal is to get some output that I can read in hyperterminal. Would a SEROUT be a suitable way to do something like that? I could perhaps concatinate a string, and send it out like that... Maybe something like this: http://forums.parallax.com/forums/default.aspx?f=7&m=109987&g=110003#m110003

    Off to read about more of the commands!

    edit: I've been trying Jon Williams Serout string examples, because this will be the best way for me to figure out if my ADC's are working... No luck yet, I'm assuming that's because its TTL levels and I need RS232, right?
    Thanks!

    Post Edited (Joshua Siegel) : 7/30/2006 11:21:45 PM GMT
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-08-03 03:30
    Perhaps this would best be moved to the SX forums...
    Anyway,
    I've spent the past several days continuing to read about this stuff and still haven't had much luck. It's getting quite frustrating and to the point where I just want to see SOME progress to know that my time has not been wasted.
    Serial output was a mess, running Jon Williams code I got nothing but jargon. Tried different bit rates, inverted, not, blah blah blah (of course, starting with what has been tried and known to work, then I monkeyed with it in a futile effort to exact some response). My main feeling is that this is a TTL/RS232 issue, but haven't been able to verify. I've tried on two different computers and get different characters, so thats what leads me to believe that. I'm on the tech board right now, with a 50mHz resonator in place - the one that came with it. It is set to OHCS2, I believe, so that shouldn't be the problem. I've also tried the 4mHz.
    After getting tired of playing with that, I wanted to see if there was any simple way I could see if the board was even reading, because I thought I might be able to start my input code. I was going to try the ADC schematic, but still do not know how to get the dual line (input/output) code to function with a single line (seemingly input only, or is that a fast switch?).
    I tried the PWM out, rather than serial out, and tried to light up a LED to vary intensity with difference (pretty much a pulsin = pulsout deal). No luck there. Then I tried to get it to flash the number of inches away my hand was. Still no luck. I dont know if it isn't reading or what, but can't really tell until I can do a serial out. It could be anything from improper conversion to simply not having a solid enough power supply; I'm running my sensor(s) off of the Vdd/Vss on the board, and though they're within spec, I feel like maybe its too much draw.
    Thoughts, anyone?
    PJV?
    I just need some direction at this point... I'm kind of burnt out from trying to teach myself SX/B and the related assembly, and would like to have something to show for my days of effort.
    Thanks!
    Josh

    edit: Ordered the parts to make a TTL/RS232 level shifter (bidirectional). I never knew that it was a 0-5V scale on TTL, I thought it was +/-5 like rs232's +/-12. I guess that explains why, even with intentional "slop" in design, it had no semblance of proper output... But that still doesn't explain why it works for some people without a shifter?

    Post Edited (Joshua Siegel) : 8/3/2006 2:39:57 PM GMT
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-08-03 15:40
    Joshua,
    I really understand what you are going through. In the beginning there is a huge blur between what is hardware and software.

    You are on the right track to get the HARDWARE verified first. Try the simplest of things to do. Then move to the software.

    Regarding RS-232......
    One of the biggest RS-232 problems is laptops. They often are so non-standard that they won't work well with other devices.
    The MAX232 chip is the usual quick fix and it converts TTL into a good +9/-9 RS-232 and does the inversion from a +5v supply.

    Of course, you can use transistors to make a similar level shifter. 2n3904 and 2n3906 transistors will do fine. They will invert, but the signals [noparse][[/noparse]without a +12 and -12 supply] will be +5 and 0 inverted from the TTL.

    This may quite often be what the laptops are doing. And yet, True RS-232 provides that negative voltage which is being omitted.

    'Trying on different computers and getting different characters'
    A. It could be that Hyperterminal [noparse][[/noparse]or whatever] is set to different values - baud rate, 7 or 8 bit, stop bits, parity
    B. It could be that software is in one instance set to invert the input and in the other to not do so.
    C. These days it is possible to have ANSI characters versus UNICODE. Generally, the 0-9 and A-Z will be the same in both. But other characters may be presented visually quite different. There is a FREEWARE called Terminal that will give you consitent display in Hexidecimal and much greater clarity about configuration via trial and error. Try this link http//:bray.velenje.cx/avr/terminal/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-08-03 15:55
    Thanks, Kramer!
    I should have my RS232 converter soon, and that should help out. Its a MAX232 adapter from acroname, which I've previously used with their BrainStem (though the device didn't belong to me and I dont have access to it anymore).
    I'm using desktops for both terminal windows, because my laptop has a serial adapter and I didn't want to throw in another can of worms to the mix. The settings on both machines were the same, 9600 baud, inverted, 8 bits, no parity, no flow control. I imagine that the differing characters were, as you suggested, either the result of a different character set or the computing mayhem that occurs when a TTL device is connected directly to a rs232 port. I'll try again later today, but I think I might take a break from the serial output portion until I get my adapter.

    I'll try out that software later today, and then probably just wait patiently for my package to arrive from Colorado until I try any more. In the meantime, I can busy myself with looking at compasses (I've been looking at the Dinsmore 1525 lately).

    Thanks again!
    Josh
  • pjvpjv Posts: 1,903
    edited 2006-08-03 16:04
    Hi Joshua;

    Sorry, I've been terribly busy getting a project finished of.... about 4 months solid now.

    I will suggest we start with making a D/A converter with one of those pulse density modulated R/C integrators.

    Hopefully your scope is running as it will be a great help in seeing what is going on.

    Please make sure you have a small capacitor (o.1 uF) and a resistor, any value 1K to 10K is fine. Later you will also want two 10K and two 100K resistors and possibly a 0.01uF capacitor.

    Please read up on interrupts as that is critical in the D/A, A/D and communication code.

    Preferably I would rather not just hand you the code; I think you will learn more if I just guide you in developing it yourself. That will be a slower process.

    I guess to get rid of some of those frustrations some small success celebrations will help...... you decide. We'll have you up and running quickly, I'm sure.

    Cheers,

    Peter (pjv)
  • BeanBean Posts: 8,129
    edited 2006-08-03 16:20
    Joshua,

    I don't know if you saw it, but SX/B 1.51 has a new command that does EXACTLY what you want. It's called ANALOGIN and it uses the PDM (continuous calibration, bitstream, whatever) method to read an analog voltage.

    Because it doesn't use interrupts the circuit must be "primed". This is done by running through the loop 256 times before actually starting to measure/count stuff. You can make the priming stage longer too (in case you have a bigger cap or larger resistor values).

    Here is a link to SX/B 1.51 in case you don't have it·http://forums.parallax.com/showthread.php?p=597707

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-08-03 17:09
    Thanks guys,
    the scope is still a no-go, but I'm going to try and troubleshoot the power supply this weekend. I keep reading about dead capacitors causing this problem, but its never a specific number, so it's hard to pinpoint.
    PJV, I understand completely the desire to teach rather than hand me the code, and I appreciate your motive and know I personally want to LEARN rather than have something handed to me. I have all of the components handy, from batches of resistors (picked up about 1,000 bulk) to capacitors, and will start wiring as soon as I can.
    That said, the ANALOGIN feature seems to be exactly what I need. I'm going to fool around with that, but still want to learn how and why it works. I feel like I have a good, basic understanding of the concept but the little details are what throw me off. Perhaps seeing it in action will be a little impetus for me to make that final mental click?
    I'll try my hand at running one or two of these sonars and getting a reading back. My only concern at this point is that, without being able to see the value returned from the sensor, I wont have a usable way to tell if my output is, well, usable. I can't very well convert an unknown value to a certain number of LED flashes without getting a ballpark to start.

    I'll take a look at SX/B 1.51 and read up on the commands. I've already digested all I can of PDM, PWM, Delta-Sigma modulation, and virtual ADC's. There's a printout as big as a Caddilac sitting on my desk right now [noparse]:)[/noparse].

    Josh
  • pjvpjv Posts: 1,903
    edited 2006-08-03 18:29
    Hi Bean;

    I must have a look at what code that instruction generates...... but immediately I have a concern:

    It is not possible to do software A/D conversion without executing the DAC at exactly the same time in a loop, hence the requirement for interrupt. Any code that causes the DAC to waver in its timing will throw the reading off. The amount of error will depend on the amount of timing inconsistency.

    Again, I have not looked at the code, so if you are some how tricking things for timing to be consistent then it will probably work. Also it would work if you stall everyting else while you are taking a single reading, and that seems pretty impractical to me, especially if you need to communicate serially at the same time.

    Where I am going with Josh is simultaneous communications and A/D conversions. The conversions are done "out of sight" in a precisely timed interrupt routine, as are the communications.

    I'll try to look at your compiled code tonight.

    Comments??

    Cheers,

    Peter (pjv)
  • BeanBean Posts: 8,129
    edited 2006-08-03 18:42
    Here is some code from a simple example. I beleive I got the timing equal for low & high outputs. I could be wrong (I thought I was wrong once...But I was mistaken). I added the comments.

                    
        70  000B  0CFA        MOV FSR,#__TRISA               ;  ANALOGIN InPin, OutPin, value
            000C  0024
        71  000D  005F        MODE $0F                      ; Set InPIn as Input
        72  000E  0500        SETB IND.0                    
        73  000F  0200        MOV !RA,IND                   
            0010  0005
        74  0011  0018        BANK $00                      
        75  0012  0CFA        MOV FSR,#__TRISA              
            0013  0024
        76  0014  005F        MODE $0F                      ; Set OutPin as Output
        77  0015  0420        CLRB IND.1                    
        78  0016  0200        MOV !RA,IND                   
            0017  0005
        79  0018  0018        BANK $00                      
        80  0019  0C02        MOV __PARAM3,#(1+1)           ; Times to do the 255 count loop
            001A  002A
        81  001B  0CFF        MOV __PARAM2,#255             ; Count 255 loops
            001C  0029
        82  001D  0068        CLR __PARAM1                  ; Clear counter (value)
        83  001E  0705        JNB InPin,$+7                 ; Is input low ? Jump to (88)
            001F  0A25
        84  0020  0000        NOP                           ; Waste time
        85  0021  02A8        INC __PARAM1                  ; Adjust count (value)
        86  0022  0425        CLRB OutPin                   ; Make output pin low
        87  0023  0010        JMP @$+7                      ; Jump to (93)
            0024  0A2A
        88  0025  0525        SETB OutPin                   ; Make output pin high
        89  0026  0000        NOP                           ; Waste alot of time
        90  0027  0000        NOP                           
        91  0028  0000        NOP                           
        92  0029  0000        NOP                           
        93  002A  02E9        DJNZ __PARAM2,$-12            ; Inter loop (255)
            002B  0A1E
        94  002C  02EA        DJNZ __PARAM3,$-17            ; Outer loop (prime+1)
            002D  0A1B
        95  002E  0208        MOV value,__PARAM1            ; Save count (value)
            002F  002D
    

    Bean.
    [noparse][[/noparse]edit] I see I forgot the [url=mailto:'@']'@'[/url] for some of the jumps. I'll have to fix that... That will change the timing too... Darn...
                     
        81  000E  0CFA        MOV FSR,#__TRISA               ;  ANALOGIN InPin, OutPin, value
            000F  0024
        82  0010  005F        MODE $0F                      ; Set InPin as INPUT
        83  0011  0500        SETB IND.0                    
        84  0012  0200        MOV !RA,IND                   
            0013  0005
        85  0014  0018        BANK $00                      
        86  0015  0CFA        MOV FSR,#__TRISA              
            0016  0024
        87  0017  005F        MODE $0F                      ; Set OutPin as OUTPUT
        88  0018  0420        CLRB IND.1                    
        89  0019  0200        MOV !RA,IND                   
            001A  0005
        90  001B  0018        BANK $00                      
        91  001C  0C02        MOV __PARAM3,#(1+1)           ; # of time to do 255 loop
            001D  002A
        92  001E  0CFF        MOV __PARAM2,#255             ; Setup for 255 loop
            001F  0029
        93  0020  0068        CLR __PARAM1                  ; Clear counter (value)
        94  0021  0705        JNB InPin,@$+14               ; If pin is low jump to (101)
            0022  0010 0A2F
        95  0024  0000        NOP                           ; Waste time
        96  0025  02A8        INC __PARAM1                  ; Adjust value counter
        97  0026  0425        CLRB OutPin                   ; Make output low
        98  0027  02E9        DJNZ __PARAM2,@$-6            ; Loop 255 times (94)
            0028  0010 0A21
        99  002A  02EA        DJNZ __PARAM3,@$-12           ; Loop until done (92)
            002B  0010 0A1E
       100  002D  0010        JMP @$+9                      ; Jump to done (104)
            002E  0A36
       101  002F  0525        SETB OutPin                   ; Make output high
       102  0030  02E9        DJNZ __PARAM2,@$-15           ; Loop 255 times (94)
            0031  0010 0A21
       103  0033  02EA        DJNZ __PARAM3,@$-21           ; Loop until done (92)
            0034  0010 0A1E
       104  0036  0208        MOV value,__PARAM1            ; Save value in variable
            0037  002D
    

    Okay I put the [url=mailto:'@']'@'[/url] in the jumps AND make the loop tighter. This will be in the NEXT release. (1.51.01 ?)

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh


    Post Edited (Bean (Hitt Consulting)) : 8/3/2006 7:18:13 PM GMT
  • pjvpjv Posts: 1,903
    edited 2006-08-09 02:46
    Hi Bean & Josh;

    I still have not had a chance to detail your code, but a quick observation indicates that you balance the times by stalling for the right duration.

    I believe this procedure will not permit multiple simultaneaous readings, nor simultaneous communications??

    What I have for Josh is an approach that permits both.

    Josh, I spent quite a bit of time this weekend trying to get a sketch from "paint" to a reply in the forum, but no luck.
    I'm rather PC "challenged"!

    If you (or anyone, please) can help me with that, then I can move on. Also I had difficulty in exporting the "Spin" graphics characters (graphic characters change to small squares), but might yet figure how to get that to work. I believe you would need to install the Parallax font in order to be able to see it. Perhaps you have already done that. Please let me know if that is a reasonable avenue for you.

    Anyhow, I'm hoping to wrap my project up in the next week, then I will be more available.

    Cheers,

    Peter (pjv)
Sign In or Register to comment.