Shop OBEX P1 Docs P2 Docs Learn Events
help with timebase for sampled data — Parallax Forums

help with timebase for sampled data

kk Posts: 7
edited 2008-05-13 14:54 in Learn with BlocklyProp
Hello,
We have an analog signal that we want to convert to digital data using the LTC1298 ADC. We followed the code for BasicStamp II shown in the manual. The values are being displayed in the Debug window. However, we were wondering if the time axis can be obtained also, because we eventually want to plot the sampled data in an application like MATLAB.

We only really need to get samples for about 10 seconds or so. We want to see the time axis and plot our data in MATLAB to see if the ADC is sampling fast enough. I'm at a loss as to how to go about it. I mean, there's mention of COUNT, RCTIME, FREQOUT commands in the posts, but sorry I find it confusing. Any help in the right direction will be appreciated.

Thanks in advance for any info.

Comments

  • MSDTechMSDTech Posts: 342
    edited 2008-05-08 11:30
    What is the sample rate that you are dealing with?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-08 12:48
    There's no direct way to get a timebase without external timekeeping hardware. Because the Stamps run off a fixed clock, the execution speed of most Basic statements is reproducible and that can sometimes be used as a rough timebase. The trick is (in your case) to make the data collection loop as uniform as possible (executing the same statements with few IF / THEN statements that are dependent on data values). Then, calibrate the overall timing by measuring the total execution time, say for roughly 10 seconds of data collection, then dividing by the number of samples collected. That should give you your timebase.
  • kk Posts: 7
    edited 2008-05-08 15:09
    Our signal is an ECG signal from the heart. Frequency analysis shows that the highest frequency of the signal is around 60 Hz. So a sampling rate of more than 120 Hz? I looked at the manual for the LTC1298, there wasn't any mention of commands to set or change sampling rate. I may have missed something...

    But i will try Mr. Green's suggestion about getting the rough timebase. We will plot the data in MATLAB and see if the signal is getting sampled properly.

    Thanks for the replies.
  • MSDTechMSDTech Posts: 342
    edited 2008-05-08 16:00
    The LTC 1298 only samples when requested. The datasheet lists a maximum sampling rate of 11.1 ksps, so if you are sampling at 120 hz, you should have no major problems with the ADC keeping up. Setting a time reference will be the problem.
    To get an easy to build 120 hz signal, you can sync off the power grid, assuming you have 60 hz power. One possible way to do this is find a low voltage dc power supply with no filtering. They usually have a small transformer running through a bridge rectifier to achieve a pulsing dc at 120 hz. Fed through a voltage divider and with a protection resistor, the stamp should see this as a sequence of pulses at 120 hz.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2008-05-08 16:45
    It is going to be difficult to achieve that high a sampling rate (120 hz) with the BS2. That allows 8.3 milliseconds per sample, and the ADC subroutine itself is going to take a large portion of that. Then something has to be done with the data, such as sending it to the DEBUG window or to StampDAQ, and that too takes time, plus the other program overhead.

    The code in the manual could be modified to make it faster, by dispensing with the subroutines and optimizing for speed in a straight line loop. The fact remains that the conversion on the LTC1298 is limited by the speed of the shiftout command and the speed of the PBASIC interpreter to about 4 milliseconds for the core sequence,
    low CS ' Activate the ADC. 
        shiftout DIO_n,CLK,lsbfirst,[noparse][[/noparse]config\4] ' Send config bits. 
        shiftin DIO_n,CLK,msbpost,[noparse][[/noparse]AD\12] ' Get data bits. 
      high CS ' Deactivate the ADC.
    



    A faster Stamp, like the BS2p could help with the speed issue, but it will still take tight programming.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • kk Posts: 7
    edited 2008-05-13 05:11
    Thank you for all the info. We're beginners at programming, and that's the reason why we chose the BS2. We didn't realize that it'd be too slow to transfer data at the frequency we need.

    We do have microcontroller samples from Microchip. Will those be able to achieve the sampling rate (120Hz) that we need? And if we do use the PICs, will it be harder to program them? I hear one can program a PIC with BASIC, so can we still use the Parallax documentation for the LTC1298 (and also the eb500) to do the same project with the PIC?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-13 14:54
    Think seriously about using a Propeller Protoboard for your project. It has more than enough speed for your needs, has an absolute timebase with a 32 bit wraparound and a resolution of 12.5ns. There's a BS2 Compatibility Library that has subroutines for most of the specialized statements in Stamp Basic (like PULSOUT, SHIFTIN, SHIFTOUT, etc.) so it's pretty straightforward to convert Stamp programs to Spin (the Propeller's language).

    The Propeller can do 12 bit ADC at a 20K samples per second rate, more than fast enough for your project.

    Post Edited (Mike Green) : 5/13/2008 3:04:35 PM GMT
Sign In or Register to comment.