Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

125 lines (101 sloc) 4.569 kB
// DueVGA Waterfall by stimmer
// ATTENTION - you will need to alter your Arduino IDE to link with libarm_cortexM3l_math.a
// see the README for how to do this
// Input: Audio signal on Analog In A0
#define ARM_MATH_CM3
#include <arm_math.h>
#include <VGA.h>
static int samprate = 4267;
const byte cmap[]={0b00000000,0b00000001,0b00000010,
0b00000011,0b00100011,
0b01000011,0b01100011,0b10000011,0b10100011,0b11000011,0b11100011,0b11100010,0b11100001,0b11100000
,0b11100100,0b11101000,0b11101100,0b11110000,0b11110100,0b11111000,0b11111100,
0b11011100,0b10111100,0b10011100,0b01111100,0b01011100,0b00111100,0b00011100,0b00011101,0b00011110,
0b00011111,0b00111111,0b01011111,0b01111111,0b10011111,0b10111111,0b11011111,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};
arm_cfft_radix4_instance_q15 C;
arm_rfft_instance_q15 S;
volatile int bufn,obufn;
uint16_t buf[5][128];
q15_t out[640];
q15_t outsq[1280];
void ADC_Handler(){
int f=ADC->ADC_ISR;
if (f&(1<<27)){
bufn=(bufn+1);if(bufn==5)bufn=0;
ADC->ADC_RNPR=(uint32_t)buf[bufn];
ADC->ADC_RNCR=128;
}
}
void setup(){
VGA.begin(316,200,VGA_COLOUR);
VGA.fillRect(0,0,319,199,3);
pmc_enable_periph_clk(ID_ADC);
adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);
ADC->ADC_MR |=0x3;
ADC->ADC_CHER=0x80;
NVIC_EnableIRQ(ADC_IRQn);
ADC->ADC_IDR=~(1<<27);
ADC->ADC_IER=1<<27;
ADC->ADC_RPR=(uint32_t)buf[0];
ADC->ADC_RCR=128;
ADC->ADC_RNPR=(uint32_t)buf[1];
ADC->ADC_RNCR=128;
bufn=obufn=1;
ADC->ADC_PTCR=1;
ADC->ADC_CR=2;
NVIC_SetPriority(ADC_IRQn,6);
pinMode(2,OUTPUT); // port B pin 25
analogWrite(2,255); // sets up some other registers I haven't worked out yet
REG_PIOB_PDR = 1<<25; // disable PIO, enable peripheral
REG_PIOB_ABSR= 1<<25; // select peripheral B
REG_TC0_CMR0=0b00000000000010011100010000000000;
REG_TC0_RC0=42000000/samprate;
REG_TC0_RA0=1;
REG_TC0_CCR0=0b101;
VGA.drawText("DueVGA Waterfall",96,4,255);
VGA.drawLine(40,176,40,179,255);
VGA.drawLine(99,176,99,179,255);
VGA.drawLine(159,176,159,179,255);
VGA.drawLine(219,176,219,179,255);
VGA.drawLine(279,176,279,179,255);
char s[10];
sprintf(s,"%d",(samprate/2)/256);
VGA.drawText(s,36,181,255);
sprintf(s,"%d",(60*samprate/2)/256);
VGA.drawText(s,88,181,255);
sprintf(s,"%d",(120*samprate/2)/256);
VGA.drawText(s,144,181,255);
sprintf(s,"%d",(180*samprate/2)/256);
VGA.drawText(s,206,181,255);
sprintf(s,"%d",(240*samprate/2)/256);
VGA.drawText(s,264,181,255);
VGA.drawText("Frequency (Hz)",104,190,255);
arm_rfft_init_q15(&S,&C,512,false,true);
}
int nn=0;
void loop(){
while(obufn==bufn);
obufn=bufn;
int bb=bufn+1;if(bb==5)bb=0;
uint16_t *q=buf[0]+128*bb;
for(int j=0;j<512;j++){
int t=(*q++)-2048;
if(q==(buf[0]+640))q=buf[0];
out[j]=t<<4;
}
arm_rfft_q15(&S,out,outsq);
arm_cmplx_mag_squared_q15(outsq,out,256);
for(int i=0;i<240;i++) {VGA.drawPixel(i+40,175,(cmap[out[1+(i)]&0xff]));}
VGA.waitSync();
VGA.scroll(40,16,240,160,0,-1);
//VGA.waitSync();
}
Jump to Line
Something went wrong with that request. Please try again.