Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switched to Timer2: working visualization.

  • Loading branch information...
commit 8cb19f33ebc2c2707a419569543fb98267318298 1 parent 6b8c385
Fabio Pugliese Ornellas authored
Showing with 103 additions and 50 deletions.
  1. +43 −0 timerTest/pins.h
  2. +60 −50 timerTest/timerTest.ino
43 timerTest/pins.h
View
@@ -0,0 +1,43 @@
+// Outdoor temperature (DS18B20)
+#define PIN_DS18B20 2
+
+// Multiplexer (CD74HC4067)
+#define PIN_CD74HC4067_SIG_A A0
+#define PIN_CD74HC4067_SIG_D 14
+#define PIN_CD74HC4067_S0 6
+#define PIN_CD74HC4067_S1 7
+#define PIN_CD74HC4067_S2 8
+#define PIN_CD74HC4067_S3 9
+
+// Photoresistor
+#define ADDR_PHOTORESISTOR_RED 0
+#define ADDR_PHOTORESISTOR_GREEN 1
+#define ADDR_PHOTORESISTOR_BLUE 2
+#define ADDR_PHOTORESISTOR 3
+
+// Humidity )HIH-4030)
+#define PIN_HIH4030 A3
+
+// Mic
+#define ADDR_MIC 4
+
+// Line In
+#define PIN_LINEIN A1
+
+// Buttons
+#define ADDR_BUTTON_MODE 9
+#define ADDR_BUTTON_A 8
+#define ADDR_BUTTON_B 6
+#define ADDR_BUTTON_C 7
+
+// Sparkfun RGB LED Matrix
+#define PIN_MATRIX_SS 3
+
+// Ethernet
+#define PIN_ETHERNET_SS 10
+
+// uSD
+#define PIN_USD_SS 4
+
+// Buzzer
+#define PIN_BUZZER 5
110 timerTest/timerTest.ino
View
@@ -1,7 +1,8 @@
#include <fixFFT.h>
+#include <SPI.h>
+#include <SFRGBLEDMatrix.h>
-#define PIN_LINEIN_L A1
-#define PIN_LINEIN_R A2
+#include "pins.h"
#define LOG2_SAMPLES 6
#define SAMPLES_COUNT (1<<LOG2_SAMPLES)
@@ -10,18 +11,19 @@ volatile word lost=0;
volatile byte count=0;
volatile int16_t samples[SAMPLES_COUNT];
-ISR(TIMER1_COMPA_vect){
+SFRGBLEDMatrix *display;
+
+ISR(TIMER2_COMPA_vect){
if(SAMPLES_COUNT==count) {
lost++;
}
else{
- int16_t b;
+ int16_t buff;
// wait convertion end
while(!(ADCSRA & (1<<ADIF)));
// read sample
- // samples[count++]=ADCH;
- b=ADCH;
- samples[count++]=b-128;
+ buff=ADC;
+ samples[count++]=(buff-512);
// clear bit
ADCSRA|=(1<<ADIF);
// start next convertion
@@ -29,31 +31,21 @@ ISR(TIMER1_COMPA_vect){
}
}
-void
-setup(){
- Serial.begin(115200);
- // 16-bit Timer/Counter1
- // 20kHz sampling (must be double of max mic freq)
-
- TCCR1A=0;
- // - Clear Timer on Compare Match (CTC) Mode
- // - 16MHz / 8x prescaling = 2MHz
- TCCR1B=(1<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10);
- TCCR1C=0;
- // - Compare
- // 100=22kHz
- // 45 = 44444.444kHz
- OCR1A=100;
- // - Enable compare interrupt
- TIMSK1=(1<<OCIE1A);
- TIFR1=0;
-
- // Analog-to-Digital Converter
+void setup(){
+ Serial.begin(115200);
+ SPI.begin();
+ display=new SFRGBLEDMatrix(PIN_MATRIX_SS, 3, 2);
+ display->fill(BLACK);
+ display->show();
+
+ //
+ // ADC Setup
+ //
// - AVCC with external capacitor at AREF pin
// - ADC Left Adjust Result
// - Analog Channel Selection
- ADMUX=(1<<REFS0)|(1<<ADLAR)|((PIN_LINEIN_L-14)&0x07);
+ ADMUX=(1<<REFS0)|(0<<ADLAR)|((PIN_LINEIN-14)&0x07);
// - ADC Enable
// - ADC Start Conversion
// - Clear ADIF
@@ -61,33 +53,57 @@ setup(){
// - Max 1 0 1 (32)
// - Min 0 1 0 (4) < more high freq noise
ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADIF)|(1<<ADPS2)|(0<<ADPS1)|(1<<ADPS0);
-
// discart first (slow) sample
while(!(ADCSRA & (1<<ADIF)));
ADCSRA|=(1<<ADIF);
- ADCSRA|=(1<<ADSC);
- // enable interrupts
- sei();
+ //
+ // Timer2 @40kHz
+ //
- Serial.println("==Boot complete==");
+ TCCR2A=(1<<WGM21);
+ TCCR2B=(1<<CS21);
+ OCR2A=50;
+ TIFR2=0;
+ ASSR=0;
+ GTCCR=0;
+
+ //
+ // Start ADC capture and Timer2 Interrupt
+ //
+ ADCSRA|=(1<<ADSC);
+ TIMSK2=(1<<OCIE2A);
}
-void
-loop(){
+void loop(){
int16_t freq[SAMPLES_COUNT/2];
- // convertion finished
+
+ // All samples acquired
if(SAMPLES_COUNT==count){
- // process
- Serial.println("==RAW==");
- for(byte c=0;c<SAMPLES_COUNT;c++)
- Serial.println(samples[c]);
+ // Serial.println("==RAW==");
+ // for(byte c=0;c<SAMPLES_COUNT;c++)
+ // Serial.println(samples[c]);
+ // FFT
fft((int16_t *)samples, freq, LOG2_SAMPLES);
- Serial.println("==FFT==");
- for(byte c=0;c<SAMPLES_COUNT/2;c++)
- Serial.println(freq[c]);
+ // Serial.println("==FFT==");
+ // for(byte c=0;c<SAMPLES_COUNT/2;c++){
+ // Serial.print(freq[c]);
+ // Serial.print(' ');
+ // }
+ // Serial.println("");
+
+ // Draw
+ for(byte x=0;x<display->width;x++){
+ for(byte y=0;y<display->height;y++){
+ if(display->height-y<freq[x])
+ display->paintPixel(RGB(0,0,1), x, y);
+ else
+ display->paintPixel(BLACK, x, y);
+ }
+ }
+ display->show();
// start next convertion
ADCSRA|=(1<<ADSC);
@@ -97,7 +113,7 @@ loop(){
lost=0;
// reset counter
count=0;
- delay(10000);
+ // delay(10000);
}
}
@@ -106,9 +122,3 @@ loop(){
-
-
-
-
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.