Studies On Criticality No. 1 – first steps

From page 3 http://journals.aps.org/prl/abstract/10.1103/PhysRevLett.59.381

From page 3 http://journals.aps.org/prl/abstract/10.1103/PhysRevLett.59.381

July 2014: Studies On Criticality No. N-Series is planned as an installation and experiment that explores self-organized criticality as an aesthetic phenomenon primarily but not solely by ear. The projects inquires this aspect of criticality defined as one of the crucial processes by which complexity arises in nature within the aesthetic framework of a minimalistic massive-multi-soundsource setting each of the soundsources acting as an audible cell of an artificial organism or an unit of a swarm. Hopefully the critical moments of such a programmed artificial non-linear system and its transitions from simple oscillation to complex behavior and finally to random noise will get audible. An Arduino Mega 2560, some mini-speakers (diameter about 1cm) and cables were used for prototyping. A first tentative to-do list (order is not significant) to achieve this idealistic goal was made:

  • program an Arduino Mega 2560 to do massively parallel signals generation. All signals must be individually controllable in its frequency and duration
  • check if amplification of the 5V 40mA signals is needed
  • check characteristics of mini-speakers in order to know more about the needed signal to drive them – make a frequency response – and check how to add directionality
  • sketch installation setting

 

Speakers
According to its datasheet the resonance frequency of the mini speaker (MCKP1227SP1-4721 by Multicomp) is 1.3kHz, but it seems to be more in the area between 1400 and 1600Hz. A diy-frequency responce testing was done using Supercollider3 to create the test sweep signal and the build-in microphone of a MacBookPro to measure/ record the response. The frequency analysis was done with Audacity. The loudest frequency seems to be 8589Hz and 8880Hz (see diagrams below).1


Here is the mini code for Supercollider3 for creating the sweep:
{ Pulse.ar(XLine.kr(40,20000,10),0.5, 0.5) }.play;

 

Connecting the speakers to an Arduino (not restricted to Mega 2560)
Testing simple snippets for LED-blinking, tone generation, timer control for parallel signal generation etc. with an Arduino Duemilanove (ATMega168) was first confusing since some snippets worked some not. After half a week of try and error, the importance of current draw calculation, measurement and the use of series resistor at the pins has been learned. To be more concrete: digitalWrite(13, digitalRead(13)^1); or digitalWrite(13, !digitalRead(13)); both seem to be good optimizations of digitalWrite(13, HIGH); delayMicroseconds(some value); digitalWrite(13, LOW); delayMicroseconds(some value); – these optimizations are important in context of “timing” explained in the next section – but need more detailed understanding.

In case the mini speaker (with 8Ω impedance, it draws 625mA) is directly connected to the specified pin the optimizations don’t work. First of all the rule that you always need a series resistor at the pins was unknown and secondly the exact working of the optimizations were as well unclear. These are the concrete snippets:

void setup()
{
pinMode(13, OUTPUT);
}


void loop()
{
digitalWrite(13, digitalRead(13)^1);
delayMicroseconds(57.24); // this is not working with an 8Ω impedance speaker
}

or
void setup()
{
pinMode(13, OUTPUT);
}


void loop()
{
digitalWrite(13, HIGH); // but this will
delayMicroseconds(57.24);
digitalWrite(13, LOW);
delayMicroseconds(57.24);
}

using the tone() function is as well working.


void setup()
{
pinMode(13, OUTPUT);
}


void loop()
{
tone(13, 8735);
}

Measuring the currents with a multimeter (Tenma 72-7745) at the specified pin the first code produces 71.5mA, both the second and last 36.5mA, which is under the maximum output value of 40mA. The first is above. Why?

Some guys via electronics.stackexchange.com helped me. The best explanations is: “digitalRead reads the state of the pin, not the value in the output register. If a heavy load is pulling the pin voltage low then it will read as logic 0 even if the output register bit is set to 1. Your first code example tries to toggle the output level by inverting the logic level found on the pin, but because it is always reading low the output will always be set high. Current is doubled because the output is ‘high’ 100% of time, not the 50% you expected.”

The solution for this is very simple: series resistors. Another problem is that the frequency definde via digitalWrite/Read is not exactly the same as calculated. The function delayMicroseconds(57.24) in combination with digitalWrite should create a square wave with a frequency of 8735Hz (=[1’000’000us/57.24us]/2), but in concrete implementation created a frequency of 7.65kHz (with digitalWrite(13, digitalRead(13)^1);) and 8.16kHz with the latter method measured with the Temna 72-7745 digital mult67imeter. In contrast tone() played the frequency more or less as coded, which was 8.77kHz at 28 Celsius.

 

Using the “timers” on the Arduino-Chips to enable parallel signals
In order to produce two or more different frequencies at two different pins some googling and reading was required, since it is a bit more complicated. Simply rowing the instructions will not work. It will create a mixed signal. For example using delayMicroseconds(60); in such a way (see below) will not create a frequency in the 8kHz area, but 3.875kHz, which is the about the half of the measured value (7.78kHz) for 60us.

void setup()
{
pinMode(13, OUTPUT);
pinMode(3, OUTPUT);
}


void loop()
{
digitalWrite(13, HIGH);
delayMicroseconds(60);
digitalWrite(13, LOW);
delayMicroseconds(60);


digitalWrite(3, HIGH);
delayMicroseconds(60);
digitalWrite(3, LOW);
delayMicroseconds(60);
}

Measured by an oscilloscope (Teledyne Lecroy WaveAce 1012) both signals look the same and have a frequency of about 3.87kHz. The “gap” between the squares is showing that the loop is as programmed alternating between doing digitalWrite for pin 13 and 3. Overlapping them creates the double frequency.

For a massive multi channel setting one needs to work with the “timers“.2 They are functional units of the ATmega chips on the Arduinos that count (via incrementing). For that reason they are sometimes are called “counters”. Timers are synchronized with the CPU clock. The timer can count to a certain value. It increments this counter one step at a time until it reaches its maximum value, at which point it overflows, and resets back to zero. This “feature” is used to generate a HIGH-signal at pin. The counter value and the incrementation (rate and bits per count) are thus defining the frequency (again half of it) of the signal.

The Arduino Mega 2560 has a 16 MHz crystal oscillator and has the following timers:

  • timer 0 (controls pin 13, 4), 8bit
  • timer 2 (controls pin 10, 9), 8bit
  • timer 1 (controls pin 12, 11), 16bit
  • timer 3 (controls pin 2, 3, 5), 16bit
  • timer 4 (controls pin 6, 7, 8), 16bit
  • timer 5 (controls pin 44, 45, 46), 16bit

This means that it can simultanously supply 15 individual pins at the same time, but one timer can generate only one frequency at a time. This means 5 different frequencies for 15 switchable pins.

  1. All this will depend later on resonance bodies etc. Speaker design. As well what is the maximum frequency for a good source location?
  2. Read as well these sources for an introduction A, B, C, D and E (in German) or google “arduino avr timer”.