Monochron - Large Sprite Animation Problem - SOLVED

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
terranjerry
 
Posts: 38
Joined: Tue Feb 11, 2014 1:39 pm

Monochron - Large Sprite Animation Problem - SOLVED

Post by terranjerry »

I don't know if anyone on the forum is working with programming their own clocks for the Monochron and doing sprite animation on it but I thought I would ask this question and see if there is someone who can help me in this area.

I have animated smaller sprites (16x16) on the Monochron with no problem. For that I use a 16 bit word. Recently I created a 32x32 sprite and animated it using 32 bit storage.
However, the problem I am running into is that it seems that when I animate this spirte, it occasionally generate pixels in odd places (somewhat at random but perhaps not entirely so) and not in the correct place when drawing the sprite.
I will try to post up a snippet of the code for this so you can see how i am rendering the sprite soon.

However, that said, I was wondering if perhaps there is a timing issue with my use of glcdSetDot() and glcdClearDot() which I use to draw and erase the individual pixels that make up my sprite.
Basically I first set all the bits in my sprite in a loop by calling glcdSetDot(), wait a few msecs and then clear all the same bits in another loop by calling glcdClearDot() before advancing the sprite one X position forward and then set the pixels again, wait, clear, etc.
I do this about as fast as the processor can run except for the very slight wait in between the loops. So, perhaps I am pushing it too hard but I have tried delaying and it still seems to happen.

The other thought I had is perhaps I am running out of memory with such a large sprite.
Can someone tell me how to judge the size of my program either after compilation or at run-time? Or conversely, how much free memory is left?
I'm sorry if that's a very basic question but I'm not familiar with this programming platform well enough to know if I can just get that from the map or some other source.

I would like to try source level debugging this code but am not sure how to go about that on the Monochron just yet but I am going to look into this.

Anyway, I know this isn't a lot to go on but any tips in which direction to look are most appreciated. I was pleased that my earlier sprites behaved in a predictable manner but this larger sprite is causing me a problem of unknown origin.

One other tip - in addition to the screen failing to update the pixels properly when it animates, I have also seen it wig out completely in which case the entire display starts flashing wildly like the processor is in some type of continuous reset loop - so perhaps I am blowing the stack or otherwise corrupting memory in some manner. Is there such thing as stack size adjustments for this platform?

I'll post up the sprite loop shortly.

Thanks for any tips you might wish to share.

Kind regards,
Jerry
Last edited by terranjerry on Wed Feb 12, 2014 9:53 am, edited 1 time in total.

User avatar
terranjerry
 
Posts: 38
Joined: Tue Feb 11, 2014 1:39 pm

Re: Monochron - Large Sprite Animation Problem

Post by terranjerry »

Ok, here is a code snippet of my 32 bit sprite animation (attempt) - the system goes wild shortly after trying to render this several times...

Here is my sprite:

Code: Select all

static uint32_t big_ship_image [32] = {
0x4000,0xA000,0x11000,0x21400,0x41A00,0x81300,0xF81280,0x881280,
0xA81280,0xA81280,0xA81280,0x8812C0,0xA812C0,0xA812C0,0xA812E0,0x8812E0,
0xA812E0,0xA812C0,0xA812C0,0x8812C0,0xA81280,0xA81280,0xA81280,0x881280,
0x881280,0xF81280,0x81300,0x41A00,0x21400,0x11000,0xA000,0x4000	
}
;

And here is the code that manipulates it... one routine draws it, the other erases it.
Perhaps I am missing something fundamental here but I welcome a second pair of eyes that might help me!
By the way, I tried it with "long" too instead of uint32_t - same result.

Code: Select all

 uint32_t big_ship_width = 32;
 uint32_t big_ship_height =32;

Code: Select all

void draw_big_ship(uint32_t x, uint32_t y) {
   uint32_t xp;
   uint32_t yp;

Code: Select all

// Draw the big_ship 
  for(yp = 0; yp < big_ship_height; yp++){
    for(xp = 0; xp < big_ship_width; xp++){
      if (big_ship_image[xp] & ((uint32_t)1 << yp)){
      	 if( (x+xp <= MAX_X) &&
            (y+yp <= MAX_Y) &&
	    (x+xp >=0)            &&
	    (y+yp >=0)                   ){	      
           glcdSetDot( (uint8_t)(x + xp),(uint8_t) (y + yp) );
	   //_delay_ms(1);
	}
      }
    }
  }
} // end of function draw_big_ship

Code: Select all

void erase_big_ship(uint32_t x, uint32_t y) {
uint32_t xp;
uint32_t yp;

// Erase the big_ship sign space...
  for(yp = 0; yp < big_ship_height; yp++){
    for(xp = 0; xp < big_ship_width; xp++){
      if (big_ship_image[xp] & ((uint32_t)1 << yp)){
      	if( (x+xp <=MAX_X) &&
            (y+yp <=MAX_Y) &&
	    (x+xp >=0)            &&
	    (y+yp >=0)                   )
            glcdClearDot( (uint8_t)(x + xp),(uint8_t) (y + yp) );
	    //_delay_ms(1);
      }
    }
  }
}
At this point I don't have any ideas about why it works for a while and then dies.
Perhaps I am rushing the glcdSetDot and glcdClearDot calls? (However adding delay didn't seem to help).
Could this be a stack issue or an overall memory issue?

Thanks in advance for any tips.

User avatar
terranjerry
 
Posts: 38
Joined: Tue Feb 11, 2014 1:39 pm

Re: Monochron - Large Sprite Animation Problem - SOLVED

Post by terranjerry »

I have figured out this problem and have to say at this point it seems incredibly obvious - especially given the excellent help provided by Adafruit at this address:
http://learn.adafruit.com/memories-of-a ... ot-dot-dot

I learned that my heap is indeed crashing into my stack when I added the large 32bit sprite. I also learned that what I am trying to do may just not fit into the tiny SRAM space of the little Arduino inside the Monochron clock but hey - that's the challenge of engineering something right? ;o)

Anyway, the addition of this large sprite had definitely shoved my heap up into my stack which caused all kinds of errant operation.
I found a function I could use to print the heap vs. stack differential to the serial port and in so doing watched the heap clobber my stack. Oh well - back to the drawing board.

I have left this item in hopes that it will prove useful to someone else.
Much of what I have learned was ably covered by the Adafruit link above.
So, if you had a well behaved Monochron program and you 'enhanced' it some (as I did) and you are now getting unpredictable operation out of it - then definitely check out the Adafruit link above. It is well written and an excellent description of what might be the problem and even some things to do to resolve it.

Happy Monochroning! ;o) - Kind regards, Jerry

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”