phase-shifted PWM

// stdint.h has types such as uint8_t and uint16_t
#include <stdint.h>

// inherent wrapping of limited data type does all the phase stuff you need during a simple add operation
// note that (255 + 1) & 255 = 0, which is exactly what happens when we work with 8 bit variables
uint8_t var, phase;

#define INITIAL_PHASE 30

// we recalculate the phase angle for 128 = 180 degrees, 256 = 360 degrees so simply adding does everything we need
// 30 degrees comes to about 21
for (var=0, phase=255 * INITIAL_PHASE / 360;;var++) {
doSomethingWith(var);
doSomethingWith(var + phase);
}