cmicrocontrollerlcdadcmikroc

ADC_READ not maxed out


I am running a microcontroller in Proteus with its integrated ADC (10bit output) and a LCD display, yet when inputing a signal of 5V, it will only display up to 4092mV, even though the LCD is perfectly fine because I tried outputing other chars.

Here is the code and a picture of Proteus.

int tension;
int valeurnum;
char valeurchar[10];

void main() {
    ADCON1=14;
    TRISA=1;TRISB=0;
    Lcd_Init();
    while(1){
            tension=ADC_Read(0);
            valeurnum=(5000/1023)*tension;
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_Cmd(_LCD_CURSOR_OFF);
            IntToStr(valeurnum,valeurchar);
            Lcd_Out(1,1,valeurchar);
            delay_ms(1000);;
            }
}

If you lads hav any idea about what I could do or check, or if you need any more infos, please tell me, thanks a lot in advance and have a great day!

Proteus Layout


Solution

  • Apparently I made a mistake with formulas, I was loosing too much accuracy with the number itself when dividing.

    float valeurnum;
    char valeurchar[20];
    void main() {
        ADCON1=14;
        TRISA=1;TRISB=0;
        Lcd_Init();
        while(1){
                valeurnum=ADC_Read(0);
                valeurnum=valeurnum*5000;
                valeurnum=valeurnum/1024;
                Lcd_Cmd(_LCD_CLEAR);
                Lcd_Cmd(_LCD_CURSOR_OFF);
                FloatToStr(valeurnum,valeurchar);
                Lcd_Out(1,1,valeurchar);
                delay_ms(1000);;
                }
    }