A/D converter 16Bit with LCD and PIC18F2550

26,137

Circuit Image

The analog to digital converter (ADC) is commonly required in most of the projects. Analog voltage measurement can be done using the ADC hardware built in together in a PIC. The picture below shows a simple setup for measuring the voltage through the adjustment of the potentiometer. PIC used in this example comes with a 10-bit ADC. In the picture, the hex value shown is the ADC value acquired from the hardware. After a simple conversion, the voltage can be obtained from this value. The next step would be to configure the register on the PIC for the ADC to operate. ADCON0 sets the reference voltage to Vdd and Vss and selects AN0 as the input for the ADC. ADCON1 configures the PIN as an analog input. Only PIN AN0 is selected as an analog input in this example. ADCON2 sets the required time for acquisition. The value for TAD is chosen based on the calculation in the datasheet (PIC18F2455, page 298-299). The ADC module is turned on for it to function. To display the floating point number conversion to string must be done. The function sprintf is used to format the output so that it can be shown on the LCD. The sprintf function provided by C18 can't be used directly on a floating point number, so the number must first be broken up into the digits left and right of the decimal point. The sprintf is used to join up the two parts and the floating point number is displayed out on the 2x16 LCD. A routine for reading the ADC value is created. The acquisition is started by setting the GO bit in ADCON0. Conversion is done when the done bits turn 0. The high and low byte of the ADC results are joined into a 16-bit data and passed back from the function. A simple formula can be used to calculate the voltage from the ADC result. The result is multiplied by the max value of reference voltage and divided by 1024. Doing this will obtain the voltage on the pin AN0.

The analog-to-digital converter (ADC) integrated into microcontrollers, such as the PIC series, serves a crucial role in interfacing analog signals with digital systems. In applications requiring voltage measurement, the ADC converts continuous analog voltages into discrete digital values, facilitating further processing and analysis.

In the described setup, a 10-bit ADC is utilized, which allows for 1024 discrete values (from 0 to 1023) corresponding to the input voltage range. The configuration of the ADC begins with setting up control registers, specifically ADCON0, ADCON1, and ADCON2. ADCON0 is responsible for selecting the analog input channel (AN0 in this case) and defining the reference voltage levels (Vdd and Vss). ADCON1 configures the selected pin as an analog input, ensuring that the microcontroller interprets the voltage from the potentiometer correctly. Meanwhile, ADCON2 sets the acquisition time, which is critical for accurate readings; this value is derived from the specific microcontroller's datasheet.

Once the ADC is configured, the module must be enabled to begin operation. The conversion process is initiated by setting the GO bit in ADCON0. The conversion is complete when the ADC indicates that the process is finished, typically monitored through a status bit. The resulting digital value, which is a combination of high and low bytes, is then processed to calculate the corresponding voltage.

To convert the digital value back to a voltage, a straightforward formula is employed: the ADC result is multiplied by the reference voltage and divided by the maximum ADC value (1024). This calculation yields the voltage present at the input pin AN0. For display purposes, particularly on an LCD, the floating-point voltage value must be formatted correctly. This is achieved using the sprintf function, which formats the number into a string for presentation. Given the limitations of the C18 compiler regarding direct floating-point handling, the number is separated into its integer and fractional components before being recombined for display.

Overall, the integration of an ADC in PIC microcontroller applications provides a versatile means to measure and interpret analog signals, enabling a wide range of electronic projects and systems.The analog to digital converter (ADC) is a commonly required in most of the projects. Analog voltage measurement can be done using the ADC hardware built in together in a PIC. The picture below show a simple setup for measuring the voltage through the adjustment of the potentiometer. PIC used in this example come with a 10 bit ADC. In the picture the hex value shown is the ADC value acquired from the hardware. After a simple conversion the voltage can be obtain from this value. The next step would be to configure the register on the PIC for the ADC to operate. ADCON0 sets the refrence voltage to Vdd and Vss and select AN0 as the input for the ADC. ADCON1 configure the PIN as analog input. Only PIN AN0 is selected as analog input in this example. ADCON2 sets the required time for acquisition. The value for TAD is choose based on the calculation in the datasheet (pic18f2455, page 298-299). ADC module is turn on for it to function. To display the floating point number conversion to string must be done. The function sprintf is use to format the output so that it can be showed on the LCD. The sprintf function provided by C18 can't be used directly on a floating point number, so the number must 1st be breakup in to the digits left and right of the decimal point. The sprintf is used to join up the 2 parts and the floating point number is display out on the 2x16 lcd.

A routine for reading of ADC value is created. The acquisition is started by setting the GO bit in ADCON0. Conversion is done when the done bits turn 0. The high and low byte of the ADC results are joined in to a 16 bit data and pass back from the function. A simple formula can be use to calculate the voltage from the ADC result. The result is multiply by the max value of reference voltage and divided by 1024. Doing this will obtain the voltage on the pin AN0. 🔗 External reference




Warning: include(partials/cookie-banner.php): Failed to open stream: Permission denied in /var/www/html/nextgr/view-circuit.php on line 713

Warning: include(): Failed opening 'partials/cookie-banner.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/nextgr/view-circuit.php on line 713