Chronulator software

Tessellated Circuits: Home => Old Home => The Chronulator SMD => software  

A bit about the software.

The original software produced by ShareBrained was written as an Arduino sketch. It requires a modified version of the Arduino bootloader to run properly. A derivative of the “original” code has been put into the github site  (I say derivative since the version there is not what I started with, even though the VERSION_RELEASE code is the same—that number is sent out the serial port upon reset if the port is enabled, or at least it was...).

Some time ago I decided to play with the code as well as the hardware. The results of the initial effort were announced in the ShareBrained forum . This got no interest, likely because most if not all Chronulator buyers were not able to program the Atmel part directly. So I eventually did make the same changes to the sketch code but for whatever reasons did not announce these changes...

The changes I made were mostly in the form of options. Each of the following except #5 and #6 are controlled by the presence of a definition for the compile-time “switches” which appear in the list, and in the code, as all caps:

  1. Added the compile-time switch PHASE_CORRECT to select a different PWM mode for the two outputs. The main advantage of the different mode is that there is no output pulse at a value of zero. This means that power-off mechanical zero calibration is sufficient for the "left end" calibration. Since the divisor is a fraction of 510 not 256, some extra work has to be done!;
  2. Added MINUTES_DOWN so that reverse/upside down meters can be used. Note that this does not change the polarity of the signal, rather it changes the output-with-time direction;
  3. Added HOURS_DOWN similarly;
  4. Added TWENTY_FOUR_HOURS to select a 24 hour clock display;
  5. Added up-edge switch debouncing. This makes it more tolerant of switch noise;
  6. Put in a second=0 statement to clear the seconds when minutes are set;
  7. Added in another option, CONTINUOUS_HOURS, to do the hours "continuously". This means that there are small steps (as small as can be made with the PWM circuitry as it is) instead of the per-hour steps;
  8. Added in yet another option, CONTINUOUS_MINUTES, to do the minutes "continuously". As above, smallest possible steps.

The code snippet below is the show_time function. It shows how the code is compiled one of four different ways depending on the two options which affect the driving of the minutes meter, and another four choices for the hours. No matter what combination of options are tuned on, only one line of code is compiled for each of the meter values, but the calculations of meter_m_value and meter_h_value are different for each case.

void show_time() {
#ifdef MINUTES_DOWN
  #ifdef CONTINUOUS_MINUTES
    meter_m_value = max_PWM -(minute * meter_scale_minutes +
                                     second/seconds_per_minute_scale_tick);
  #else
    meter_m_value = max_PWM -(minute * meter_scale_minutes);
  #endif
#else
  #ifdef CONTINUOUS_MINUTES
    meter_m_value = minute * meter_scale_minutes + second/seconds_per_minute_scale_tick;
  #else
    meter_m_value = minute * meter_scale_minutes;
  #endif
#endif

#ifdef HOURS_DOWN
  #ifdef CONTINUOUS_HOURS
    meter_h_value = max_PWM -(hour *meter_scale_hours +
                                       minute/minutes_per_hour_scale_tick);
  #else
    meter_h_value = max_PWM -(hour * meter_scale_hours);
  #endif
#else
  #ifdef CONTINUOUS_HOURS
    meter_h_value = hour * meter_scale_hours + minute/minutes_per_hour_scale_tick;
  #else
    meter_h_value = hour * meter_scale_hours;
  #endif
#endif
}

Oh, and the original code? Simply this:

void show_time() {
  meter_m_value = minute * meter_scale_minutes;
  meter_h_value = hour * meter_scale_hours;
}

As I said above these changes were made to a version of the sketch code (it was not even clear, when I first looked at doing this, that conditional compilation was possible in that environment). Now that I have a couple more Chronulator boards around I can continue with proper software development and maintenance.