Post Go back to editing

Aduc7061的ADC数据不正确

用的ADC1的4通道,看着例程写的,基本没什么改变,但是读出来的数据貌似是垃圾数。我也试了主ADC,也不行,是我的程序那个地方需要注意吗??信号电压是0.22V,读出来的数据总是

808117左右,用的片内基准。我就是对地短路这个数也不会变化。其它串口定时器什么的程序都没问题,就这个ADC很奇怪。大佬们有类似的问题吗?用的keil5。

#include "main.h"

unsigned int runtime = 0;
unsigned char newADCdata;


#include <aduc7061.h>
int main(void)
{
/******************修改,以p0.4,ir为例*******************/
newADCdata = 0;
runtime = 0;
POWKEY1 = 0x1;
POWCON0 = 0x78; // Set core to max CPU speed of 10.24Mhz
POWKEY2 = 0xF4;

GP0DAT = BIT17+BIT25+BIT28;//DAT功能设置,比如输入输出,24~31位配置
GP0SET = BIT16; //GPxSET为端口x的数据设置寄存器

// Initilize Timer 1 in Periodic mode with timeout period of 1 Second

T1LD = 0x2800; //10240 1ms
T1CON = 0x6C0; // 110 1100 0000,Periodic mode, enable timer, 10.24M clock/1,增

IRQCONE = BIT1; // Rising edge
FIQEN = BIT4 + BIT13; // Enable Timer 1 IRQ
UARTInit();
IRQEN = BIT11; // Enable UART interrupt


// Configure ADC1 for continuous conversions, 1khz, ADC4 input
ADCMSKI = BIT1; // Enable ADC1 result ready interrupt source
ADCFLT = 0x7; // Chop off, 1Khz samping rate, SF = 7. No averaging
ADCMDE = BIT0; // Continuous Conversion mode, Normal mode
ADC1CON = BIT8 + BIT9 // ADC1 input channel 4 in Single-Ended mode.
+ BIT15; // Auxiliary-ADC Enabled
// Also, Int reference,
ADCCFG = 0;

IRQEN = BIT10+BIT11; // Enable ADC1 and UART interrupts
printf("初始化成功!\r\n");

while(1)
{

if (newADCdata == 1) // Is there an ADC0 result ready for UART transmission?
{
newADCdata = 0;
printf("NTC\t%lu \r\n",lADC0_Thermocouple); //2^24=16777216
}

if(runtime%1000 < 30)
{
printf ("runtime = %d\r\n",runtime/1000 );
GP0DAT ^= BIT17; // Toggle LED on Evaluation board (P0.4)
// printf("ADC值为%d \r\n",newADCdata);
}
}
}


void IRQ_Handler(void) __irq
{
unsigned long IRQSTATUS = 0;
IRQSTATUS = IRQSTA; // Read off IRQSTA register

if ((IRQSTATUS & BIT10) == BIT10) //If ADC0 interrupt source
{

// if (newADCdata==0)
// {
lADC0_Thermocouple = ADC0DAT;
lADC0_Thermocouple = ADC1DAT; //读从ADC,要先读主ADC的数据
newADCdata = 1;

// }
}

unsigned char ucCOMIID0 = 0;
if ((IRQSTATUS & BIT11) == BIT11) //UART interrupt source
{
ucCOMIID0 = COMIID0;
if ((ucCOMIID0 & 0x2) == 0x2) // Transmit buffer empty 发送缓冲区为空
{
ucTxBufferEmpty = 1;
}
if ((ucCOMIID0 & 0x4) == 0x4) // Receive byte
{
ucComRx = COMRX;
printf("%d\r\n",ucComRx);

}
}
}


void FIQ_Handler(void) __irq
{
unsigned long FIQSTATUS = 0;
FIQSTATUS = FIQSTA; // Read off IRQSTA register
if ((FIQSTATUS & BIT4) == BIT4) //Timer 1 interrupt source
{
//
runtime++;
T1CLRI = 0x55; // Clear the currently active Timer0 Irq
}

}

void Delay_ms(u32 time)
{
u32 tick = runtime;
while(runtime < (tick+time));
}

Top Replies

Parents Reply Children
No Data