Skip to main content

Posts

Showing posts from July, 2012

Memory access stride in loops change loop timing in AVR C!

I found a strange situation when programming in C for AVRs. I have a bunch of structures to be worked on, but any of them can be flagged "active" or not at any given moment, to signal whether they need further work. My first approximation was to add a (uint8_t volatile: set in main, checked in interrupt time) member variable named "active" to the struct, to quickly check/set each structure. Shock: only looping through the array checking the "active" member variables was taking an enormous amount of time – about 20 clock cycles per access !