



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lab experiment where an embedded system uses a photo sensor and led to maintain a constant light intensity environment. The system employs a pid controller to adjust the led's duty cycle based on the error between the desired and current light intensity. The document also includes the circuit diagram, switch functions, and initialization code for timer2 and port d.
Typology: Slides
1 / 5
This page cannot be seen from the preview
Don't miss anything!




This embedded system uses the Photo sensor to detect the light intensityof the environment and adjusts the light emitted by the LED to maintain aconstant light intensity environment.
You may need aresistor other thanexactly 2K forbetter sensitivity
22K
2K
To Computer
Serial Port
Sensor200K
V_Feedback
In this lab, the plantās function is to generate a desired levelof ambient light. The sensor measures ambient light with aCadmium Sulfide (CdS) photocell. The sensor measuresthe plantās performance.
ATMEGA16L
VTG
10K
150 SW
VTG
10K
SW1 150
PB0 PB1 PC
RXDTXD
To Computer
Serial Port
1415
1 2 22
LED
VCC
VTG
10K
150
VTG
10K
150 SW
PC
23
PB
3
VTG
10K
150 SW
PB
4
VTG
10K
150 SW
PB
5
LED
VCC
VTG
10K
150
LED
VCC
VTG
10K
LED
VCC
VTG
10K
LED
VCC
VTG
10K
150
150
150
PC
24
PC
25
PC
26
OC (PD7)
21
130
Ī©
Sensor 200K
Ī©
LED
ADC0(PA0)
40
VTG
V_Feedback
R
R
#include <mega16.h>
// Standard Input/Output functions
#include <stdio.h>
#include <math.h>
bit update = 0; // Update the duty cycle.
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
// Update every 100ms.
TCNT1H=0xE9;
TCNT1L=0x8A;
update = 1;
}
if( update )
{
// Read channel 0 adc.
adc_input = read_adc( 0x0 );
// Print the adc value.
//
printf( "Target Reading = %X\r", target_reading );
//
printf( "ADC Input = %X\r", adc_input );
// Find the difference between the adc input and
// the sensor reading.
error = adc_input - target_reading;
????/
Delta V as a Function of R
R1 Value (Ohms)
Delta V (V)
Theoretical Max Delta V as a Function of R
R1 Resistance (Ohms)
Delta V (V)
Response Time - Step Change from 30% LED Intensity to 80% LED Intensity
Time (s)
LED Intensity (ADC Integer Units)
iComiMeas
R11kOhm R21kOhm
Detector_Output
R
150 Ohm
LED
PWM_from_AVR
R41kOhm
R51kOhm
R61kOhm R71kOhm
VCC
5V
3_VDC_to_Aref
Software minimum requirements:(1)
SW0-SW4 are used to set the target level for the control loop.according to the following table
(2)
LED0-LED4 are used to indicate to the user which switch has beenpressed.
(3)
The percentage of the LED intensity is sent to the computer terminalthrough the serial port.Switch
Target Level
SW0 (100%)
Full LED intensity
SW1 (75%)
no_LED +((full_LED - no_LED)*3/4)
SW2 (50%)
no_LED +((full_LED - no_LED)/2)
SW3 (25%)
no_LED +((full_LED - no_LED)*1/4)
SW4 (0%)
No LED intensity