Shop OBEX P1 Docs P2 Docs Learn Events
Using the Propellor for state data logging — Parallax Forums

Using the Propellor for state data logging

learninglearning Posts: 2
edited 2009-07-24 03:15 in Propeller 1
I am new at programming microcontrollers, and am wondering if it is possible to use the Propellor to create a data logger with an extremely high sample rate.

What I need to make is a data logger that will record the change of state (On/Off), with the accuracy of a few milliseconds, and record it to an SD card.

Is this possible? How would I go about doing it?

Comments

  • HannoHanno Posts: 1,130
    edited 2009-07-23 23:09
    Check out ViewPort- as long as you're connected to a PC, it'll do exactly what you want and more. It samples all 32 IO pins at adjustable frequencies up to 80 million samples per second. So, you're accuracy is 12.5nano seconds! In streaming mode, you can send all 32bits into your pc's memory at 2mbps, enough to take ~200,000 samples/second, or a time resolution of 5 micro seconds.
    Hanno

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Download a free trial of ViewPort- the premier visual debugger for the Propeller
    Includes full debugger, simulated instruments, fuzzy logic, and OpenCV for computer vision. Now a Parallax Product!
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-07-23 23:22
    Yes it is possible. There are objects available to write to SD cards, and the sample rate of the pins can be many factors better than "a few milliseconds". It will just be a matter of combining a few objects and the your own code/logic to control exactly what your care about.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!
  • lonesocklonesock Posts: 917
    edited 2009-07-23 23:25
    learning said...
    I am new at programming microcontrollers, and am wondering if it is possible to use the Propellor to create a data logger with an extremely high sample rate.

    What I need to make is a data logger that will record the change of state (On/Off), with the accuracy of a few milliseconds, and record it to an SD card.

    Is this possible? How would I go about doing it?
    For the best possible timing, you will want to use a fast crystal. Opinion varies on valid values for commercial applications. If you look at the data sheet you can see a temperature vs. fastest clock frequency graph. Using the Propeller Assembly, any crystal solution will get you a resolution well below the ms range.

    Look at the "waitpne" command. You can use it to suspend the cog until the input pins change state. As soon at the state changes, you can grab the new state and a snapshot of the time. I would recommend placing both the pin state (a 32-bit long) and the counter value (also a 32-bit long) into a buffer (sized for example 1024 bytes or 256 longs). Once you have 512 bytes of data logged you hand off that data to fsrw to write to a SD card for you. Meanwhile you continue logging state changes to the next part of your buffer. When the next 512 bytes are ready to go, hand them off, etc.

    I would recommend that you also set up your code to take periodic snapshots of the pin state, even if the state hasn't changed, say every 2^30 clocks. That way you can never have your clock counter roll over and miss it.

    This application would be simple enough that you could use most of the Hub RAM for a buffer, so any SD card speed hiccups won't mess you up.

    Note: if you want to do de-bouncing you will probably want to do that right after the cog wakes from the waitpne command.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-07-23 23:59
    The 32-bit counter takes over 53.68 seconds to roll over at 80MHz so if you know that you will have an event sometime in this period you can keep the code simple as Hanno mentioned by using the waitpne and although it might seem wasteful it is quite practical to log both 32-bit values. The thing with the Prop is that you don't need any complicated interrupt structures to maintain real-time logging as you can as Hanno mentioned again "hand them off" to another cog, isn't it wonderful.

    This kind of thing is very easy with the Propeller, don't worry too much about the exact details for now, just get into it because the Prop will not have any problems.

    *Peter*
  • learninglearning Posts: 2
    edited 2009-07-24 02:03
    Thanks everyone!

    I will have to spend some time to digest this, and thanks again for all your help, it's much appreciated.
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-07-24 03:15
    Jazzed has done code to display on the pc (see his signature for a link). I have done code to log using 4 cogs at up to 12.5uS (80MHz clock) and about 1800 samples. My code is linked in tools in my signature.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBladeProp, RamBlade, TwinBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80), MoCog (6809)
    · Search the Propeller forums (via Google)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Sign In or Register to comment.