Shop OBEX P1 Docs P2 Docs Learn Events
Circular buffer — Parallax Forums

Circular buffer

BasilBasil Posts: 380
edited 2007-07-08 23:40 in Propeller 1
Hi All,

I am going crazy trying to figure out how to do a circular buffer.

I need it to record flight data for a high powered rocket.

I need to record 500ms of data (rounded to the nearest full page) prior to launch detection, and wen launch is detected, I need to dump the buffer into my dataflash memory and continue recording in realtime (no buffer needed I dont think).

To maximise the dataflash's life expectancy, I would like to write page by page (as discussed in a previous thread).

The data is 3 x longs: flighttime, bADC, iADC.

My recording period is variable, but 10ms is the shortest period.

If someone could point me in the right direction that would be super! I have 1 cog available to do this in.

Thanks,

Alec

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-08 21:54
    Look at the keyboard driver (keyboard.spin) that's distributed with the Propeller Tool. It uses a simple 16 item circular buffer and the buffer size can be increased by powers of 2. Because the buffer is small, I suggest you use two identical buffers, one used up until launch and one used all the time. When launch occurs, you'd set a flag that the data acquisition routine would use. When the flag is set, it stops entering data into the first buffer. You'd have a cog that just waits until this flag is set, then writes the buffer and the buffer pointer to dataflash while everything else continues. 15 entries of 12 bytes each would fit into three 64 byte EEPROM pages plus the buffer pointer. I suspect you could actually use 3 words per entry rather than 3 longs. That would be only two 64 byte pages.
  • BasilBasil Posts: 380
    edited 2007-07-08 22:08
    Hi Mike,

    Cool, thanks for that pointer (no pun intended).
    Im a little confused how to use 3 words per entry rather than longs?

    The bADC and iADC are 12bit read from the MCP3208, and the flighttime variable need to record 600000ms (10 mins flight is probably overkill but I want to play it safe)

    Ill take a look at the kdb routine when I get home [noparse]:)[/noparse]
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-08 22:39
    bADC and iADC are each 12 bits which will each fit nicely in a 16-bit word.

    Regarding the time, you only need to record the time prior to launch (for saving this information). If your unit is 1ms, that allows for over a minute prior to flight time. If you want, you can also save the absolute launch time as a single 32-bit value in the second page of the EEPROM.
  • BasilBasil Posts: 380
    edited 2007-07-08 22:56
    "bADC and iADC are each 12 bits which will each fit nicely in a 16-bit word."

    Oh yeah! lol I new the 16bit thing but thought that was a long not a word :P

    "Regarding the time, you only need to record the time prior to launch (for saving this information). If your unit is 1ms, that allows for over a minute prior to flight time. If you want, you can also save the absolute launch time as a single 32-bit value in the second page of the EEPROM."

    The first data recorded (ie ~500ms prior to launch) I would liked to be tagged at 0ms. This would mean launch is at approx 500ms.
    Is this what you mean by absolute launch time?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-08 23:36
    By absolute launch time, I mean the time of launch to whatever resolution you want. For example, you could have milliseconds since midnight the current date and time to the nearest millisecond. You could certainly record the times as milliseconds since the first data item recorded.
  • BasilBasil Posts: 380
    edited 2007-07-08 23:40
    Ahhh, I see [noparse]:)[/noparse]

    Time since launch is the most practical but I may have a reason to use absolute time in another project. Thanks for the hint [noparse]:D[/noparse]

    Ill post again once I get stuck with the keyboard routine :P

    Thanks Mike
Sign In or Register to comment.