Hello Friends, I am working with ADC module for PIC24F series . I have used the sample source code as given in the reference manual for ADC available in PIC website. Please refer to example 17-6 in the refernce manual. I am using the Explorer 16 development board. I tried transmitting the converted value to the hyperterminal. I am facing two problems with this 1. The baud rate i have calulated for serial communication is 19200 but when i set the same speed in the hyperterminal it doesnt show the data properly. When i change the baud rate to 9600 in hyperterminal then it receives the converted data properly. 2. The ADC coversion does not take place continuosly. It converts for 1200 times approximately and then the Micro controller resets . I am attaching the code along with this mail. It would be really a great help if any of you can clarify me why is this happening? I need to fix this problem to proceed further in my work. *my main.c file* #include "system.h" #include "p24FJ64GA004.h" #include "iomapping.h" #include "f_uart.h" #define PPS_UART2_TX_TRIS TRISCbits.TRISC9 #define PPS_UART2_RX_TRIS TRISCbits.TRISC3 #define UART2_TX_TRIS PPS_UART2_TX_TRIS #define UART2_RX_TRIS PPS_UART2_RX_TRIS //ADC channels numbers #define ADC_TEMPERATURE ADC_TEMP_CHAN #define ADC_VOLTAGE ADC_VOLT_CHAN static void ADCInit(); UINT8 buff[6]; void __attribute__((__interrupt__, auto_psv)) _U2TXInterrupt(void) { /*clear the transmission interrupt flag everytime a byte is transmitted outside. */ IFS1bits.U2TXIF = 0; } void __attribute__((__interrupt__,auto_psv)) _OscillatorFail(void) { INTCON1bits.OSCFAIL = 0; //Clear the trap flag while (1); } void __attribute__((__interrupt__,auto_psv)) _AddressError(void) { INTCON1bits.ADDRERR = 0; //Clear the trap flag while (1); } void __attribute__((__interrupt__,auto_psv)) _StackError(void) { INTCON1bits.STKERR = 0; //Clear the trap flag while (1); } void __attribute__((__interrupt__,auto_psv)) _MathError(void) { INTCON1bits.MATHERR = 0; //Clear the trap flag while (1); } void __attribute__((__interrupt__, auto_psv)) _U2RXInterrupt(void) {/*Start-Serial reception interrupt*/ /*Clear the transmission interrupt flag on entry*/ IFS1bits.U2RXIF = 0; } int main(void) { UINT32 ADCValue,*adc_buff; UINT16 i,j,count; RPINR19bits.U2RXR = 19;/*added for testing*/ RPOR12bits.RP25R = U2TX_IO; /*added for testing*/ UART2_TX_TRIS = 0; /*added for testing*/ UART2_RX_TRIS = 1; /*added for testing*/ init_UART1_communication(); enable_UART1_serial_interrupt(); ADCInit(); lockIO(); while(1) { ADCValue = 0; IFS0bits.AD1IF = 0; AD1CON1bits.ASAM = 1; adc_buff = &ADC1BUF0; while(!IFS0bits.AD1IF); AD1CON1bits.ASAM = 0; for(count = 0; count < 16;count++) ADCValue = *adc_buff; /*why do we do this calculation*/ ADCValue = (ADCValue * 3300) / 1024; for(i = 0;i<1000;i++); buff[0] = (ADCValue /1000) + '0'; ADCValue = ADCValue % 1000; buff[1] = '.' ; buff[2] = (ADCValue /100) + '0'; ADCValue = ADCValue % 100; buff[3] = (ADCValue /100) + '0'; ADCValue = ADCValue % 10; buff[4] = ADCValue + '0'; buff[5] = ' '; for(j = 0;j<2000;j++); for(i = 0;i<6;) { U2TXREG = buff[i]; for(j = 0;j<2000;j++); i++; } }; return 0; } static void ADCInit() { /* AD1CON1 = 0x80E4; //Turn on, auto sample start, auto-convert AD1CON2 = 0; //AVdd, AVss, int every conversion, MUXA only AD1CON3 = 0x1F05; //31 Tad auto-sample, Tad = 5*Tcy AD1CHS = ADC_VOLTAGE; same as Anolog PIn for voltage scanning in explorer 16 board. TRISBbits.TRISB2 = 1; TRISBbits.TRISB3 = 1; AN_VOLT_PIN = 0; //Disable digital input on AN5 AN_TEMP_PIN = 0; //Disable digital input on AN4 AD1CSSL = 0; //No scanned inputs */ AD1PCFG = 0x0000; AD1CON1 = 0x80e4; //Turn on, auto sample start, auto-convert AD1CHS = ADC_VOLTAGE; AD1CSSL = 0; //No scanned inputs AD1CON3 = 0x1f05; //31 Tad auto-sample, Tad = 5*Tcy AD1CON2 = 0x00; //AVdd, AVss, int every conversion, MUXA only AD1CON1bits.ADON = 1; } void lockIO(){ asm volatile ("mov #OSCCON,w1 \n" "mov #0x46, w2 \n" "mov #0x57, w3 \n" "mov.b w2,[w1] \n" "mov.b w3,[w1] \n" "bset OSCCON, #6"); } /***************************************************************************** * Function: unlockIO * *****************************************************************************/ void unlockIO(){ asm volatile ("mov #OSCCON,w1 \n" "mov #0x46, w2 \n" "mov #0x57, w3 \n" "mov.b w2,[w1] \n" "mov.b w3,[w1] \n" "bclr OSCCON, #6"); } /***************************************************************************** * Function: init_uart_communication * *****************************************************************************/ void init_uart_communication(void) { U2BRG = SYSCLK /32/19200 - 1; U2MODE = (UART_UXMODE_EN | UART_UXMODE_IDLE_CON | UART_UXMODE_DIS_WAKE | UART_UXMODE_DIS_LOOPBACK | UART_UXMODE_DIS_ABAUD | UART_UXMODE_NO_PAR_8BIT | UART_UXMODE_1STOPBIT); U2STA = ( UART_STS_INT_TX_BUF_EMPTY | UART_STS_IrDA_POL_INV_ZERO | UART_STS_SYNC_BREAK_DISABLED | UART_STS_TX_ENABLE | UART_STS_INT_RX_CHAR| UART_STS_ADR_DETECT_DIS ); } /***************************************************************************** * Function: enable_UART1_serial_interrupt* *****************************************************************************/ void enable_UART1_serial_interrupt(void) { /*UART1 Interrupt registers*/ /*Clear the UART2 reception interrupt flag*/ U2RX_CLEAR_INTR_STATUS_BIT(); /*Claer the UART2 transmission interrupt flag*/ U2TX_CLEAR_INTR_STATUS_BIT(); /*Set the priority level of transmission interrupt to 2*/ SET_PRIORITY_INTR_U2TX(UART_TX_INTR_PR2); /*Set the priority level of the reception interrupt to 6*/ SET_PRIORITY_INTR_U2RX(UART_RX_INTR_PR3); /*Enable the reception interrupt for UART2*/ ENABLE_INTR_U2RX(); /*Enable the transmission interrupt for UART2*/ ENABLE_INTR_U2TX(); } Looking forward for suggestions for fixing this problem Thanks and Regards Manju Bhargavi -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist