Digital Voltmeter Using PIC Microcontroller 16F877A and
Here I’m explaining the constructional details of digital panel voltmeter using PIC16F877Amicrocontroller. It can measure voltage between 0V to 30V DC.
The program for digital voltmeter using pic microcontrolle is compiled using CCS.
Circuit Schematics of Digital Voltmeter Using PIC Microcontroller
The following figure shows digital voltmeter panel circuit diagram with microchip PIC.
Components Required for Digital Voltmeter Using PIC Microcontroller
- PIC16F877A Microcontroller
- LCD 16*2
- Resistor ( 1KΩ; 9KΩ)
- Crystal (20MHz)
- Capacitor ( 22PF x2)
Working of Digital Voltmeter Using PIC Microcontroller
- PIC programming is quite easy if you have a perfect C compiler like Mikro C pro, MPLAB Hi-tech C etc.
- If you are new to PIC microcontroller I recommend to checkout our previous articles andGetting started guides for PIC MCU. You may also checkout our PIC Projects
- PIC16F877A has inbuilt ADC (Analog to Digital Converter) Module, I used ADC to read input voltage value.
Measuring Voltage and Design of Voltage Divider Circuit
- First of all let I discuss how do we measure voltage? Actually PIC’s ADC can measure 0V to +5V, but here our voltage range is 0V to +100V.
- Hence we can’t feed the input voltage directly to the controller’s ADC pins. Instead of feeding directly, input voltage is reduced by a combination of voltage divider resistors.
V out = (R1/R1+R2 ) V in
AN.
Vout = (1/1+9 ) 12 = 0.12
Mapping ADC Values to Input Voltage
- PIC microcontroller ADC is a 10 bit ADC, that means the output of ADC can be vary from0 to 1023 maximum while input varies from 0 to 5V.
- That is when the input voltage is +5V then ADC value is 1023, when input voltage is 0V ADC value will be 0.
- We have to map 0 → 1023 to 0 → 5; it can be done by multiplying ADC value with a
5-------------->1023
?---------------> ADC val
voltge = (5* adc val /1023)
I multiply by 10 to display the exact value Battery
TBAT=voltge *10
program
#include <16F877A.h>
#device ADC=10
#FUSES HS
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay (clock=4000000)
#define LCD_DATA_PORT getenv("SFR:PORTD")
#include <lcd.c>
int16 tbat;
float test;
void batrie()
{
set_adc_channel( 1);
delay_us(20);
tbat = read_adc();
test=tbat;
test=test*0.04887585532746823069403714565;
lcd_gotoxy(1,1);
printf(LCD_PUTC, "Tb=%2.1f V",test);
}
void main()
{ setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
lcd_init();
lcd_gotoxy(1,2);
printf(LCD_PUTC, "Smart_tech naim ");
while(true)
{
batrie();
}
}
Aucun commentaire:
Enregistrer un commentaire