Skip to main content

PC Based Digital Voltmeter Using PIC 16F877A

Voltmeter C# .Net PIC, Arduino, AVR






This is a simple voltmeter which measures 0-5V at a precision of 4.8 mV. This is a simple design using inbuilt ADC of PIC 16F877A. PIC 16F877A have 8 channel 10bit ADC.  This is a computer interfaced project. Measured voltage is output in serial interface software in computer. There is a serial interface circuit (MAX232) is necessary for interfacing with computer, which is not included in the circuit. Please check     PIC Serial Communication Tutorial (UART)  for the circuit and more details.





Using one of the most popular 8 bit PIC 16f877A, for instance, reading the datasheet, we'll find that the ADC modules (10 bit) are controlled by four different registers. The first two, ADCON0 and ADCON1, are used to set and start the ADC module. When high level language is used, the programmer doesn't need to care a lot of the register connected to the results because they are normally stored in a variable by a routine of the language itself (adc_read, for instance, using mikroc).

The ADCON0
As we can see this registers are 8 bit registers where.
- bit6 and bit 7 are used to set the frequency of the conversions.
- bits 3, 4 and 5 are used to select the pins of the microcontroller enabled to the adc conversions.
- bit 2 represents the status of the conversion procedure.
- bit 0 starts the conversion.


ADCON1










Regarding the second register, ADCON1, it must be set for two reasons: to select the format of the result value (bit 7), to select (bit0...bit3) the reference voltage and to set the port configuration control bits according to the following table





ADCON1








This circuit uses AN0 channel of ADC. The voltage conversion is employed in a logic, 16F877A have 10 bit ADC. That is, it can have 1024 levels. Reference voltage is fixed at
0 – 5 V Analog I/P is mapped to one of the 1024 levels (0-1023 Digital Count)
Resolution = 5/(1024)   (as it is 10 bit ADC)
= 5/1024
= 4.8828 mV   It  means that for a change in 4.8828mV, the binary output changes by 1.

ADC module of PIC Microcontroller converts the Signals on its analog pin to 10 bit binary data and it has software selectable high and low voltage reference input to some combination of VDD, VSS, RA2 and RA3. The analog input to PIC is limited to 0 to 5.


The converted value is in mV. It is then converted to volts and characters to send to serial port.
Normal hiperterminal application can be used for reception. Comments are given in program to easy understanding.

Click here for the PC program



PIC 16F877A Voltmeter

Code

/**********************************************/
/*
  
 http://www.facebook.com/EmbeddedProjects

 http://microcontrollerprojects00.blogspot.in/

 Author: Vishal K M

 uC:16F877A
 Compiler: mikroC
 Crystal freq: 4MHz


                                              */
/**********************************************/





unsigned long temp;
unsigned int i;
char digit[]="0.000-VOLTS ";

void main() {


TRISA=0xFF;

ADCON0=0x01;
ADCON1=0x0E;
UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize
 
   UART1_Write_Text("Embedded Projects");
   UART1_Write(0x0D);

  do {
    temp = ADC_Read(0);   // Get 10-bit results of AD conversion
    temp=temp*5000/1023;   //Convert ADC value to mV
   
   

    digit[0]=(temp/1000)+48;
    digit[2]=((temp%1000)/100)+48;
    digit[3]=(((temp%1000)%100)/10)+48;
    digit[4]=(((temp%1000)%100)%10)+48;
   
    UART1_Write_Text(digit);

    UART1_Write(0x0D);   //Carriage Return
    Delay_ms(500);

  } while(1);
}

Comments

  1. can you explain this part of the code

    digit[0]=(temp/1000)+48;
    digit[2]=((temp%1000)/100)+48;
    digit[3]=(((temp%1000)%100)/10)+48;
    digit[4]=(((temp%1000)%100)%10)+48;

    UART1_Write_Text(digit);

    UART1_Write(0x0D); //Carriage Return
    Delay_ms(500);

    } while(1);
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

PIC 16F877A Microcontroller Based Electronic Lock 16x2LCD 4x3 Keypad

 Circuit Diagram Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible. An access control for doors forms a vital link in a security chain. The microcontroller based digital lock for Doors is an access control system that allows only authorized persons to access a restricted area. An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a Keypad, LCD and the controller PIC16F877A. This article describes the making of an electronic code lock using the 16F877A microcontroller. The system is fully controlled by the 8 bit microcontroller 16F877A which has a 8Kbytes of ROM for the program memory. The password is stored in the

Electronic Voting Machine Using 8051 Microcontroller (AT89C51)

  Circuit Electronic voting machine has now replaced the traditional mechanism of voting due to several advantages like security, automatic counting etc. This project presents a way to develop an electronic voting machine which displays the count of votes on a 16x2 LCD interface. A user can get his/her vote register through a set of switches (one for each candidate). After every cast of vote, the subsequent count can be seen on LCD. The circuit uses AT89C51 microcontroller and the code for the project has been written in C. This LCD based electronic voting machine is designed for four candidates. The input part consists of a set of six tactile switches. The switches and 16x2 LCD are interfaced to microcontroller AT89C51 for various operations and displays. The provision of casting votes for the candidates has been provided through four of these switches. These switches are made active high and connected to pins 2-5 (P1^1 – P1^4) of the controller. The remaining two

89C51 Based Digital Thermometer Using DS1820

Introduction The hardware configuration when using multiple 1-Wire temperature sensors like the DS1820 is very simple, as illustrated in the block diagram below. A single-wire bus is used for communication between the microcontroller and the temperature sensor. It is also possible to power the devices direclty via this 1-Wire bus. An almost unlimited number of 1-WireTM devices can be connected to the bus because each device has a unique 64-bit ROM code identifier which is used to address each sensor   Temperature measurement using DS1820 sensor. Use of ‘1-wire’ protocol... Temperature measurement is one of the most common tasks performed by the microcontroller. A DS1820 sensor is used for measurement here. It is capable of measuring temperature in the range of -55 °C to 125 °C with 0.5 °C accuracy. For the purpose of transferring data to the microcontroller, a special type of serial communication called 1-wire is used. Due to a simple and wide use of these sensors, commands us