Jump to content
munny

Microphone data output

Recommended Posts

Hello,

I am trying to record my voice using MSP430F5438A onboard microphone. So as a starting point I am reading the microphone data(Channel 5, ADC12). I am sending the data directly to PC and observing the output at tera term. But I am confused seeing the ADC output. After a certain amount of data, the value saturates and actually doesn't change at all even if I speak or make a sound. I don't catch where I'm doing wrong. I'm attaching my code and the data output snapshot. Any suggestion is highly appreciated.  

#include <msp430.h>


unsigned int voice;
volatile unsigned char volt [5];

void init_serial (void);
void init_serial (void)
{
     P5SEL |= 0xC0;              // 5.6 and 5.7 for TX/RX- UCA1
     UCA1CTL1 |= UCSWRST;
     UCA1CTL1 |= UCSSEL_1;       //32768 Hz
     UCA1BR0 = 03;               // Baudrate 9600
     UCA1BR1 = 0x00;
     UCA1MCTL = 0x06;            // Modulation  Sx=3, Fx= 0
     UCA1CTL0 = 0x00;
     UCA1CTL1 &= ~UCSWRST;        // In operation mode

    }

void ADC_value (int);
void ADC_value (int ADC_Data)
{
    volatile char x=3;
    volt [3] = volt [2] = volt [1] = volt [0] = 0x30;
    while (ADC_Data > 0)
    {
        volt [x] = (ADC_Data%10)| 0x30;  // Separating unit digit
        ADC_Data = ADC_Data/10;          // rest of the digit than last digit
        x--;
    }
    volt [4] = '\0';
    }

void Send_Serial (void);
void Send_Serial (void)
{
    volatile char i=0;
    while (volt[i] != '\0')
    {
        UCA1TXBUF = volt[i];

        while (UCA1STAT & UCBUSY);
        i++;
    }
    UCA1TXBUF = 0x0a;
    while (UCA1STAT & UCBUSY);
    UCA1TXBUF = 0x0d;
    while (UCA1STAT & UCBUSY);

    }


int main(void)
{
    P6OUT |= BIT4;                         // microphone power
    P6OUT &= ~BIT5;                        // microphone connected at input channel 5
    P6SEL |= BIT5;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  /* Initialize the shared reference module */
  REFCTL0 |= REFMSTR + REFVSEL_0 + REFON;    // Enable internal 1.5V reference

  /* Initialize ADC12_A */
  ADC12CTL0 &= ~ADC12ENC;                                                          // Ensure ENC
  ADC12CTL0 = ADC12ON + ADC12SHT02;            // Set sample time
  ADC12CTL1 = ADC12SHP + ADC12SSEL_3;                     // Enable sample timer
  ADC12MCTL0 = ADC12INCH_5;  // ADC input ch A5 => MIC

  init_serial ();
  while (1)
  {
      ADC12CTL0 &= ~ADC12SC;
      ADC12CTL0 |= ADC12SC + ADC12ENC;
      while (ADC12CTL1 & ADC12BUSY)
      __no_operation();
      voice = ADC12MEM0;
      ADC_value (voice);
      Send_Serial ();
  }
}

User guide:

http://www.ti.com/lit/ug/slau263i/slau263i.pdf

image.png.aac6fc15cca34154ad8b724e984f9be8.png

Share this post


Link to post
Share on other sites
void ADC_value (int ADC_Data)
{
    volatile char x=3;
    volt [3] = volt [2] = volt [1] = volt [0] = 0x30;
    while (ADC_Data > 0)
    {
        volt [x] = (ADC_Data%10)| 0x30;  // Separating unit digit
        ADC_Data = ADC_Data/10;          // rest of the digit than last digit
        x--;
    }
    volt [4] = '\0';
    }

 

I' thinking this is your issue...

what happens if you pass straight ADC values to your serial output?

does it show the same thing?

Share this post


Link to post
Share on other sites
2 hours ago, jsolarski said:

void ADC_value (int ADC_Data)
{
    volatile char x=3;
    volt [3] = volt [2] = volt [1] = volt [0] = 0x30;
    while (ADC_Data > 0)
    {
        volt [x] = (ADC_Data%10)| 0x30;  // Separating unit digit
        ADC_Data = ADC_Data/10;          // rest of the digit than last digit
        x--;
    }
    volt [4] = '\0';
    }

 

I' thinking this is your issue...

what happens if you pass straight ADC values to your serial output?

does it show the same thing?

Hello,

Thank you for your response. Can you please explain what do you mean straight ADC values to serial output? How to do that? If you please explain, I can then try and confirm that it's working or not. 

Share this post


Link to post
Share on other sites

OK, i did my best with out having the device and while working so it may or may not work, but you should be able to get the idea of what I mean

#include <msp430.h>


unsigned int voice;
volatile unsigned char volt [5];
//JS edits
volatile unsigned char raw_adc_data // added global for adc data to serial


void init_serial (void);
void init_serial (void)
{
     P5SEL |= 0xC0;              // 5.6 and 5.7 for TX/RX- UCA1
     UCA1CTL1 |= UCSWRST;
     UCA1CTL1 |= UCSSEL_1;       //32768 Hz
     UCA1BR0 = 03;               // Baudrate 9600
     UCA1BR1 = 0x00;
     UCA1MCTL = 0x06;            // Modulation  Sx=3, Fx= 0
     UCA1CTL0 = 0x00;
     UCA1CTL1 &= ~UCSWRST;        // In operation mode

    }
//js edit removed for testing.
//void ADC_value (int);
//void ADC_value (int ADC_Data)
/*{
    volatile char x=3;
    volt [3] = volt [2] = volt [1] = volt [0] = 0x30;
    while (ADC_Data > 0)
    {
        volt [x] = (ADC_Data%10)| 0x30;  // Separating unit digit
        ADC_Data = ADC_Data/10;          // rest of the digit than last digit
        x--;
    }
    volt [4] = '\0';
    }*/

void Send_Serial (void);
void Send_Serial (void)
{
	//js edit removed for testing
    //volatile char i=0;
    /*while (volt[i] != '\0')
    {
        UCA1TXBUF = volt[i];

        while (UCA1STAT & UCBUSY);
        i++;
    }*/
	UCA1TXBUF = raw_adc_data;
	while (UCA1STAT & UCBUSY);
    UCA1TXBUF = 0x0a;
    while (UCA1STAT & UCBUSY);
    UCA1TXBUF = 0x0d;
    while (UCA1STAT & UCBUSY);

    }


int main(void)
{
    P6OUT |= BIT4;                         // microphone power
    P6OUT &= ~BIT5;                        // microphone connected at input channel 5
    P6SEL |= BIT5;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  /* Initialize the shared reference module */
  REFCTL0 |= REFMSTR + REFVSEL_0 + REFON;    // Enable internal 1.5V reference

  /* Initialize ADC12_A */
  ADC12CTL0 &= ~ADC12ENC;                                                          // Ensure ENC
  ADC12CTL0 = ADC12ON + ADC12SHT02;            // Set sample time
  ADC12CTL1 = ADC12SHP + ADC12SSEL_3;                     // Enable sample timer
  ADC12MCTL0 = ADC12INCH_5;  // ADC input ch A5 => MIC

  init_serial ();
  while (1)
  {
      ADC12CTL0 &= ~ADC12SC;
      ADC12CTL0 |= ADC12SC + ADC12ENC;
      while (ADC12CTL1 & ADC12BUSY)
      __no_operation();
     // voice = ADC12MEM0; js edit 
	 raw_adc_data = ADC12MEM0;
     // ADC_value (voice); js edit 
      Send_Serial ();
  }
}

 

Share this post


Link to post
Share on other sites

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...