Inside this loop, ADC_Read(0) reads analog input signal value from AN0/RA0 pins and store this value into a variable “voltage”. This code is placed inside the while(1) loop function and it keeps executing. LCD_Out(1, 1, "Digital voltmeter") // print "Digital voltmeter"on first line and first rowĭelay_ms(1000) // add a delay of one second LCD_Cmd(_LCD_CLEAR) // Clear whatever is written on LCD LCD_Cmd(_LCD_CURSOR_OFF) // turn off LCD cursor These code lines initialize built-in library of ADC module and liquid crystal dislpay. These lines are used to define pic microcontroller pins that will be used with 16×2 LCD. First, we used ‘sbit’ to define pins connection with LCD and PIC16F877A. Now let’s understand the working of code. Inttostr(voltage,volt) // it converts integer value into string Write your first program in MikroC for PIC Compiler.If you don’t know how create new project in mikroC, we suggest you read this post: Create a new project with MikroC compiler by selecting PIC16F877A microcontroller and set frequency to 8MHz. This code is written using MikroC for Pic compiler. Statement one is used to reading ADC value and stores its value in variable “voltage” and in second statement voltage value is multiplied with resolution factor and voltage divider factor to convert it into actual input voltage value. Voltage = (voltage * 5 * 10)/ (1024) // resolution factor and voltage divider factor Voltage measured by the ADC module of PIC16F877A microcontroller can be calculated by following programming commands: voltage = ADC_Read(0) // ADC channel zero stores value in variable voltage The code for digital voltmeter is written using the MikroC Pro compiler. Above I have discussed the function of each component and its working in dc voltage measurement with pic microcontroller. Now, let’s discuss how to write a program for digital dc voltmeter using a pic microcontroller. It means for every analog signal of 4.87mV, ADC value increments by one. Hence by using these values in the above formula, this minimum voltage will be: resolution = (5 - 0 )/ (1023) = 4.8876 mV In this project, we are taking Verf+= 5 volts and Vref- = 0 volt. This minimum analog value is called resolution. For example, pic16f877A microcontroller has 10-bit ADC and it counts binary from 0-1023 for every minimum analog value of the input signal. This minimum analog value is called resolution ADC increment by one. Resolution means minimum value of the analog signal for which ADC counter increment by one. Resolution = (Vrer+ - Vref-) / (1024 -1 ) ĪDC resolution is an important concept to discuss here. So it converts an analog signal to a 10-bit digital number which can be back converted into voltage using the following calculation in the programming of digital voltmeter. PIC16F877A microcontroller has a 10 bit ADC. ADC module of pic microcontroller converts an analog signal into binary numbers.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |