Question: Project Name: - ADC _ Compare _ ANO _ AN 3 Description: - This program reads the Analog voltage from the potentiometers on inputs

Project Name:-
ADC_Compare_ANO_AN3
Description:- This program reads the Analog voltage from the potentiometers on inputs "AN0(RA0)" and "AN3(RA3). If the input voltage on pin AN0 is greater thanor equal to AN3 then the LED connected to pin RB0 is turned ON, otherwise it is turned off.
Instructions:-
1. Create a macro name for the LED:-
E.g.\#define LED RB0
2. Create a macro name for ON and OFF:-
E.g.\#define ON 1
\#define OFF 0
3. Use the macros listed above in your program.
4. Setup RB0 pin as a Digital Output.
5. Setup AN0/RA0 pin and AN3/RA3 pin as Analog inputs.
6. Setup the ADC as follows (see ADCONO \& ADCON1 registers on pages 114/115 of the PIC16F188 Datasheet):-
ADCON0
- Setup "ADCS \(1: 0>\)" bits to select the internal RC oscillator
- Setup "CHS2:0>" to select Channel 0(i.e. RA3/AN3)
- Setup "ADON" bit to turn on A/D module
ADCON1
- Setup "ADFM" bit to select Left Justified result
- Setup "ADCS2" bit as disabled
- Setup "VCFG \(1: 0>\)" bits to use AVDD and AVss
7. Create two 8-bit variables called "adc_val0" and "adc_val3" to store the value of the two ADC results from each channel (i.e. Channel 0 and Channel 3).
8. Inside a continuous loop, call a function (explained below) twice in succession that returns the ADC value for channel 0 and channel 3 into the variables "adc_val0" and "adc val3" respectively. If the voltage on AN0(RA0) is greater than or equal to AN3(RA \(\overline{3}\)) then turn on the LED connected to RB0, othwerwise turn off the LED.
9. Create a function with the following function header:-
unsigned char get_adc_val(unsigned char channel)
where,
channel equals ADC Channel number
unsigned char equals the 8-bit result retuned from the \( A D C \)
- Inside the function do the following:-
- Set the channel using the C statement \(\rightarrow \) ADCON0bits.CHS \(=x x \);
- Insert a 10uSec delay to allow the ADC to switch channel \(\rightarrow \)__delay_us(xx);
- Start the ADC Conversion.
- Wait for the ADC conversion to finish.
- Return the ADC result from the function.
10. Add comments to your code (marks lost for no comments).
11. Ensure all code is properly indented (i.e. marks lost for no indentation).
Inputs:-2(i.e. AN0(RA0), AN3(RA3))
Outputs:-1(i.e RB0)
Project Name: - ADC _ Compare _ ANO _ AN 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!