各位大神,我用信号源产生一个2kHz的正弦波信号,幅度1v,然会通过MSP430G2553的ADC10来采集信号,再将采集到数据通过UART发送到matlab中进行波形的还原,但是还原出来的信号总是会有毛刺(有时候也正常)。请问这是我程序哪里出问题了嘛?(信号源产生的信号是准确的,已经测试过了)。
下图为两种出现毛刺的情况
正常现象
#include <msp430.h>
#include "stdint.h"
#define nn 100;
uint16_t adcbuff[100] = {0};
uint8_t combuff[20]={0};
uint8_t iscomend =0 ;
/**
* main.c
*/
void InitSystemClock(void)
{
DCOCTL = CALDCO_16MHZ;
BCSCTL1 = CALBC1_16MHZ;
BCSCTL2 &= ~SELS;
BCSCTL2 &= ~(DIVS0 | DIVS1);
}
void InitUART(void)
{
UCA0CTL1 |= UCSWRST;
UCA0CTL0 &= ~(UCMODE1 | UCMODE0);
UCA0CTL0 &= ~UCSYNC;
UCA0CTL1 |= (UCSSEL1 | UCSSEL0);
UCA0BR0=0x82;
UCA0BR1=0x06;
UCA0MCTL |= (UCBRS1| UCBRS2);
P1SEL |= BIT1 + BIT2;
P1SEL2 |= BIT1 + BIT2;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE;
IFG2 &= ~UCA0RXIFG ;
}
void InitADCTrigByTimerA(void)
{
ADC10CTL1 |= ADC10SSEL_2;
ADC10CTL1 |= SHS0;
ADC10CTL1 |= CONSEQ1;
ADC10CTL0 |= SREF_1;
ADC10CTL0 |= ADC10SHT_1;
ADC10CTL0 &= ~ADC10SR;
ADC10CTL0 |= REF2_5V;
ADC10CTL0 |= REFON;
ADC10CTL1 |= INCH_4;
ADC10AE0 |= 1 << 4;
ADC10DTC0 |= ADC10CT;
ADC10SA = (uint16_t)(adcbuff);
ADC10CTL0 |= ADC10ON;
ADC10CTL0 |= ENC;
}
void InitTimerA()
{
TA0CTL |=TASSEL1;
TA0CTL |= MC0;
TA0CCR0 =0x004F;
TA0CCR1= 0x002F;
TA0CCTL0 &= ~CAP;
TA0CCTL1 &= ~CAP;
TA0CCTL1 |= OUTMOD_6;
P1SEL |= BIT6;
P1DIR |= BIT6;
}
int main(void)
{
uint16_t cnt = 0;
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
InitSystemClock();
InitUART();
InitADCTrigByTimerA();
InitTimerA();
__bis_SR_register(GIE);
while(1)
{
if(iscomend)
{
iscomend =0;
for(cnt = 0; cnt<100;cnt ++)
{
while(UCA0STAT & UCBUSY);
UCA0TXBUF=*(adcbuff+cnt)/256;
__delay_cycles(30000);
while(UCA0STAT & UCBUSY);
UCA0TXBUF=*(adcbuff+cnt)%256;
__delay_cycles(30000);
}
}
}
return 0;
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void UART_Receive_ISR(void)
{
static uint8_t cnt2 = 0;
if(IFG2 & UCA0RXIFG)
{
IFG2 &= ~UCA0RXIFG;
combuff[cnt2++] = UCA0RXBUF;
cnt2 %= 20;
if(combuff[cnt2 - 1] == '#')
{
cnt2 = 0;
iscomend = 1;
}
}
}