RadioLocman.com Electronics ru
Advanced Search +
  
Go Back   RadioLocman Forum > Electronics and ... > Microcontrollers (MCU)

Microcontrollers (MCU) Application and programming of MCUs, Evaluation Kits and Demonstration Boards, Programmers.

Reply
 
Thread Tools Search this Thread
Old 03-25-2016, 06:56 PM   #1
vdurgaidass
Junior Member
 
Join Date: Jan 2016
Posts: 3
vdurgaidass is on a distinguished road
Default PIC32 MX795F512L - ADC problem

I made a custom board based on Microchip MEB (DM320005) and PIC32 Ethernet Starter Kit that use the MCU in subject.
My board has a touch screen that works fine, connected to AN11 AN12 AN13 and AN14.
The internal ADC10 of the pic convert the analog signal to X and Y position.
My board is powered by a Li-ion battery 3.7V and I need to know the battery voltage to have simple indication of the battery state, so I connected the battery to AN2 through a voltage divider.
I'm using the microchip touchscreen driver included in microchip framework V. 2013-06-15.
My problem is I cannot get the correct value of the adc for the AN2 channel. To do some tests I used the code below, took from the Microchip ADC reference:
Code:
void ReadBatteryAdc()
{
    //disable timer 4
    T4CONbits.TON = 0;
    
    CloseADC10();
    //mPORTBSetPinsAnalogIn(BIT_2);
    //ADC_POT_PCFG = RESISTIVETOUCH_ANALOG;
    
    TRISBbits.TRISB11 = 0;
    TRISBbits.TRISB12 = 0;
    TRISBbits.TRISB13 = 0;
    TRISBbits.TRISB14 = 0;
    TRISBbits.TRISB2 = 0;
    LATBbits.LATB11 = 0;
    LATBbits.LATB12 = 0;
    LATBbits.LATB13 = 0;
    LATBbits.LATB14 = 0;
    LATBbits.LATB2 = 1;
    AD1CHSSET = 0x0020000;

    AD1CON1 = 0;            // reset
    AD1CON2 = 0;            // AVdd, AVss, int every conversion, MUXA only
    AD1CON3 = 0x1FFF;       // 31 Tad auto-sample, Tad = 256*Tcy
    AD1CON1 = 0x80E0;       // Turn on A/D module, use auto-convert
    
    
    AD1CSSL = 0;            // No scanned inputs

    
    DelayMs(100);
    AD1CON1bits.SAMP = 1;
    DelayMs(100);
    while(AD1CON1bits.DONE == 0);
    
    vBitLevel = ADC1BUF0;


    //enable timer4
    TickTouchInit();
    TouchHardwareInit(NULL);
}
vdurgaidass is offline   Reply With Quote
Old 03-27-2016, 11:29 AM   #2
symbol
Senior Member
 
Join Date: Oct 2013
Posts: 124
symbol is on a distinguished road
Default

Are you running the MCU directly from the battery or through a LDO regulator?
The reason I ask is that you are setting AD1CON2 such that it will use AVdd as Vrefh and AVss as Vrefl.
symbol is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
LCD 16x2 LCD display problem PIC 16f887 Momoatomic Microcontrollers (MCU) 1 03-04-2016 10:01 AM
ADC using DMA in STM32F105, zero value alibarghi Microcontrollers (MCU) 0 01-09-2016 03:54 PM
PIC32 and I2C EEPROM interface problems symbol Microcontrollers (MCU) 0 08-01-2015 11:12 AM

All times are GMT. The time now is 10:48 AM.




Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Slices ↓
Radiolocman facebook Radiolocman twitter Radiolocman google plus