Question: Using MPLAB - ADC _ Controlled _ Pulse Description: - This program reads the Analog voltage from the potentiometer on input AN 0 (

Using MPLAB - ADC_Controlled_Pulse
Description:- This program reads the Analog voltage from the potentiometer on input "AN0(RA0)" as a 10-bit value and turns "ON" the LED connected to pin "RB0" with an on-time proportional to the ADC value using a For Loop. As you adjust the potentiometer (i.e. ADC value) this will vary the ON Vs OFF time of the LED which is used to implement a variable brightness on the LED. This is effectively a PWM (Pulse Width Modulated) waveform.
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 as an Analog input.
6. Setup the ADC as follows (see ADCON0\& 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. RA0/AN0)
- Setup "ADON" bit to turn on A/D module
ADCON1
- Setup "ADFM" bit to select Right Justified result
- Setup "ADCS2" bit as disabled
- Setup "VCFG \(1: 0>\)" bits to use AVDD and AVss
7. Create a 16-bit variable called "adc_val", to store the 10-bit adc result.
8. Inside a continuous loop, start an \( A \bar{D} C \) conversion by writing to the "GO_DONE" bit.
9. Wait until the ADC conversion has completed.
10. Align the 10bit adc value from ADRESL \& ADSREH inside the variable "adc_val".
11. Use a FOR loop, that counts from 0 to 1023, to turn on the LED connected to RB0 when the value of the For Loop iteration count value (e.g. i) is less than the ADC value, and turn it off when value of the For Loop iteration counter is greater than the ADC value. This is in effect produces a variable on-time that is proportional to the ADC value and implements a of implementing Pulse Width Modulation (PWM). This produces a variable brightness on the LED.
12. The PWM waveform can be viewed by double clicking the Oscilliscope while running a simulation. The waveforms shown below illustrate a Low-Duty cycle PWM cycle with low brigthness on the LED, while the Analog Input voltage is close to 0 V . Also, shown is a High-Duty cycle PWM waveform with an Analog Input Voltage close to 5V.
13. Add comments to your code (marks lost for no comments).
14. Ensure all code is properly indented (i.e. marks lost for no indentation).
Inputs:-1(i.e. AN0(RA0))
Outputs:-1(i.e RB0)
Using MPLAB - ADC _ Controlled _ Pulse

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!