<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Throbbing LED maple R5</title>
		<link>http://forums.leaflabs.com/topic.php?id=13139</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:17:35 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=13139" rel="self" type="application/rss+xml" />

		<item>
			<title>pyrohaz on "Throbbing LED maple R5"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13139#post-28312</link>
			<pubDate>Tue, 06 Aug 2013 15:10:56 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">28312@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Well! Sorry for the late reply.&#60;/p&#62;
&#60;p&#62;I've finally had the opportunity to test out this code and can safely say that its fully working! By decimating each bin from 8 bit down to 3 bit, then shifting up 5 bits and subtracting 1 (ensuring that 0 bins are 0 with a simple if), I have made a graphic analyzer! Its really interesting to learn about this sorta stuff, so now i've done a standard fourier transform, whats next within the field of frequency domain transformation?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "Throbbing LED maple R5"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13139#post-28138</link>
			<pubDate>Tue, 30 Jul 2013 08:36:54 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">28138@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;There are some problems here that results in the throbbig error light, that is probably caused by array indices gone haywire.&#60;/p&#62;
&#60;p&#62;First you must initialise your loop variables.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;for(int WaveWrite; WaveWrite&#38;lt;256; WaveWrite++){&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;should be&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;for(int WaveWrite = 0; WaveWrite&#38;lt;256; WaveWrite++){&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The delay of 1000 after starting the sample timer results in the program trying to read 18000 samples, overflowing available RAM and crashing. The NextSamples flag alone is not a reliable way to stop sampling after exact 256 samples, there is no way to be sure that&#60;br /&#62;
this flag is cleared without delay after the 256'th sample has been read. The main loop can be busy waiting for the I/O buffers to clear. Instead set NextSamples to 0 in the sampling interrupt after the last sample has been read.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void Sampling(){
  //Samples done here
  if(NextSamples==1){
    SampleRead = (analogRead(0) - MidP)&#38;gt;&#38;gt;4; //Sample and subtract midpoint(constant), shift to 8 bit range
    Sample[SampCount] = SampleRead; //Store samples in array
    SampCount++; //Increment sample counter
    if (SampCount&#38;lt;=256) NextSamples = 0; //Stop sampling until buffer handled by loop()
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Another method is to stop the timer in the sampling interrupt after the last sample, and restart it when the FT has been calculated.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "Throbbing LED maple R5"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13139#post-28137</link>
			<pubDate>Tue, 30 Jul 2013 08:27:20 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">28137@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You should change&#60;br /&#62;
if(NextSamples==1){&#60;br /&#62;
to&#60;br /&#62;
if(SampCount&#38;lt;256){&#60;br /&#62;
Otherwise you will overwrite your sample array in the main loop is not fast enough.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pyrohaz on "Throbbing LED maple R5"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13139#post-28105</link>
			<pubDate>Mon, 29 Jul 2013 21:01:48 +0000</pubDate>
			<dc:creator>pyrohaz</dc:creator>
			<guid isPermaLink="false">28105@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey guys,&#60;/p&#62;
&#60;p&#62;I've got a new project:&#60;/p&#62;
&#60;p&#62;I recently received another 8x8 matrix LED display, powered by the Maxim MAX7219 chip, it works fine with the LED control library.&#60;/p&#62;
&#60;p&#62;What i'm having a go at is a really simple graphic equalizer. Now I don't actually do any formal studying of electronics or mathematics so please bare with my lack of ability!&#60;/p&#62;
&#60;p&#62;I know of the fourier transform so i'm merely going off my knowledge of that and i've written this code:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
#include &#38;lt;math.h&#38;gt;&#60;/p&#62;
&#60;p&#62;volatile int16 Sample[256], SampleRead, SampCount;&#60;br /&#62;
int16 Wa1[256], Wa2[256], Wa3[256], Wa4[256], Wa5[256], Wa6[256], Wa7[256], Wa8[256];&#60;br /&#62;
int16 MidP, NextSamples = 1;&#60;br /&#62;
double SineD = 0;&#60;br /&#62;
byte Fv = 127;&#60;br /&#62;
int16 Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8;&#60;/p&#62;
&#60;p&#62;HardwareTimer SampleTimer(2);&#60;/p&#62;
&#60;p&#62;void setup(){&#60;br /&#62;
  SerialUSB.begin();&#60;br /&#62;
  SampleTimer.pause();&#60;/p&#62;
&#60;p&#62;  //Create Sine wave arrays&#60;br /&#62;
  for(int WaveWrite; WaveWrite&#38;lt;256; WaveWrite++){&#60;br /&#62;
    Wa1[WaveWrite] = 127*sin(SineD); //~70Hz&#60;br /&#62;
    Wa2[WaveWrite] = 127*sin(SineD*2); //~141Hz&#60;br /&#62;
    Wa3[WaveWrite] = 127*sin(SineD*4); //~281Hz&#60;br /&#62;
    Wa4[WaveWrite] = 127*sin(SineD*8); //~563Hz&#60;br /&#62;
    Wa5[WaveWrite] = 127*sin(SineD*16); //1125Hz&#60;br /&#62;
    Wa6[WaveWrite] = 127*sin(SineD*32); //2250Hz&#60;br /&#62;
    Wa7[WaveWrite] = 127*sin(SineD*64); //4500Hz&#60;br /&#62;
    Wa8[WaveWrite] = Fv; //9000Hz&#60;br /&#62;
    SineD+=0.024544;&#60;br /&#62;
    Fv*=-1;&#60;br /&#62;
  }&#60;/p&#62;
&#60;p&#62;  pinMode(0, INPUT_ANALOG); //Analog Input (mid biased 2x 1k resistors)&#60;/p&#62;
&#60;p&#62;  adc_set_sample_rate(ADC1, ADC_SMPR_1_5); //Fastest sampling rate&#60;/p&#62;
&#60;p&#62;  //Sample rate of 18KHz&#60;br /&#62;
  SampleTimer.setPrescaleFactor(1);&#60;br /&#62;
  SampleTimer.setOverflow(3999);&#60;br /&#62;
  SampleTimer.setChannel1Mode(TIMER_OUTPUT_COMPARE);&#60;br /&#62;
  SampleTimer.setCompare(TIMER_CH1, 1);&#60;br /&#62;
  SampleTimer.attachCompare1Interrupt(Sampling);&#60;br /&#62;
  SampleTimer.refresh();&#60;br /&#62;
  SampleTimer.resume();&#60;/p&#62;
&#60;p&#62;  delay(1000);&#60;br /&#62;
  MidP = analogRead(0); //Find mid point of circuit, no audio applied&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;void loop(){&#60;/p&#62;
&#60;p&#62;  if(SampCount&#38;gt;=255){&#60;br /&#62;
    NextSamples = 0; //Stop more samples being processor&#60;/p&#62;
&#60;p&#62;    //Compute FT, multiply all sine tables by samples and sum to store in bin(s)&#60;br /&#62;
    for(int FT = 0; FT&#38;lt;256; FT++){&#60;br /&#62;
      Bin1 += (Sample[FT]*Wa1[FT]);&#60;br /&#62;
      Bin2 += (Sample[FT]*Wa2[FT]);&#60;br /&#62;
      Bin3 += (Sample[FT]*Wa3[FT]);&#60;br /&#62;
      Bin4 += (Sample[FT]*Wa4[FT]);&#60;br /&#62;
      Bin5 += (Sample[FT]*Wa5[FT]);&#60;br /&#62;
      Bin6 += (Sample[FT]*Wa6[FT]);&#60;br /&#62;
      Bin7 += (Sample[FT]*Wa7[FT]);&#60;br /&#62;
      Bin8 += (Sample[FT]*Wa8[FT]);&#60;br /&#62;
    }&#60;/p&#62;
&#60;p&#62;    //Magnitude of bins, shift to 8bit range&#60;br /&#62;
    Bin1 = (abs(Bin1))&#38;gt;&#38;gt;7;&#60;br /&#62;
    Bin2 = (abs(Bin2))&#38;gt;&#38;gt;7;&#60;br /&#62;
    Bin3 = (abs(Bin3))&#38;gt;&#38;gt;7;&#60;br /&#62;
    Bin4 = (abs(Bin4))&#38;gt;&#38;gt;7;&#60;br /&#62;
    Bin5 = (abs(Bin5))&#38;gt;&#38;gt;7;&#60;br /&#62;
    Bin6 = (abs(Bin6))&#38;gt;&#38;gt;7;&#60;br /&#62;
    Bin7 = (abs(Bin7))&#38;gt;&#38;gt;7;&#60;br /&#62;
    Bin8 = (abs(Bin8))&#38;gt;&#38;gt;7;&#60;/p&#62;
&#60;p&#62;    SampCount = 0; //Reset sample counter&#60;br /&#62;
    NextSamples = 1; //Start next set of samples&#60;br /&#62;
  }&#60;br /&#62;
  else{&#60;br /&#62;
    //While the FT isn't being calculated, print bins, debug only&#60;br /&#62;
    SerialUSB.print(Bin1);&#60;br /&#62;
    SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
    SerialUSB.print(Bin2);&#60;br /&#62;
    SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
    SerialUSB.print(Bin3);&#60;br /&#62;
    SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
    SerialUSB.print(Bin4);&#60;br /&#62;
    SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
    SerialUSB.print(Bin5);&#60;br /&#62;
    SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
    SerialUSB.print(Bin6);&#60;br /&#62;
    SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
    SerialUSB.print(Bin7);&#60;br /&#62;
    SerialUSB.print(&#34;  &#34;);&#60;br /&#62;
    SerialUSB.println(Bin8);&#60;br /&#62;
  }&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void Sampling(){&#60;br /&#62;
  //Samples done here&#60;br /&#62;
  if(NextSamples==1){&#60;br /&#62;
    SampleRead = (analogRead(0) - MidP)&#38;gt;&#38;gt;4; //Sample and subtract midpoint(constant), shift to 8 bit range&#60;br /&#62;
    Sample[SampCount] = SampleRead; //Store samples in array&#60;br /&#62;
    SampCount++; //Increment sample counter&#60;br /&#62;
  }&#60;br /&#62;
}&#60;br /&#62;
&#60;/code&#62;&#60;code&#62;&#60;/p&#62;
&#60;p&#62;As you can see, its creating 8 sine wave arrays of different frequencies in the setup and once a full 256 array of samples has been done, carrying out a real only fourier transform on the sample array (no phase).&#60;/p&#62;
&#60;p&#62;What I then want to do with the 8 bins is convert them into 3 bit values to then be used to drive my graphic LED.&#60;/p&#62;
&#60;p&#62;The only problem i'm having is when I upload this code, the LED on my maple just throbs at me and it doesn't want to do anything. What seems to be wrong with my code and how can I fix it? I've tried replacing the &#34;next samples&#34; section for timer pause and refresh/resume but this still caused the throbbing LED problem. My maple still works as I can upload the blink program successfully.&#60;/p&#62;
&#60;p&#62;Thanks,&#60;br /&#62;
Harris&#60;/code&#62;
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
