Jump to content
43oh

Audio Spectrum Analyzer


Recommended Posts

  • 2 weeks later...

Here's the code:

 

#include "msp430g2553.h"

#define DATAPIN BIT6
#define CLOCKPIN BIT5
#define LATCHPIN BIT0
#define EQ_DC_IN_PIN BIT4 // P1.4
#define EQ_RESET_PIN BIT6 // P2.6
#define EQ_STROBE_PIN BIT7 // P2.7

void setUp();

unsigned char timerCounter = 0;
unsigned char column = 0;
unsigned char txData = 0;
unsigned char txCounter = 0;
unsigned char eqCounter = 0;
unsigned char eqCtrl = 0;

unsigned const char columnSelector[8] = {
                                           0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
                                       };

unsigned int data[8] = {0,0,0,0,0,0,0,0};

void main(void) {

   setUp();

   __bis_SR_register(GIE);				// enable global

   while(1) {							// main loop

       column = (timerCounter >> 4) & 0x07;
       txData = columnSelector[column];
       txCounter = 0;

       while(txCounter < 8) {
           (txData & BIT7) ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN);
           txData <<= 1;
           P1OUT |= CLOCKPIN;
           P1OUT &= ~CLOCKPIN;
           txCounter++;
       }

       txData = data[column];
       txCounter = 16;

       while(txCounter > 0) {
           (txCounter <= txData)? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN);
           P1OUT |= CLOCKPIN;
           P1OUT &= ~CLOCKPIN;
           txCounter--;
       }

       P1OUT &= ~LATCHPIN;                     // Latch data
       P1OUT |= LATCHPIN;

       __bis_SR_register(LPM0_bits);	// go to sleep and wait for the timer
   }
}

#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer1_A0 (void) {
   eqCtrl = (eqCounter >> 2) & 0x07;
   if(eqCtrl == 0) {
       if(eqCounter == 0) {
           P2OUT |= EQ_RESET_PIN;
           P2OUT &= ~EQ_RESET_PIN;
           eqCounter += 4;
       }
   } else if((eqCounter & 0x03) == 3) {
       ADC10CTL0 |= ENC + ADC10SC;
   } else if(eqCounter & 0x01) {
       P2OUT |= EQ_STROBE_PIN;
   } else if(eqCounter & 0x02) {
       P2OUT &= ~EQ_STROBE_PIN;
   }
   eqCounter++;
   timerCounter++;

   if((timerCounter & 0xF) == 0) {
       __bic_SR_register_on_exit(LPM0_bits);
   }
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) {
   data[eqCtrl-1] = (ADC10MEM >> 6) & 0x0F;
}

void setUp() {

   WDTCTL = WDTPW + WDTHOLD;			// disable WDT
   BCSCTL1 = CALBC1_8MHZ;				// 8MHz clock
   DCOCTL = CALDCO_8MHZ;

   P1OUT |= LATCHPIN;
   P1DIR |= LATCHPIN + CLOCKPIN + DATAPIN;

   P2SEL &= ~(BIT6|BIT7);				// port 2 all out
   P2OUT = 0;
   P2DIR = 0xFF;

   TA1CCR0 = 576;						// 576/72us
   TA1CTL = TASSEL_2 + MC_1;			// SMCLK, upmode
   TA1CCTL0 = CCIE;

   ADC10CTL1 = INCH_4;
   ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE;
}

 

post-197-135135508696_thumb.jpg

Link to post
Share on other sites
  • 6 months later...

from what i understand, most msp430s have a 10bit ADC, which means the input values would vary anywhere from 0-1023 (1024 values)... not sure if there are 14 or even 16 channel eq chips, but do you think it would be effective to interpolate additional "frequencies" into the 7 channels you get from the chip?

 

example would be 1st freq = 430, 2nd freq = 887, (430+887)/2 would equal 658. that could be an interpolated value between the 1st and 2nd frequencies, right?

 

that way you could have 7 true values with 6 interpolated values, giving you a total of 13 frequencies to represent. thoughts? i'm new to the whole msp thing and it's tough to do all the stuff i want to when midterms are going on X(

 

thanks in advance for any responses :D

Link to post
Share on other sites
from what i understand, most msp430s have a 10bit ADC, which means the input values would vary anywhere from 0-1023 (1024 values)

Yes, I am dividing 10 bit value by 64 to get 4 bit value.

 

... not sure if there are 14 or even 16 channel eq chips, but do you think it would be effective to interpolate additional "frequencies" into the 7 channels you get from the chip?

example would be 1st freq = 430, 2nd freq = 887, (430+887)/2 would equal 658. that could be an interpolated value between the 1st and 2nd frequencies, right?

that way you could have 7 true values with 6 interpolated values, giving you a total of 13 frequencies to represent. thoughts? i'm new to the whole msp thing and it's tough to do all the stuff i want to when midterms are going on X

This is pretty much what I am doing in my 10 ch light controller, but instead of interpolating 2 consecutive channels, I am mixing them up, for example ch1 and ch4, ch2 and ch7. This way I get more varied results.

Link to post
Share on other sites
  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...