The 4 channels of ADC1 used, looking at the routine written, basically did not change, but the data read out seems to be garbage. I also tried the main ADC, and it didn't work. Is there something I need to pay attention to in my program? ? The signal voltage is 0.22V, and the data read out is always around 808117, which is the on-chip reference used. Even if I short-circuit to ground, this number will not change. Other programs such as serial port timers are fine, but this ADC is very strange. Do you guys have a similar problem? The compiler used is 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));