swapan
Full Member level 4
Friends,
Surfing net I got a project on PIC based Volt Meter. The code is given as under. Going through the code I stopped at a point and seek your help please. What I got from the code is that, Input voltage is first scaled down to a factor. Then the scaled down voltage is digitized using ADC module. Then the ADC value is multiplied by 2. The resultant value is converted to ASCII and finally displayed using 2x16 LCD module.
I got the entire project except the multiplication by 2 factor. It is not clear why the ADC value is multiplied by 2. Though the matter has been detailed as "To avoid floating point, use I/P voltage = 2*Digital Count", still I could not get the idea.
Help in this regard is solicited please.
regards,
swapan
Surfing net I got a project on PIC based Volt Meter. The code is given as under. Going through the code I stopped at a point and seek your help please. What I got from the code is that, Input voltage is first scaled down to a factor. Then the scaled down voltage is digitized using ADC module. Then the ADC value is multiplied by 2. The resultant value is converted to ASCII and finally displayed using 2x16 LCD module.
I got the entire project except the multiplication by 2 factor. It is not clear why the ADC value is multiplied by 2. Though the matter has been detailed as "To avoid floating point, use I/P voltage = 2*Digital Count", still I could not get the idea.
Help in this regard is solicited please.
regards,
swapan
Code:
// LCD module connections
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
char Message1[] = “DVM Project”;
unsigned int ADC_Value, DisplayVolt;
char *volt = "00.0";
void main() {
ANSEL = 0b00000100; // RA2/AN2 is analog input
ADCON0 = 0b00001000; // Analog channel select @ AN2
ADCON1 = 0x00; // Reference voltage is Vdd
CMCON0 = 0x07 ; // Disable comparators
TRISC = 0b00000000; // PORTC All Outputs
TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,Message1);
Lcd_Chr(2,10,'V');
do {
ADC_Value = ADC_Read(2);
DisplayVolt = ADC_Value * 2;
volt[0] = DisplayVolt/1000 + 48;
volt[1] = (DisplayVolt/100)%10 + 48;
volt[3] = (DisplayVolt/10)%10 + 48;
Lcd_Out(2,5,volt);
delay_ms(500); // Hold for 500 ms
} while(1);