Like for 4mA current it showed 925mV and for 20mA current it showed 4.78V.
/****************************************************************
1) RA0 is selected as input channel
2) Source is connected to RA0 pin on kit, by varying it we can have ADC result which is displayed on PORTC.
3) GO/DONE bit must be set before monitoring it for going low.
******************************************************************/
void main() {
//int arr[10] = {0x5f,0x06,0x3b,0x2f,0x66,0x6d,0x7d,0x47,0xff,0x6f};
unsigned int temp, i,x,y,z,no1,no2,no3;
TRISA = 0xff; //Set port A direction as i/p
//TRISA = 0x00; //Port A as output
PORTA = 0X00; //ALL BITS OFF
TRISB = 0x00; //Set port B as output
TRISC = 0x00; //Set PORT C as output
ADCON0 = 0X00; //CLOCK SELECTION Fosc/2 AND ANALOG CHANNEL SELECTION channel RA0 as input
ADCON1 = 0X00; //ALL CHANNELS AS ANALOG INPUT Vref is VDD
//PORTA.A1 = 1; //PORT A0 as input
PORTB.B1 = 1; //4 FND's are connected on PORT B1, B2, B3, B4
PORTB.B2 = 1;
PORTB.B3 = 1;
PORTB.B4 = 1;
PORTC = 0xFF;
Delay_ms(1000);
PORTC = 0x00;
Delay_ms(1000);
while(1)
{
ADRES = 0x00;
ADCON0.ADON = 0x01; //Turn on the ADC
ADCON0.GO = 1;
while(ADCON0.GO == 1); //Wait till conversion is goin on
ADCON0.GO =0
ADCON0 = 0x00; // Stop the ADC
//PORTC = ADRES;
temp = ADRES;
//x = temp/10;
no1 = temp%10;
//temp = x%10;
no2 = temp/10;
no2 = no2%10;
no3 = temp/100;
//PORTC = no1 | 0x30;
PORTC = no1;
Delay_ms(1000);
//PORTC = no2 | 0x30;
PORTC = no2;
Delay_ms(1000);
//PORTC = no3 | 0x30;
PORTC = no3;
Delay_ms(1000);
Delay_us(2); //Call delay 2 microseconds;
}
}
The divide by 2 was to get the best resolution from the D/A. You could also have used 122ohm resistor to avoid the div/2. In either case you would need a lookup table.Hi,
Thank you pebe. However can you please tell me why divide by 2?
Here is my code, which is not working. Its displaying some garbage value on FND. Digits are not getting seprated. Where I am goin wrong?
Hi all,
Value for ADC are now being displayed on FND now. But I am displaying it one by one. Can you guys tell me how to implement scanning mechanism so that values will be displayed at once. I know lil basic that we have to employ 'Persistance Of Vision' mechanism, but he how to implement it? What should be the time interval for scanning?
Thanking you
Hi all,
Value for ADC are now being displayed on FND now. But I am displaying it one by one. Can you guys tell me how to implement scanning mechanism so that values will be displayed at once. I know lil basic that we have to employ 'Persistance Of Vision' mechanism, but he how to implement it? What should be the time interval for scanning?
Thanking you
Hi djc,
Is that using the setup I suggested in thread #7 ?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?