 }
 
 void init_analog() {
-  for (int i = 0; i < 256; i++) wave[i] = (int16_t)round(ANALOG_DIVS*sin(i * 2 * (M_PI / 256)));
-  analogWriteResolution(12);
+  for (int i = 0; i < ANALOG_DIVS; i++) wave[i] = ANALOG_ZERO + (int16_t)round(ANALOG_AMPL*sin(i * 2 * (M_PI / ANALOG_DIVS)));
+  analogWriteResolution(ANALOG_BITS);
   analogWrite(A14, ANALOG_ZERO);
 }
 

 *******************/

Channel* process_get_channel(byte ch) {
  if (ch >= 'A' && ch <= 'Z' && ch != 'Y') {
    return channels + ((ch == 'Z') ? 25 : (ch - 'A'));
  } 
  else {
    char tiny[2];
    tiny[0] = ch;
    tiny[1] = 0;
    error_with_message("Unknown channel ", tiny, 1);
    return &not_a_channel; 
  }
}

Protocol* process_get_protocol(byte ch) {
  Channel *c = process_get_channel(ch);
  if (c->who != 255) {
    return protocols + c->who;
  }
  else {
    char tiny[2];
    tiny[0] = ch;
    tiny[1] = 0;
    error_with_message("No protocol for channel ", tiny, 1);
    return &not_a_protocol;
  }
}

 * Runtime *
 ***********/

volatile int tick;        // Last CPU clock count
Dura global_clock;        // Time since start of running.
Dura next_event;          // Time of next event.  Just busywait until then.

#define MIN_BUSY_US 1000
#define MAX_BUSY_US 20000
Dura io_anyway;           // Time at which you need to read I/O even if it may interfere with events

#define RUN_LOCKED   -3
#define RUN_ERROR    -2
#define RUN_TO_ERROR -1
#define RUN_COMPLETED 0
#define RUN_PROGRAM   1
#define RUN_GO        2
volatile int runlevel;   // -2 error; -1 stopping to error; 0 ran; 1 accepting commands; 2 running
volatile int alive;      // Number of channels alive and running

