Shop OBEX P1 Docs P2 Docs Learn Events
Programming to send the ouput from the ADC 0831 via serial port — Parallax Forums

Programming to send the ouput from the ADC 0831 via serial port

erick_2987erick_2987 Posts: 11
edited 2011-03-12 07:42 in BASIC Stamp
Hi,

i want to do a programming to send digital output from the ADC 0831 to computer serial port via RS232 cable. The input from the serial port(computer) will be recorded for 10 seconds and process via matlab.
i need some guidance from u guys to make the BS2P mc to send data from ADC for 10 sec and pause a while and send data again as loop. Thank you.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-07 17:50
    There are examples of the use of an ADC0831 in the Nuts and Volts Columns and in the Basic Analog and Digital tutorial. You can find the Columns index by clicking on the Resources button on the main Parallax webpage. All of the tutorials can be downloaded by clicking on the Downloads button on the main Parallax webpage, then clicking on the Educational Tutorials & Translations button on the downloads page.

    To send data to the PC, use the DEBUG statement. The Basic Stamp Syntax and Reference Manual describes this in detail. The "What's a Microcontroller?" tutorial in the tutorials webpage is a good introduction to Stamp Basic and will show you how to pause and make loops.
  • ercoerco Posts: 20,257
    edited 2011-03-07 18:34
    Here's one of the Parallax app notes: http://www.parallax.com/dl/docs/prod/acc/SharpGP2D12Snrs.pdf
  • erick_2987erick_2987 Posts: 11
    edited 2011-03-08 02:41
    Thank u mike and erco. Actually what i mean to is send the output from the adc to computer via serial communication. the output from the ADC is continuous. i want to send the data for 10sec to computer and pause a while. The data will be processed via neural network in matlab and show the output in GUI. I want to know the programming for this process. i think DEBUG is normally used to show the current value in Pbasic's GUI.. Cn any1 gv me the link where i can get some ideas about neural network and BS2 interface. Thank you...
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-08 07:26
    DEBUG is the way to send serial data from a Stamp to the attached PC via the same serial port used for programming. As far as the PC is concerned, this is just an ordinary serial port. The SEROUT statement with a "pin #" of 16 is functionally equivalent. There's nothing special or ready-made about a neural network and the BS2.

    How many samples do you expect in 10 seconds? How regular do they have to be? Do you want to read and save the samples first, then send them to the PC during the pause? The BS2 has 2K of EEPROM for your program and a simple program won't take that much. You could store a couple of hundred samples in the EEPROM and then send them to the PC separately. Remember that it takes about 1ms per character to transmit a message to the PC and the Stamp can't sample the ADC while it's transmitting. It also takes a few ms to store a value in the EEPROM.
  • erick_2987erick_2987 Posts: 11
    edited 2011-03-11 18:35
    at least i want 200 samples per second. i want the bs2 read and save the samples first , and then send the samples to the pc. first i try with plx-daq to retrive the samples i only gt 23 samples per second. nw im trying with matlab to retrive the stored samples inside bs2's eeprom. i tried in many way still i cant get the solution...
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-11 21:48
    200 samples per second gives you about 5ms per sample. That's not enough time to read a sample and store it in the EEPROM. Not only that, but 10 seconds worth of samples at that rate is about 2000 samples and you have only about that much memory in the EEPROM (and you have to get your program in there too).

    You need something like a Propeller for that sort of sample speed. The Propeller also has enough memory to keep the samples in SRAM which doesn't have the speed limitation of EEPROM. You could attach a Ramtron FRAM to your Stamp or Propeller for a memory that behaves like EEPROM, but doesn't have the speed limitation. 5ms is still too little time for a BS2. You might manage with a BS2px and could use the built-in I2C statements to access a FRAM to store the samples.

    Remember that MATLAB can't "retrieve" the stored samples from any Stamp or Propeller. There has to be a program in the Stamp (or Propeller) that gets the stored samples and sends them to MATLAB.
  • erick_2987erick_2987 Posts: 11
    edited 2011-03-12 00:05
    where can i get some codes or guidance to send stored data to the matlab. Any sample projects which work in matlab... i need it urgently. I tried many time to interface bs2 with matlab but not succeed.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-12 07:35
    Look in the MATLAB forums for information on transmitting and receiving serial data (like this). From the Stamp side, you're going to be using SEROUT and SERIN, possibly DEBUG and DEBUGIN. These are described in detail in the Stamp Manual and the Stamp Editor's help files. You're going to have to write a program for the Stamp that goes through the saved data (using READ) and transmits it to your PC, probably using DEBUG. You haven't said just what data you're storing. If it's just the samples from the ADC0831, you could just format them as decimal numbers, one per line of text like this: "DEBUG DEC sample,CR". If the sample value is 101, MATLAB would see the characters "1", "0", "1", then a carriage return. The "RS232_Read_Format" routine mentioned in the above link would read this and convert it to a numeric value for processing.
  • Mike GMike G Posts: 2,702
    edited 2011-03-12 07:42
    The code that I posted on your other thread shows how to transmit a byte from the STAMP to MatLab. Did you try it?
    http://forums.parallax.com/showthread.php?130180-help-with-Matlab-and-serial-communication
Sign In or Register to comment.