ENGR 294 Fall 2020 Prof: Mohamed Hajiaboli Project #1: PWM, RMS vs Average Using analogRead and analogWrite Functions Purpose: The purpose of this project is for you to understand PWM, the differences...

1 answer below »
ENGR 294 Fall 2020 Prof: Mohamed Hajiaboli Project #1: PWM, RMS vs Average Using analogRead and analogWrite Functions Purpose: The purpose of this project is for you to understand PWM, the differences between its RMS and Average value. You will be using analogRead and analogWrite functions to read and write from/to a specific pin. You will breadboard a circuit and test out your code. Objectives: This project has the following objectives: - To familiarize you with Arduino intergrated development environment (IDE). - To learn how to use analogWrite function to control the output RMS value of a PWM pin to control the LED brightness. - To use the LED to excite a photocell and read its value using analogRead function. - To use your program to control the rise time (tau) of the photocell. Notes: The RC time constant, also called tau, of a RC circuit is equal to the product of RC in seconds. It’s the time required to charge the capacitor from an initial zero to approximately 63.2% through the resistor. In this project, I don’t want you to hardwire your breadboard with RC components to control the rise time, but I want you to take advantage of the MCU and do it with software. Things to Do and Due Dates: - You will need to demonstrate your breadboard and program by Oct 7th. I’ll create a signup sheet for demo signing up and answer any questions that you might have regarding the project. Of course, you always can meet me during my office hours if needed. - You will need to write a formal engineering project report (due on Oct 14) on the following: using the collected PWM pin’s RMS and corresponding photocell values. - You need to find a function via regression curve fitting that provides the best fit to the specific curves in your dataset. - Thereafter, you will use the curve fitting function to predict and verify what a required PWM value should be for a given photocell value or vice versa. - With your experience using MCU to control tau via software, describe how one could use this MCU technique to control other applications’ rise time and its benefits. Step 1: Hardware required and breadboarding: - 1 LED (any color) - 1 photo resistor - (2) 1K Ohm resister - A few jumper cables - You will need a 1KOhm pull down resistor in series with the LED and photo resistor to avoid they draw too much current and burn up. - We will use the LED to provide excitation light to the photo resistor by placing it directly above and next to the LED. - Analog pin A0 will be used to read the photo resistor’s voltage. Step 2: Declaring variables: - DutyCycle as integer, rms and output as float Setup: - Set pin #5 as output. - To generate a PWM signal out of pin #5, use function analogWrite and write to pin #5 with the different duty cycles. Ex. analogWrite(5, dutyCycle). - Calculate rms = sqrt(dutyCycle/255.0) value and convert it to voltage. Remember that the range of the analogWrite function is 0 to 255. For average value, it is average = dutyCycle/255. - Set output = analogRead(A0); notes: the range of this function’s return value is 0-1023. Results: - For each dutyCycle value, compare and record the rms to A0 values (this is the photocell value), also compare and record the PWM’s rms vs average values (notes: this is pin#5’s values). - Extra work and credit: if you don’t want to hardcode dutyCycle value and want to challenge yourself, you can feed pin #5 with different values on-the-fly by using a potentiometer. You will need to feed the potentiometer to analog pin A1, read A1, convert it from 0-1023 to 0-255 and then use it as pin #5 dutyCycle.
Answered Same DayOct 07, 2021

Answer To: ENGR 294 Fall 2020 Prof: Mohamed Hajiaboli Project #1: PWM, RMS vs Average Using analogRead and...

Deep answered on Oct 13 2021
148 Votes
/*
I have used pin 5 to generate pwm for LED, which varies in range of 0-255; at 0 LED will be off
and at 255 LED will be brightest
pin A0 is selected to read ADC values of photocell resistor, when the brghtness of LED changes the excitation of photocell resistor changes accordingly and the adc values will be printed over com port.
the equation for the average pwm voltage, rms pwm voltage and adc output voltage has been implemented, and will be printed over comm. port at every 10m sec of interval.
as implemented in loop led will fire from 0 to 255 in approx 2 sec and when it...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here