• AVR Freaks

Hot!ADC interface doesnt work

Author
aviator3679
Starting Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2019/08/22 13:32:23
  • Location: 0
  • Status: offline
2019/08/28 21:16:18 (permalink)
0

ADC interface doesnt work

Hello, i am using PIC18F2580 and the XC8 v1.34 compiler and trying to interface an ADC but doesnt compile.Does anyone know whats happening? The code im using is below:
 
#include <stdio.h>
#include <stdlib.h>
#include "adc.h"
#include <delays.h>
void Initialize_ADC(void);
void Initialize_XLCD(void);
void DelayFor18TCY(void);
void DelayPORXLCD(void);
void DelayXLCD(void);
unsigned int ADCResult=0;
float voltage;
unsigned char ResultString[10];
void main(void)
{
OSCCON=0x76;

Initialize_ADC();
Initialize_XLCD();

putrsXLCD("ADC");
SetDDRamAddr(0x40);
putrsXLCD("Display Voltage");
for(int x=0;x<=20;x++)__delay_ms(50);
WriteCmdXLCD(0x01);

while(1)
{
ADCResult=0;
ConvertADC();
while(BusyADC());
ADCResult=ReadADC();
voltage=(ADCResult*5.0)/1024;

putrsXLCD("Voltage=");
sprintf(ResultString, "%.3", voltage);
putsXLCD(ResultString);
putrsXLCD("V");
putrsXLCD(" ");
WriteCmdXLCD(0x02);
}
}
void DelayFor18TCY(void)
{
Delay10TCYx(2);
}
void DelayPORXLCD(void)
{
Delay1KTCYx(60);
return;
}
void DelayXLCD(void)
{
Delay1KTCYx(20);
return;
}
void Initialize_ADC(void)
{
OpenADC(ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_2_TAD, ADC_CH0 & ADC_INT_ON & ADC_REF_VDD_VSS, ADC_1ANA);
}
void Initialize_XLCD(void)
{
OpenXLCD(FOUR_BIT & LINES_5X7);
while(BusyXLCD());
WriteCmdXLCD(0x06);
WriteCmdXLCD(0x0C);
WriteCmdXLCD(0x01);
}
#1

13 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24605
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 22:06:44 (permalink)
    0
    "Doesn't compile" is not very informative.
    What error message do you get?
    Post the whole build log if you don't know which bit is relevant.

    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
    aviator3679
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/08/22 13:32:23
    • Location: 0
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 22:11:37 (permalink)
    0
    Yeah sorry about that haha.....the whole build log is below:
     
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory 'C:/Users/aeros/MPLABXProjects/adc.X'
    make -f nbproject/Makefile-default.mk dist/default/production/adc.X.production.hex
    make[2]: Entering directory 'C:/Users/aeros/MPLABXProjects/adc.X'
    "C:\Program Files (x86)\Microchip\xc8\v1.34\bin\xc8.exe" --pass1 --chip=18F2580 -Q -G --double=24 --float=24 --emi=wordwrite --opt=+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/adc.p1 adc.c
    adc.c:45: error: (969) end of string in format specifier
    adc.c:45: warning: (325) error in printf-style format string
    (908) exit status = 1
    nbproject/Makefile-default.mk:107: recipe for target 'build/default/production/adc.p1' failed
    make[2]: Leaving directory 'C:/Users/aeros/MPLABXProjects/adc.X'
    nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
    make[1]: Leaving directory 'C:/Users/aeros/MPLABXProjects/adc.X'
    nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
    make[2]: *** [build/default/production/adc.p1] Error 1
    make[1]: *** [.build-conf] Error 2
    make: *** [.build-impl] Error 2
    BUILD FAILED (exit value 2, total time: 2s)
    #3
    ric
    Super Member
    • Total Posts : 24605
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 22:29:17 (permalink)
    0
    Here's the first error
    adc.c:45: error: (969) end of string in format specifier

    What is on line 45 of your copy of adc.c ?
    Possibly that file is corrupt.
     

    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!
    #4
    aviator3679
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/08/22 13:32:23
    • Location: 0
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 22:49:06 (permalink)
    0
    On line 45 i have:
     
    sprintf(ResultString, "%.3", voltage);
     
    But still this should work
     
    #5
    ric
    Super Member
    • Total Posts : 24605
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 23:22:36 (permalink)
    0
    aviator3679
    On line 45 i have:
     
    sprintf(ResultString, "%.3", voltage);
     
    But still this should work



    It would if you had remembered the format character. I assume there's meant to be an "f" in there!
     

    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
    aviator3679
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/08/22 13:32:23
    • Location: 0
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 23:27:35 (permalink)
    0
    I am watching a youtube tutorial the he has it exactly like that and it works
    #7
    aviator3679
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/08/22 13:32:23
    • Location: 0
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 23:28:54 (permalink)
    0
    how is it with an f ?......I am a student, its not like i have much experience with this kind of stuff
     
    #8
    ric
    Super Member
    • Total Posts : 24605
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 23:29:32 (permalink)
    0
    It is invalid C syntax, so he's using some sort of non compliant compiler then.
    I can't comment any further as you failed to reveal the address of this "Youtube video".
     

    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!
    #9
    ric
    Super Member
    • Total Posts : 24605
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: ADC interface doesnt work 2019/08/28 23:32:40 (permalink)
    0
    aviator3679
    how is it with an f ?......I am a student, its not like i have much experience with this kind of stuff

    So how much C learning have you done?
    "format specifiers" in printf() statements are something you should learn how to use in the first week, before you start playing with exotic hardware...
     

    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!
    #10
    aviator3679
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/08/22 13:32:23
    • Location: 0
    • Status: offline
    Re: ADC interface doesnt work 2019/08/29 00:05:13 (permalink)
    0
    Yeah i know,i supposed that since its a tutorial he may be using something i dont know ,so it should be alright,i am almost done with embedded C,only some final theoritical stuff remain about the better structure of the code and some practice in assignments,thats it....unfortunately for some reason the forum doesnt allow me to include a link...
    #11
    aviator3679
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/08/22 13:32:23
    • Location: 0
    • Status: offline
    Re: ADC interface doesnt work 2019/08/29 00:06:29 (permalink)
    0
    I tried what you said about the f in the code and works,it compiles....THANK YOU !!!!!
     
    #12
    Aussie Susan
    Super Member
    • Total Posts : 3637
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: ADC interface doesnt work 2019/08/29 19:04:08 (permalink)
    0
    I'm not totally sure but I do know that the XC8 compiler parses the format specifier when it is a string literal so that it can optimise what modules need to be included in the app (rather than including everything and leaving it to runtime to do the parsing and interpreting). If the compiler can't interpret the format specifier string according to the 'rules', then it looks like it treats it as a compile error.
    Susan
    #13
    aviator3679
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2019/08/22 13:32:23
    • Location: 0
    • Status: offline
    Re: ADC interface doesnt work 2019/08/29 20:58:26 (permalink)
    0
    Maybe, because this  project seems to work now but in another i think that everything is alright except the adc conversion, resulting in displaying black boxes on my lcd display simulation on proteus....For more info :
    https://www.microchip.com/forums/m1110825.aspx   with title : lcd / black vertical bars

    [font="verdana; font-size: 14px; font-weight: normal"] 

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