This commit is contained in:
Jonathan Wyss 2024-03-22 23:53:40 +01:00
parent d70675b9e7
commit 6466905783
2 changed files with 35 additions and 20 deletions

49
main.c
View File

@ -1,3 +1,4 @@
#include<avr/power.h>
#include<util/delay.h>
#include<avr/io.h>
#include"fix_fft.h"
@ -29,9 +30,21 @@
//7- 880
//8- 1kHz
//
const float log_scale = 64./log(64./SCALE_FACTOR + 1.);
int msec;
ISR(TIMER1_OVF_vect)
{
if(msec<100)
{
msec++;
}
else msec=0;
}
int main (void)
{
int i,i2;
@ -42,13 +55,17 @@ int main (void)
char im[64];
char buff[64];
char temp;
float fac_r=0.5;
float fac_g=0.5;
float fac_b=1;
msec=0;
struct cRGB led_bar1[8];
//DDRB = (1<<mic);//would be setting output, default is input so no need for setting
setupADC();
setupTimer();
OSCCAL = 240;//overclock!!! to 30MHz
OSCCAL = 250;//overclock!!! to 30MHz
for(i=0;i<8;i++)
{
led_bar1[i].r=0;
@ -75,14 +92,14 @@ int main (void)
//
sum+=sample[i];//dc-bias
//while(msec==0);
//while(msec<=1);
}
avg = sum/64;//calculate bias
for(i=0;i<64;i++)
{
sample[i]-=avg;//remove bias
}
fix_fftr(sample,6,0);//im[i] is always zero
fix_fftr(sample,6,0);//im[i] is alwa§§ys zero
//####Averaging Data####
//
for(i=0;i<64;i++)
@ -104,17 +121,17 @@ int main (void)
if(sample[i]<20)
{
led_bar1[i].r=0;
led_bar1[i].g=0;
led_bar1[i].b=sample[i];
led_bar1[i].r=(char)sample[i]*fac_r;
led_bar1[i].g=(char)sample[i]*fac_g;
led_bar1[i].b=(char)sample[i]*fac_b;
}
else if(sample[i]<40)
else if(sample[i]<30)
{
led_bar1[i].r=0;
led_bar1[i].g=sample[i];
led_bar1[i].b=sample[i]/2;
}
else if(sample[i]<60)
else if(sample[i]<50)
{
led_bar1[i].r=sample[i];
led_bar1[i].g=0;
@ -133,12 +150,13 @@ int map(int value, int old_min, int old_max,int new_min, int new_max)
void setupTimer(void)
{
TCCR1 = (1<<CS13)|(1<<CS10)|(1<<CTC1); //clear timer on compare match
clock_prescale_set(0);
TCCR1 = (1<<CS10);//(1<<CS13)|(1<<CS10)|(1<<CTC1); //clear timer on compare match
GTCCR = 0; //default values should be ok
OCR1C = 117; //Compare value of timer / overflow , sets OCF1A
OCR1A = 117;
TIMSK = (1<<OCIE1A);//|(1<<TOIE1); //enable interupt compare a
TIFR = (1<<OCF1A); //flag register "aka when to interrupt
//OCR1C = 117; //Compare value of timer / overflow , sets OCF1A
//OCR1A = 117;
TIMSK |= (1<<TOIE1);//|(1<<TOIE1); //timer0 ovf
TIFR |= (1<<TOV1); //flag register "aka when to interrupt
}
/*
* 1/(30Mhz/16384) *255 = 0.139264s Time for one overflow
@ -153,8 +171,5 @@ void wait_period(void)
// TIFR |=(1<<TOV1); //clear overflow flag
}
ISR(TIMER1_COMPA_vect)
{
msec++;
}

View File

@ -10,7 +10,7 @@ FORMAT = ihex
TARGET = main
SRC = $(TARGET).c avr_adc.c fix_fft.c light_ws2812_AVR/Light_WS2812/light_ws2812.c
ASRC =
OPT = s
OPT = 0
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
@ -28,7 +28,7 @@ DEBUG = stabs
CSTANDARD = -std=gnu99
# Place -D or -U options here
CDEFS = -DF_CPU=30000000UL
CDEFS = -D F_CPU=32000000UL
# Place -I options here
CINCS =