Shop OBEX P1 Docs P2 Docs Learn Events
BS2e Programming Question — Parallax Forums

BS2e Programming Question

'O Flyer'O Flyer Posts: 9
edited 2005-05-05 19:12 in BASIC Stamp
Hello,

I'd like to write a program for a BS2e. In my "declarations" I state that I/O pin 3 is·connected to·"serial data out" from an A/D converter by writing:

SDO······CON····· 3

The bits arriving at I/O pin 3 from the converter·I've described this way:

AD_SDO···· VAR···· Bit

My question: How does one·state·within the program that bit variable "AD_SDO"
is arriving at I/O pin 3?· A relationship has to be defined. How does one do that? I don't want to see you·do this in the comments!!!·I'm hoping I can understand the answer. I have a couple of programming examples in front of me by apparently competent programmers, but unfortunately one of them is incomplete, and they're both as clear as mud, as they say.

Vern Roach


Post Edited By Moderator (Jon Williams) : 5/4/2005 1:03:21 PM GMT

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-05-04 06:07
    Vern -

    First, I suspect that you're ADC will be sending more than one bit - probably 8 bits, and the data will be "clocked" in. Also you need to assign a "clock" pin, so you want to declare the variable thusly:

    SDO CON 3 'Assign data pin
    DCLK CON 4 'Assign clock pin for bit timing
    AD_SDO VAR BYTE ' 8 bits of ADC data

    Now were ready to roll. Here's where the "relationship" is made, in the verb which accesses the ADC:
    ' clock data variable
    ' pin pin name
    SHIFTIN DCLK, SDO, AD_SDO

    Now, SDO will contain 8 bits of data, presuming the ADC you're using produces just 8 bits, and not more. If it produces more than 8 bits, adjustments need to be made in the size of the variable (byte --> word). More details can be found in the manual or in the help file under SHIFTIN.

    Regards,

    Bruce Bates
  • BeanBean Posts: 8,129
    edited 2005-05-04 11:08
    Vern,
    What A/D are you using ?
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video Display Module" Available Now.

    www.sxvm.com

    "I thought I was wrong once...But I was mistaken [noparse];)[/noparse]"
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 13:05
    If you're using a synchronous serial device, then SHIFTOUT and SHIFTIN are probably best. Also, use PIN to define IO pins so that the compiler can take care of context-sensitive issues.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • 'O Flyer'O Flyer Posts: 9
    edited 2005-05-04 22:59
    To both Jon and Bruce,

    The fairly·straightforward SHIFTIN and SHIFTOUT commands would be workarounds to·the problem but for the fact that the Stamp manual seems to indicate that they employ a clock cycle time of 60 microseconds. The recommended max. sample clock cycle time for the (4 ch., low current drain) Tx. Instruments TLV2544 A/D·converter that I'm using is 10 microseconds, so I had been looking at other approaches, e.g., using the PULSOUT command as is done in "Stamp Applications No.4" about interfacing a BS1 with the LTC1298 ADC. But that article raised·questions, because, among other things, while "PIN" is a reserved word for the BS1, it is not for the BS2e, i.e., "PIN" means no more to the BS2e than "NIP", lets say.·Am I right on this? Lately·I'd been·trying to pattern parts of my program after a program in an article called "Basic Stamp 2 - Measuring Atmospheric Pressure and Wind Direction" at www.phanderson.com/stamp/wx_ad, but its presentation on that site at least·is incomplete, e.g., it lacks the declarations of its variables and constants. I guess my question really amounted to "How is he (at phanderson.com) doing it?

    A week or so ago I spoke to a man at the Tx. Instruments technical help line and he seemed to say that a "slow" host processor is seldom a problem in interfacing with an ADC -·and the '2544 data sheet does say that 10 microseconds is the recommended·max sample clock cycle time. Also "recommended"·for the '2544 is a nearly symmetrical sample clock cycle, but its hard to believe that everyone who writes code for a microprocessor/ADC interface has to 'scope the circuit to determine the data-in or data-out subroutine cycle time·to thereby arrive at an appropriate (50%) PULSOUT (or equivalent) pulse width for the sample clock.

    I'm going to try it with the SHIFTIN and SHIFTOUT commands, but in the meantime, if anyone knows·from experience that a BS2 or BS2e can be interfaced with·the faster (or more modern) type of ADC (200K samples/sec vs 11.1K samples/sec for the LTC1298), their comments would be much appreciated.

    Vern Roach
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-05 00:58
    Vern,

    ·· The BASIC Stamp 1 will interface with the LTC1298...So yeah, the BS2 can handle it as well.· We sell it.· But on the PIN definition, it IS a reserved word for the BS2.· But you have to have the PBASIC 2.5 directive in your code for it to mean anything.· Since I tend to use a template, I always have that directive in my code.· And I always use the PIN command in place of just a CON statement due to it's versatility.··You can find information about this command in the Help file built into the editor.· Of course, your editor may or may not be dated.· I would recommend downloading the latest version if you're in doubt.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-05 01:25
    If your ADC is a synchronous serial device, them I'm betting it will be fine. A few months ago a customer complained that the BS2 SHIFTOUT/SHIFTIN bitrate was too slow for the ADC08832 (?) and I found that it worked without any problems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • 'O Flyer'O Flyer Posts: 9
    edited 2005-05-05 19:12
    Chris,
    Thanks for enlightening me on PBASIC 2.5 and the PIN declaration. For a couple of months I've had the Parallax CD ("software/documentation/product briefs/...") dated Sept. 2004, but had just been skimming past it - much to my detriment!

    Jon,
    My recollection from reading the data sheet a few hrs. ago is that the (National Semiconductor) ADC08832 has a throughput of something like 153K samples/sec., so your words are reassuring. I'm now thinking that certain recommended high clock speeds are merely meant to maintain the advertised throughputs...which would make sense.

    Vern Roach
Sign In or Register to comment.