<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[The 1-Bit Forum — Tritone on Arduino]]></title>
	<link rel="self" href="https://randomflux.info/1bit/extern.php?action=feed&amp;tid=126&amp;type=atom" />
	<updated>2017-08-03T16:32:27Z</updated>
	<generator>PunBB</generator>
	<id>http://randomflux.info/1bit/viewtopic.php?id=126</id>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1438#p1438" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>garvalf wrote:</cite><blockquote><p>@chupo_cro: I&#039;ve tried your code, and it seems to fix the problem, thanks. </p><p>I don&#039;t remember how was Shiru&#039;s code before he fixed the tempo problem, but now we have both the correct tempo, and the songs won&#039;t halt after a while (the &quot;bourrasque&quot; tune lasts 2 minutes, until the end, after it loops, instead of 10 seconds before)</p><p>Like for the other engines, we can add a nice led for lighning during the beats:</p><div class="codebox"><pre><code>if(drum_pulse_length)
    {
        --drum_pulse_length;
               digitalWrite(LED,HIGH);
    }</code></pre></div></blockquote></div><p>Hi, I am not aware how the code looked like before, I have downloaded it this night. Since the variable used in a while loop is 8 bit, the only change was to remove the delay. That is possible because <strong>parser_sync_enable</strong> is always zero when loading <strong>parser_sync_l</strong> and <strong>parser_sync_h</strong>. If that would not be the case <strong>cli()</strong> and <strong>sei()</strong> would have to be added before <strong>parser_sync_l</strong> and after <strong>parser_sync_h</strong> respectively to prevent an interrupt in between loading low and high byte.</p><p>As for the &#039;light show&#039;, I have this little nice <strong>ATmega128</strong> board (a picture) which has two SMD LEDs connected to the lowest two bits of the PORTA so the nice effect can be done by:</p><div class="codebox"><pre><code>if(n&gt;=2&amp;&amp;n&lt;128)  //drum sound
    {
        drum_data=(const unsigned char*)pgm_read_word(&amp;(drum_sample_list[n-2]));

        drum_output=0;
        drum_pulse_length=0;
        drum_sync=0;
        drum_request=1;

        PORTA ^= 0x03;        // turn off one of the LEDs and turn on the other one
                
        ++pattern_ptr;
    }</code></pre></div><p>For that to work I added:</p><div class="codebox"><pre><code>// LEDs
DDRA = 0x03;        // PA0 &amp; PA1 = output
PORTA = 0x01;        // light on one of the LEDs</code></pre></div><p>The same code could be used with Arduino by changing the port (and maybe the pins) and connecting one more LED.</p><p>The positions to add &#039;light show&#039; code are:</p><p><strong>Phaser1:</strong></p><div class="codebox"><pre><code>else  //118..127 is a drum
{
    drum_ptr=0;
    PORTA ^= 0x03;        // turn off one of the LEDs and turn on the other one
    drum_sample=1&lt;&lt;(tag-118); //bit mask for the drum sample

    cli();
    parser_sync=MUSIC_FRAME*1;  //drum always take one tempo unit, so it normally followed by the wait command
    sei();
}</code></pre></div><p><strong>Octode:</strong></p><div class="codebox"><pre><code>if(n&gt;=0xf0)
{
    click_drum=7-(n-0xf0);
    click_drum_len=128;
    PORTA ^= 0x03;        // turn off one of the LEDs and turn on the other one

    ++pattern;  //skip to the next byte
}</code></pre></div><p><strong>Qchan:</strong></p><div class="codebox"><pre><code>if(tag&gt;=0x81) //a drum
{
    tag=(tag-128)&lt;&lt;1;
     
    click_drum_cnt_1=tag;
    click_drum_cnt_2=tag;
      
    click_drum_len=0;
    PORTA ^= 0x03;        // turn off one of the LEDs and turn on the other one
 
    ++pattern_ptr; 
}</code></pre></div><p><strong>Fuzzclick:</strong></p><div class="codebox"><pre><code>if(tag&gt;=0x81&amp;&amp;tag&lt;0x81+4)
{
    drum_data=(const unsigned char*)pgm_read_word(&amp;(drum_sample_list[tag-0x81]));
                
    drum_output=0;
    drum_pulse_length=0;
    drum_request=1;       //interrupt handler will get changed in the next tone interrupt

    PORTA ^= 0x03;        // turn off one of the LEDs and turn on the other one
}</code></pre></div><p> It is quite nice to watch the dot jumping on every drum beat, I might record a video.</p><p>I am BTW using this <strong>ATmega128</strong> board only when developing because the programs can fit in the memory even with the disabled compiler optimizations which can sometimes be neccesarry and because I can use cheap JTAG. The PCBs which I like to use for final products are <a href="https://www.dropbox.com/sh/9qft6lkox9z73ry/AACup-QzIG-WNYtfTUA4MCZ8a">this one</a> and <a href="https://www.dropbox.com/sh/zaze7pqolc6tlb9/AACY2psnbaXW40PBqy7pgs_va">this one</a>. These are <strong>Dropbox</strong> links to picture albums, <strong>no need to register</strong>.</p>]]></content>
			<author>
				<name><![CDATA[chupo_cro]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=106</uri>
			</author>
			<updated>2017-08-03T16:32:27Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1438#p1438</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1437#p1437" />
			<content type="html"><![CDATA[<p>@chupo_cro: I&#039;ve tried your code, and it seems to fix the problem, thanks. </p><p>I don&#039;t remember how was Shiru&#039;s code before he fixed the tempo problem, but now we have both the correct tempo, and the songs won&#039;t halt after a while (the &quot;bourrasque&quot; tune lasts 2 minutes, until the end, after it loops, instead of 10 seconds before)</p><p>Like for the other engines, we can add a nice led for lighning during the beats:</p><div class="codebox"><pre><code>if(drum_pulse_length)
    {
        --drum_pulse_length;
               digitalWrite(LED,HIGH);
    }</code></pre></div>]]></content>
			<author>
				<name><![CDATA[garvalf]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=6</uri>
			</author>
			<updated>2017-08-03T14:12:02Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1437#p1437</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1436#p1436" />
			<content type="html"><![CDATA[<p>Since <strong>parser_sync_enable</strong> is just one byte, this time you can fix the sync code just by:</p><div class="codebox"><pre><code>//set up parser sync counters

parser_sync_l=song_tempo&amp;255;
parser_sync_h=song_tempo&gt;&gt;8;
parser_sync_enable=1;

//wait for the next row
//delay 1 is important, by some reason song tempo starts to jump a lot without it

//while(parser_sync_enable) delay(1);
while(parser_sync_enable)
    ;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[chupo_cro]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=106</uri>
			</author>
			<updated>2017-08-03T01:12:02Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1436#p1436</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1188#p1188" />
			<content type="html"><![CDATA[<p>No, Linux double boot is not an option. Unfortunately my notebook that is normally used for such things broke, and I don&#039;t want to mess with my main working PC having no backup working machine.</p><p>Interestingly, I noticed that while the COM monitor is active, the resetting stops, so it became a bit easier to debug.</p><br /><p>Anyways. I think I found a fix for the player hanging. That&#039;s likely related to the way I was invoking the drums - by changing the interrupt handler pointer from the main thread. But that&#039;s AVR8, so this operation is not atom - it changes two bytes one by another, and there is a good chance (considering the high sample rate) that timer interrupt will occur in the middle of the change, calling the half-changed address of the handler function. I tried to fix it by changing the handler only in the timer interrupt handler, where it is guaranteed that another interrupt won&#039;t occur. Re-attached the code to the first post, please test.</p>]]></content>
			<author>
				<name><![CDATA[Shiru]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=11</uri>
			</author>
			<updated>2017-02-26T10:42:42Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1188#p1188</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1187#p1187" />
			<content type="html"><![CDATA[<p>Could the use of a linux double boot be an option for you?<br />Or if the problem is the arduino software, trying an older version?</p>]]></content>
			<author>
				<name><![CDATA[garvalf]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=6</uri>
			</author>
			<updated>2017-02-25T07:23:40Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1187#p1187</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1186#p1186" />
			<content type="html"><![CDATA[<p>I also found and read that article about phone software interferring with Arduino. Actually tried to remove all drivers that use COM mode, figured out which ones they are using USBDeview. Nothing changed at all - unstable upload, constant resetting. Guess the only option that is left is to disable the auto reset indeed, will try it later.</p>]]></content>
			<author>
				<name><![CDATA[Shiru]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=11</uri>
			</author>
			<updated>2017-02-25T06:18:38Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1186#p1186</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1185#p1185" />
			<content type="html"><![CDATA[<p>Was just reading about <a href="https://robinelvin.wordpress.com/2012/03/06/arduino-resetting-itself-on-usb/">this guy&#039;s troubles</a>, so a software issue seems quite possible. </p><p>Perhaps it&#039;s easier to <a href="http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection">disable auto-reset</a> until you&#039;ve found the culprit?</p>]]></content>
			<author>
				<name><![CDATA[utz]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=2</uri>
			</author>
			<updated>2017-02-24T10:17:13Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1185#p1185</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1184#p1184" />
			<content type="html"><![CDATA[<p>Found the power supply. Didn&#039;t help, the Arduino keeps resetting after a few seconds while it connected to the PC. So that&#039;s not a power issue, likely a software one (something accesses the USB port, causing resets).</p>]]></content>
			<author>
				<name><![CDATA[Shiru]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=11</uri>
			</author>
			<updated>2017-02-24T09:42:09Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1184#p1184</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1179#p1179" />
			<content type="html"><![CDATA[<p>Thanks for the information, I&#039;ll try to figure out what&#039;s going wrong. It has to be something with the code. Maybe the interrupt train system is not very reliable in some case. Although it is very determined and set to exact same state at start, so it expected to fail always at the same spot.</p><p>My Arduino works well with the external 5V power source plugged into USB. The problem is that I need to have it hooked up to PC in order to debug. Haven&#039;t found a suitable 9V adapter just yet (&#039;minus outside&#039; are rarity here, don&#039;t have spare ones to rewire either), hopefully it will fix the issue.</p>]]></content>
			<author>
				<name><![CDATA[Shiru]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=11</uri>
			</author>
			<updated>2017-02-19T15:42:35Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1179#p1179</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1178#p1178" />
			<content type="html"><![CDATA[<p>I remember before your last fix one song stopped after only a few seconds. But after your fixed it worked (at least longer).</p><p>I&#039;ve tested on another arduino (a dccduino clone), and it&#039;s the same, it stops at the same moment. But this moment seems rather random from one song to an other: I&#039;ve isolated the part when I stopped, and removed all patterns before it. Then this time it won&#039;t stop there, but only after a while.</p><p>In the original &quot;bourrasques&quot; tune it stopped after 25 seconds, now with this abridged version, it&#039;s after 12 seconds, will it be enough for you to test? Here is the music_data as attachment.<br />I&#039;ve put 2 files, one (v0) with the original data, only the part before the bug were removed, but the song last until the normal end. For the other one, I&#039;ve removed the end, I&#039;ve only kept the data until it stops + about 3 seconds, so it&#039;s supposed to stop after 15 seconds but will stop at 12 sec.<br />I&#039;ve also tried to remove the loop (I chose exit instead before compilation) but it&#039;s the same, stop after 12 sec (the output data are identical)</p><p>Will your arduino reset as well if you plug it to a 5V phone charger, after you&#039;ve uploaded the sketch?</p>]]></content>
			<author>
				<name><![CDATA[garvalf]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=6</uri>
			</author>
			<updated>2017-02-19T12:16:07Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1178#p1178</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1177#p1177" />
			<content type="html"><![CDATA[<p>That&#039;s weird, but I can&#039;t really test it - neither I know how the songs supposed to sound, nor my Arduino works stable while it connected to the PC, it randomly resets after a few seconds, and I haven&#039;t found a fix for this yet. If you will be able to provide a test where it will be easy to spot the issue, like really hanging on the first notes or something, I&#039;ll be able to examine and fix the problem (none of your tests stopped too soon for me, but I wasn&#039;t able to listen them entirely).</p>]]></content>
			<author>
				<name><![CDATA[Shiru]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=11</uri>
			</author>
			<updated>2017-02-19T10:51:33Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1177#p1177</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1175#p1175" />
			<content type="html"><![CDATA[<p>the one called music_data_snakecharmer.h replays completely. &quot;Incantation&quot; stops after a while, like &quot;bourrasque&quot;. The one called &quot;souvenirs&quot;&nbsp; plays for most of the song, but is cut anyway before the end. The mister beep song replays correctly. What could it be? What is strange is one parts plays well, while later the same part which is repeated will stop abruptly.</p><p>I&#039;ll test it on another arduino, in case it&#039;s the one I use (official Arduino Uno) which has some limitations (but it doesn&#039;t stop like that with other engines). I&#039;ve already encountered differences between arduino versions, for example a shield was working on a clone, but not on the official one, and not either on another clone.</p>]]></content>
			<author>
				<name><![CDATA[garvalf]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=6</uri>
			</author>
			<updated>2017-02-19T09:04:12Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1175#p1175</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1174#p1174" />
			<content type="html"><![CDATA[<p>ok, I&#039;ll have a look at the new version this evening, thank you.</p><p>I don&#039;t know what happened with the attached files. Here it is again. (edit: I know, I&#039;ve just selected the file with the browser, but forgot to click on &quot;add file&quot;)</p><p>(edit) I&#039;ve quickly tested it, tempo is ok for the &quot;bourrasque&quot; tune, but it still stops during the replay. For the other &quot;souvenirs&quot;, it doesn&#039;t stop at the beginning like before, but I haven&#039;t replayed it completely. I&#039;ll test more soon. Thanks again for the fix anyway.</p>]]></content>
			<author>
				<name><![CDATA[garvalf]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=6</uri>
			</author>
			<updated>2017-02-18T16:23:45Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1174#p1174</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1173#p1173" />
			<content type="html"><![CDATA[<p>Thanks for report, but you forgot to attach the files.</p><p>Regarding the slower tempo, no, Arduino can handle crazy speeds, that&#039;s not the issue. That&#039;s seem to be just a misimplentation of the thread sync (row counters in beeper engines may work in tricky ways). Thinking how to fix it now.</p><p><strong>Edit:</strong> made the tempo fix and replaced the test song with yours. The file attach replaced, please re-download.</p>]]></content>
			<author>
				<name><![CDATA[Shiru]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=11</uri>
			</author>
			<updated>2017-02-18T12:36:56Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1173#p1173</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Tritone on Arduino]]></title>
			<link rel="alternate" href="http://randomflux.info/1bit/viewtopic.php?pid=1172#p1172" />
			<content type="html"><![CDATA[<p>it sounds very good too (I&#039;ve only tested through an old speaker), very close to original it seems. What you did for getting the conversion is very impressive!</p><p>Yet, I&#039;ve found a few problems:</p><p>- I have a song with a very fast tempo of 19 (in the zip it&#039;s called music_data_bourrasque.h and the original from zx version can be heard there <a href="http://chipmusic.org/garvalf/music/bourrasques">http://chipmusic.org/garvalf/music/bourrasques</a> ). The arduino code doesn&#039;t handle that probably because it&#039;s too fast. The song is slowed down, with it seems some accelerations and decelerations (I guess it&#039;s not possible to fix this, which I can understand)</p><p>- on at least two of my songs, (music_data_souvenirs_tritone.h and music_data_snakecharmer.h) the arduino stops the music before the end, on the first one it&#039;s after just a few notes, on the second one it&#039;s a bit longer but not much. Probably there are some data which are confusing the engine...</p>]]></content>
			<author>
				<name><![CDATA[garvalf]]></name>
				<uri>http://randomflux.info/1bit/profile.php?id=6</uri>
			</author>
			<updated>2017-02-18T10:06:50Z</updated>
			<id>http://randomflux.info/1bit/viewtopic.php?pid=1172#p1172</id>
		</entry>
</feed>
