19 Februari 2013

POV Globe - Part IV - Software & Data



One block of data = 512B = 4096bit = 16 columns.One revolution (or "frame") = 512 columns = 32 blocks = 16KB.One second of animation = 50 frames = 800KB.A quick calculation shows that 1GB of data can hold a little over 20 minutes of 50FPS animation. My card has 2GB, and it is easy to find cards with more.
The format is as follows:
First 4 bytes are the total number of blocks in the image, followed by 508B of padding.Then the image itself follows, column-by-column, where the bytes in each column are ordered from top 8 LEDs to bottom 8 LEDs, and the bits in each byte are ordered so that the MSB is the top LED and LSB is the bottom LED.
A timer keeps the time elapsed since the beginning of the column.The variable col_dur holds the duration of a single column (1/512 the duration of a revolution) - it is updated every time we get an IR pulse.The variable pos keeps the current (estimated) physical position of the LEDs, between 0..511.The variable cur_col keeps the last column that has been drawn, between 0..511.And the main loop looks something like this:while (true) { // draw all the columns until the current position while (cur_col != pos) { draw_column(); if (++cur_col == 512) col = 0; } while (TIMER < col_dur); // wait until the end-of row time // advance position according to how much time elapsed do { TIMER -= col_dur; if (++pos == 512) pos = 0; } while (TIMER >= col_dur); // check position sensor and make adjustments if (pos == 0) { ... wait for rising edge of the sensor ... ... recalculate col_dur (make it longer or equal), and reset TIMER ... } else if (sensor_rising_edge()) { // got a premature signal - we're falling behind ... force pos = 0, recalculate col_dur (make it shorter), and reset TIMER ... }}The draw_column() function just streams 32B of data from the SD to the LED board, pulses the latch line, and then prepares the next column (i.e. issues a SD command to get the next block and waits for it to become ready, if needed).

View the original article here

Ikuti Blog ini


Mau dapet Update-an Blog ini lewat e-mail? Masukkin aja alamat Email kamu disini:

Dikirim Oleh FeedBurner