Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC output conversion problem

Status
Not open for further replies.

ecaits

Member level 4
Member level 4
Joined
Jan 16, 2014
Messages
76
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
579
Dear All,

I am facing problem in below code. Please refer below.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void main()
{
    int data[4];
    unsigned int b,c,d,z=0,e,i,f,a,x,p=0,g,h,j,k,l,o,q;
    unsigned int v;
    float t=0;
    long long m,n;
 
    PORTD=0x00;
    PORTC=0x00;
    PORTB=0x00;
    TRISD = 0x00;
        TRISB = 0x00;
        TRISC = 0x00;
    ADC_Init();
    
    f = ADC_Read(0);
 
    a = f;
    t=a/6.82;



In above code, I am getting output of ADC say 193 in f and same in variable a.

Now I want to devide a by 6.82 to reduce the range from 0-1023 t0 0.00 to 150.00 to display on LCD. But I am not getting the output as per my expectation. What may the problem or how can i divide the variable a by 6.82???

This is part of the whole program code. I am working on PIC16F877 using Hitech C Compiler.
 
Last edited by a moderator:

Add LCD code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unsigned char strADCVal[23];
float fAdcVal = 0.0;
 
void main()
{
     
    TRISA = 0x01;
    PORTA = 0x00;
    //ADCON1 register have to be configured
          
    while(1) {
    
        fAdcVal = ADC_Read(0) / 6.82;
        //if adc value is 1023 then 1023 / 6.82 = 150 (LM35 max o/p)
        //1023 should represent 150 that is Vref+ should be 1.5V
        FloatToStr(fAdcVal, strADCVal);
        LCD_Out(2,1,strADCVal);     
    }
}

 

Add LCD code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unsigned char strADCVal[23];
float fAdcVal = 0.0;
 
void main()
{
     
    TRISA = 0x01;
    PORTA = 0x00;
    //ADCON1 register have to be configured
          
    while(1) {
    
        fAdcVal = ADC_Read(0) / 6.82;
        //if adc value is 1023 then 1023 / 6.82 = 150 (LM35 max o/p)
        //1023 should represent 150 that is Vref+ should be 1.5V
        FloatToStr(fAdcVal, strADCVal);
        LCD_Out(2,1,strADCVal);     
    }
}




But I require LCD output in 150.00 range and I want to keep Vref+ as 5V.
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unsigned char strADCVal[23];
float fAdcVal = 0.0;
 
void main()
{
     
    TRISA = 0x01;
    PORTA = 0x00;
    //ADCON1 register have to be configured
    //Configure CMCON here (disable Comparators)
     
    while(1) {
    
        fAdcVal = ADC_Read(0) / 2.046;
        
        FloatToStr(fAdcVal, strADCVal);
        LCD_Out(2,1,strADCVal);     
    }
}



//5V = 1023
//1.5V = 306.9

//306.9 * x = 150

//x = 0.4887585532746823

//1/x = 2.046

//Temperature = fADCVal / 2.046

//If AD value is 306.9 then 306.9 / 2.046 = 150 (150 degree C)

//If your Vref+ is 5V then your max adc value for 150 deg C will be 306.9 (less resolution)
//If your Vref+ is 1.5V then max adc value for 150 deg C will be 1023 (more resolution)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top