Description: 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.
This project is a microcontroller-based college automation system aimed at addressing the challenges faced in educational institutions. It replaces the conventional notice board with an automated device that allows users to both hear and read the information being announced through...
Many of today's appliances feature displays and buttons. Instead of relying on motors and gears, numerous household items now incorporate embedded microcontrollers. This exploration focuses on how to experiment with microcontrollers at home.
Microcontrollers serve as the central processing units for...
The kit employs an off-the-shelf microcontroller based on the AtMega328P-PU Arduino, along with a simplified version designed for ease of replication and modification by collaborators and students. This initiative aims to enable the fabrication of simplified microcontrollers for DIY synthetic...
A regulated and noise-free power supply voltage is essential for microcontrollers and other components such as amplifiers, filters, and GPS devices. Voltage surges in the supply voltage can permanently damage embedded systems. A voltage regulator must maintain the output voltage...
The two optical sensors will provide a count of individuals to the microcontroller, which will relay this value to MCU-II. The microcontroller will detect the entrance of any person through high-to-low pulse transitions on input pins A3 and A4.
The circuit...
The Intersil ICL7106 and ICL7107 are high-performance, low-power, 3½ digit analog-to-digital (A/D) converters. They include seven-segment decoders, display drivers, a reference, and a clock. The ICL7106 is designed to interface with a liquid crystal display (LCD) and features a multiplexed...
The moving message will be displayed on the LCD, which will be controlled through a microcontroller. The message will be sent by a computer using RS232. The circuit diagram of the moving message display is shown in this post, and...
The potentiometer value is not critical; any value from 1 kΩ to 100 kΩ is acceptable. If the "precision potentiometer" described earlier in this chapter has been constructed, it is recommended for use in this experiment. The actual values of...
The objective is to control the power to a load, specifically an 8051-based microcontroller (uC), using two switches. When the uC is powered on, it sets the PWR pin high. Upon pressing the switches again, pin 4 of the flip-flop...
We use cookies to enhance your experience, analyze traffic, and (if you allow) serve personalized ads.
By clicking Accept All, you agree to our use of cookies.
Learn more