目前使用msp430f5438a,只是當我的硬體電路輸出是0V的狀態下,經過晶片AD轉換,以及正規化後的數值都會在0.3~0.5之間飄動
想請問各位,是否我的ADC轉換有哪邊沒設定好
//******************************************************************************
// MSP430F543xA Demo – USCI_A0, 115200 UART Echo ISR, DCO SMCLK
//
// Description: Echo a received character, RX ISR used. Normal mode is LPM0.
// USCI_A0 RX interrupt triggers TX Echo.
// Baud rate divider with 1048576hz = 1048576/115200 = ~9.1 (009h|01h)
// ACLK = REFO = ~32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
// See User Guide for baud rate divider table
//
// MSP430F5438A
// —————–
// /|\| |
// | | |
// –|RST |
// | |
// | P3.4/UCA0TXD|————>
// | | 115200 – 8N1
// | P3.5/UCA0RXD|<—— ——
//
// M. Morales
// Texas Instruments Inc.
// June 2009
// Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B
//******************************************************************************
#include "msp430x54xA.h"
int A0results[14];
/* 埠數據緩衝區 */
unsigned char Rx_Buffer[1460]; /* 埠接收資料緩衝區 */
unsigned char Tx_Buffer[1460]; /* 埠發送資料緩衝區 */
void Sensor_AD(void);
void Coder_AD(void);
/******************************************************************
取AD值
******************************************************************/
void Sensor_AD(void)
{
int i,j,k1,k2,ork;
k1=0x00 ;
k2=0x00 ;
P1OUT = 0x00 ;
ork = 0x00 ;
//P4OUT |= BIT0; //test LED
for (i=0;i<=7;i+=7)
{
for (j=0;j<7;j++)
{
k1 = i/7;
k2 = j;
ork = k2|(k1<<4);
P1OUT = ork;
__delay_cycles(5);
ADC12CTL0 |= ADC12SC; // Start conversion
while (!(ADC12IFG & BIT0));
__no_operation(); // SET BREAKPOINT HERE
//if (ADC12MEM0<900)
//{
A0results[i+j] = ADC12MEM0;
//}
//else
//{
//A0results[i+j] = ADC12MEM0-900;
//}
P1OUT = 0x00;
}
k1 = 0;
}
k2 = 0;
//P4OUT &= 0x00; //test LED
UCA0CTL1 |=0x01;
UCA0CTL1 &= ~UCSWRST;
Coder_AD();
}
/******************************************************************
編碼
******************************************************************/
void Coder_AD(void)
{
//P4OUT |= BIT0; //test LED
int i,t;
t = 0;
for(i=0;i<14;i++)
{
Tx_Buffer[i+t+2] = (A0results[i] >> 8);
Tx_Buffer[i+t+3] = (A0results[i] & 0x00FF);
t++;
}
//P4OUT &= 0x00; //test LED
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 6; // 1MHz 9600 (see User's Guide)
UCA0BR1 = 0; // 1MHz 9600
//UCA0MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA0MCTL = UCBRS_0 + UCBRF_13 + UCOS16; // Modln UCBRSx=0, UCBRFx=0,
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= 0x01; // Enable USCI_A0 RX interrupt
//AD converter
P6SEL |= BIT0; // Enable A/D channel A0
/* Initialize REF module */
// Enable 2.5V shared reference, disable temperature sensor to save power
REFCTL0 |= REFMSTR+REFVSEL_2+REFON+REFTCOFF;
/* Initialize ADC12 */
ADC12CTL0 = ADC12ON+ADC12SHT02; // Turn on ADC12, set sampling time
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12MCTL0 = ADC12SREF_1; // Vr+=Vref+ and Vr-=AVss
__delay_cycles(75); // 75 us delay @ ~1MHz
ADC12CTL0 |= ADC12ENC;
//I/O PORT set
P1DIR |= 0xFF; //Set P1 to output direction
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
__no_operation(); // For debugger
}
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,4))
{
case 0:break; // Vector 0 – no interrupt
case 2:
UCA0IE |= 0x01;
UCA0CTL1 |=0x01;
UCA0CTL1 &= ~UCSWRST;
// Vector 2 – RXIFG
while(1)
{
Sensor_AD();
Tx_Buffer[0] = 0x00;
Tx_Buffer[1] = 0xFF;
int i;
for(i=0;i<30;i++)
{
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = Tx_Buffer[i];
}
}
break;
case 4:break; // Vector 4 – TXIFG
default: break;
}
}
灰小子:
你采集的是什么信号?外部电路是怎么样的?
Liang KAI MIN:
回复 灰小子:
您好
我是採集壓力感測器FSR406訊號
外部電路使用儀表放大器做放大和慧思登電喬做電組電壓轉換
Butterfly:
回复 Liang KAI MIN:
给你个内部2.5V电压基准的ADC单次转换代码,输入信号在P6.0/A0口,0-2.5V。
ADC转换结果在ADC12寄存器ADC12MEM0下面,先排除硬件问题
// MSP430F543xA// —————–// /|\| |// | | |// –|RST |// | |// Vin –>|P6.0/A0 |// | |
//// M. Morales// Texas Instruments Inc.// June 2009// Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B//******************************************************************************
#include <msp430.h>
int main(void){ WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer P6SEL |= BIT0; // Enable A/D channel A0 /* Initialize REF module */ // Enable 2.5V shared reference, disable temperature sensor to save power REFCTL0 |= REFMSTR+REFVSEL_2+REFON+REFTCOFF; /* Initialize ADC12 */ ADC12CTL0 = ADC12ON+ADC12SHT02; // Turn on ADC12, set sampling time ADC12CTL1 = ADC12SHP; // Use sampling timer ADC12MCTL0 = ADC12SREF_1; // Vr+=Vref+ and Vr-=AVss
__delay_cycles(75); // 75 us delay @ ~1MHz
ADC12CTL0 |= ADC12ENC; // Enable conversions
while (1) { ADC12CTL0 |= ADC12SC; // Start conversion while (!(ADC12IFG & BIT0)); __no_operation(); // SET BREAKPOINT HERE }}