/************************************************************************************************ Author : ADI - Apps www.analog.com/AduC7060 Date : November 2007 File : ADC_Cont.c Hardware : ADuC706x Description : This Simple ADC0 example shows how to initialize the Primary ADC for continuous sampling using differential inputs. When using the ADuC7060 Evaluation board, it will digitize the RTD reading. To measure the RTD, the following switch settings must be in place: S4-1 - ON S4-2 - ON S4-3 - ON S4-4 - ON S4-5 to S4-8 - OFF *************************************************************************************************/ // Bit Definitions #define BIT0 0x01 #define BIT1 0x02 #define BIT2 0x04 #define BIT3 0x08 #define BIT4 0x10 #define BIT5 0x20 #define BIT6 0x40 #define BIT7 0x80 #define BIT8 0x100 #define BIT9 0x200 #define BIT10 0x400 #define BIT11 0x800 #define BIT12 0x1000 #define BIT13 0x2000 #define BIT14 0x4000 #define BIT15 0x8000 #define BIT16 0x10000 #define BIT22 0x400000 #define BIT24 0x1000000 #define BIT30 0x40000000 #define Null (void*) 0 #include # include "stdio.h" # include "string.h" void delay(int); void Temperature (void); void save (unsigned long addr, unsigned long value); unsigned load (unsigned long addr); unsigned char ERROR; // global variable declarations.... float Trtd = 0.0; // temperature of RTD float Rrtd = 0.0; // Resistance of RTD unsigned char newADCdata; // 1 means new ADC data available unsigned char newEEPROMdata; volatile unsigned char bSendResultToUART = 0; // Flag used to indicate ADC0 resutl ready to send to UART unsigned char szTemp[128] = ""; // Used to store ADC0 result before printing to UART float Wert[100]; // Used to store ADC0 result before making a calculation unsigned char ucTxBufferEmpty = 0; // Used to indicate that the UART Tx buffer is empty signed long ulADC0Result = 0; // Variable that ADC0DAT is read into in ADC0 IRQ volatile unsigned char ucRxChar = 0; // Variable to read COMRX register into in IRQ handler float ADCconversion = 0.0; signed long y = 0; signed long ResultADC0 = 0; int main(void) { unsigned char i = 0; unsigned char nLen = 0; Wert[j] = Wert[j] + ADCconversion; summe = Wert[j]; Max_wert = Wert[j]; Min_wert = Wert[1]; POWKEY1 = 0x1; POWCON0 = 0x78; // Set core to max CPU speed of 10.24Mhz POWKEY2 = 0xF4; // Initialize the Flash/EEPROM FEEMOD = FEEMOD | BIT3; // FEEADR = 0xFFC3; // FEEDAT = 0x3CFF; // FEECON = 0x06; // turn on excitation current source IEXCON = BIT1 + BIT6; // Enable Excitation Current Source 0 - 400uA GP0DAT = BIT24; GP1DAT = BIT30; // Configure P1.6 as an output to drive the LED // Initialize the UART for 9600-8-N GP1CON = BIT0 + BIT4; // Select UART functionality for P1.0/P1.1 COMCON0 = BIT7; // Enable access to COMDIV registers COMDIV0 = 0x21; // Set baud rate to 9600. COMDIV1 = 0x00; COMCON0 = BIT0 + BIT1 + BIT2; COMIEN0 = BIT0 + BIT1; // Enable UART interrupts when Rx full and Tx buffer empty. // Configure ADC0 for continuous conversions, 100hz, AIN0/1 Differential inputs ADCMSKI = BIT0; // Enable ADC0 result ready interrupt source ADCFLT = 0x4F; // 100Hz no filtering, Chop off, No averaging ADC0CON = BIT10 + BIT15; // Gain = 32, Unipolar, enable ADC0, Int Reference ADCCFG = 0; // Offest Self Calibration ADCMDE = BIT2 + BIT4 + BIT7; while((ADCSTA & BIT0) != BIT0){} // Wait for Calibration routine to complete // Gain Self Calibration ADCMDE = BIT0 + BIT2 + BIT4 + BIT7; while((ADCSTA & BIT0) != BIT0){} // Wait for Calibration routine to complete ADC0CON = BIT0 + BIT2 + BIT10 + BIT15; // Gain = 32, Unipolar, enable ADC0, Int Reference ADCMDE = BIT0 + BIT7; // Enable Continuous conversion mode IRQEN = BIT10 + BIT11; // Enable ADC0 and UART interrupts bSendResultToUART = 0; while (1) { if (newADCdata == 1) { Temperature(); bSendResultToUART = 1; } if (newEEPROMdata == 1) { // for ( i = 0; i < 20; i++) save(0xF000, *((unsigned long*)0xFFFF051C)); } { load(0xF000); y = FEEDAT; } delay (0x8FFFF); } void Temperature () { newADCdata = 0; // First calculate the resistance across the RTD // Equation = ADC0Result * ((RREF/Gain)/# of bits) Rrtd = (float)ulADC0Result * ((5600.0 /32.0) /0xFFFFFF); // Next the temperature value is calculated using Rtd resistance // Simple Linear equation: // At 35 degree Celsius, the equivalent resistance of a PT100 is 113.607 Ohm. Trtd = (Rrtd - 100.0) * (35.0/13.607); } void save (unsigned long addr, unsigned long value) { unsigned long Flash_Status = 0; FEEADR = addr; FEEDAT = value; //*((unsigned long*)0xFFFF051C); FEECON = 0x03; Flash_Status = FEESTA&0x03; while (!(Flash_Status)) Flash_Status = FEESTA&0x03; if ((Flash_Status & 0x02) == 0x02) ERROR = 1; return; } unsigned load (unsigned long addr) { unsigned long Flash_Status = 0; FEEADR = addr; FEECON = 0x01; Flash_Status = FEESTA&0x03; while (!(Flash_Status)) Flash_Status = FEESTA&0x03; if ((Flash_Status & 0x02) == 0x02) ERROR = 1; return(FEEDAT); } void IRQ_Handler(void) __irq { unsigned long IRQSTATUS = 0; unsigned char ucCOMIID0 = 0; // unsigned long Flash_Status = 0; IRQSTATUS = IRQSTA; // Read off IRQSTA register if ((IRQSTATUS & BIT11 ) == BIT11) //UART interrupt source { ucCOMIID0 = COMIID0; if ((ucCOMIID0 & 0x2) == 0x2) // Transmit buffer empty { ucTxBufferEmpty = 1; } } if ((IRQSTATUS & BIT10) == BIT10) //If ADC0 interrupt source { // if ADCnorm variables are ready for new data.. if (newADCdata==0) { // ulADC0Result = ADC0DAT; // Read ADC0 conversion result ADC0data_ptr = (signed long*)0xFFFF051C; ulADC0Result = *ADC0data_ptr; ResultADC0 = ulADC0Result - (y); *ADC0data_ptr = ResultADC0; ADCconversion = (float) ((ResultADC0 * (1200.0 / 16777216.0)) /32.0); } if ((IRQSTATUS & BIT13) == BIT13) // XIRQ0 external Interrupt Source { newEEPROMdata = 1; } newADCdata = 1; GP1DAT ^= BIT22; newADCdata = 1; IRQCLR = BIT10; } } // Simple Delay routine void delay (int length) { while (length >0) length--; }