• AVR Freaks

Hot!ADC Values are not reading correctly in PIC16F1526

Author
harsha.reddy
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2018/06/18 23:16:16
  • Location: 0
  • Status: offline
2019/06/23 21:34:52 (permalink)
0

ADC Values are not reading correctly in PIC16F1526

Hello,
We are using PIC16F1526 micro controller and we are trying to read ADC values from channel 16(connected power supply and providing input) then ADC giving wrong voltages as shown below
1V (input)------- 1.30V(ADC Read)
1.5V-------------->1.94V
2.0V -------------->2.58V
2.5V--------------->3.22V
 we are getting above values with ratio difference 1.3, Can you please tell anybody what might be an issue? Our code is below
#define ADC_CHANNEL 16
int main(){
unsigned int adcResult;
char dummyBuf[20];
ANSEL = 0x01 //Making RF0 as analog pin
TRISF0_bit = 1 ;
adcResult = ADC_Read(LMK_ADC_CHANNEL);
voltage = (adcResult/1024.0)*3.3;
FloatToStr(voltage,dummyBuf);
UART1_Write_Text(dummyBuf);
}
Please help us we really struck very bad
Regards,
Harsha
#1

8 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24646
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/24 20:48:39 (permalink)
    +1 (1)
    harsha.reddy
    int main(){

    Not your problem, but this should be
    void main(void)
     
    ANSEL = 0x01 //Making RF0 as analog pin
    there is no register named "ANSEL". Did you mean "ANSELF" ?
    You don't show any code configuring the ADC. Plainly you have just retyped the bits of code that YOU think are at fault.
     
    I would suggest just outputting the raw value you get in adcResult first, and do the calculation by hand.
    That way you know the problem is in the measurement, not the calculations.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    harsha.reddy
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/06/18 23:16:16
    • Location: 0
    • Status: offline
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/25 00:19:55 (permalink)
    0
    Thank you for the reply
      Yes, it is ANSELF = 0x01;
     Ok we are outputting the raw value, it is problem with measurement not the calculation.
    Can you please tell me what needs to configure for ADC. The above code only i have tested, it's giving wrong values. so that i have posted a quesition. Please tell me the sequence to measure the ADC values correctly.
    #3
    PStechPaul
    Super Member
    • Total Posts : 2447
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/25 22:13:40 (permalink)
    +1 (1)
    The datasheet will tell you how to configure the ADC.

     
    #4
    harsha.reddy
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/06/18 23:16:16
    • Location: 0
    • Status: offline
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/25 23:07:20 (permalink)
    0
    We gone through the datasheet and configured as above but it doesn't work that's the reason we are asking again. Is it known issue in PIC16F1526 or some configuration issue?
     
    Regards,
    Harsha
    #5
    ric
    Super Member
    • Total Posts : 24646
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/25 23:17:10 (permalink)
    +2 (2)
    harsha.reddy
    We gone through the datasheet and configured as above ...

    Where?
    There is NO ADC configuration code in what you have posted.
    Where is the code for ADC_Read() ?
    Is it coming from MCC or the old peripheral libraries?
     
    These are the sorts of questions we have to ask when you do not post ALL of the code.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    pcbbc
    Super Member
    • Total Posts : 1388
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/26 00:44:12 (permalink)
    +2 (2)
    How are you powering your PIC? From a LIPO battery perhaps with voltage of 4.3v? Just a guess....

    As well as posting your entire code, please put [​code]code tags[/​code] around your code when posting. It makes your posts readable and means you are more likely to get help.
    #7
    harsha.reddy
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/06/18 23:16:16
    • Location: 0
    • Status: offline
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/26 04:06:18 (permalink)
    0
    We have written the above code in MikroC Pro, In which ADC_Read() function is available to read ADC values, Usually for other microcontrollers like PIC16F18777, we have written same kind of  code to read ADC values, it was giving proper results . I don't think any other configuration is required. and We are powering up PIC by using 3.3V power supply. Please find the below code 

    #define LMK_ADC_CHANNEL 16
    void main(){
    unsigned int adcResult;
    char dummyBuf[20];
    ANSELF = 0x01 //Making RF0 as analog pin
    TRISF0_bit = 1 ;
    adcResult = ADC_Read(LMK_ADC_CHANNEL);
    voltage = (adcResult/1024.0)*3.3;
    FloatToStr(voltage,dummyBuf);
    UART1_Write_Text(dummyBuf);
    }

     
    Regards,
    Harsha
    #8
    PStechPaul
    Super Member
    • Total Posts : 2447
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: ADC Values are not reading correctly in PIC16F1526 2019/06/26 12:56:52 (permalink)
    +1 (1)
    There are probably very few people here who use or are familiar with the MikroC environment and libraries. I found some articles that might help, but you might want to try a MikroC forum:
     
    http://download.mikroe.co...c/help/adc_library.htm

    unsigned int temp_res;

    void main() {
    ANSEL = 0x04; // Configure AN2 pin as analog
    ANSELH = 0; // Configure other AN pins as digital I/O
    C1ON_bit = 0; // Disable comparators
    C2ON_bit = 0;

    TRISA = 0xFF; // PORTA is input
    TRISC = 0; // PORTC is output
    TRISB = 0; // PORTB is output

    do {
    temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
    PORTB = temp_res; // Send lower 8 bits to PORTB
    PORTC = temp_res >> 8; // Send 2 most significant bits to RC1, RC0
    } while(1);
    }


    https://electrosome.com/a...digital-converter-pic/

    https://forum.mikroe.com/viewtopic.php?t=6788
    post edited by PStechPaul - 2019/06/26 13:02:11

     
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5