Lab 5: Controls and Feedback - Light Intensity Regulation with ATMEGA16L, Slides of Computer Science

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

2012/2013

Uploaded on 03/22/2013

dhritiman
dhritiman šŸ‡®šŸ‡³

4.7

(6)

106 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
1
Lab 5: Controls and feedback
2
Lab 5: Control and Feedback
This embedded system uses the Photo sensor to detect the light intensity
of the environment and adjusts the light emitted by the LED to maintain a
constant light intensity environment.
You may need a
resistor other than
exactly 2K for
better sensitivity
22K
2K
3
ATMEGA16L
VTG
10K
150
SW0
VTG
10K
150
SW1
PB0
PB1
PC0
RXD
TXD
To Computer
Serial Port
14
15
1
2
22 LED0
VCC
VTG
10K
150
VTG
10K
150
SW2
PC1 23
PB2 3
VTG
10K
150
SW3
PB3 4
VTG
10K
150
SW4
PB4 5
LED1
VCC
VTG
10K
150
LED2
VCC
VTG
10K
LED3
VCC
VTG
10K
LED4
VCC
VTG
10K
150 150 150
PC2 24
PC3 25
PC4 26
OC2
(PD7)
21
130 Sensor
200K
LED
ADC0
(PA0)
40
VTG
V_Feedback
R2
R1
4
Lab 5: Controls and Feedback
• PID control
– P: Proportional
• The error signal (error = desired – current) multiplied by a
constant and fed out to the drive. (proportional = gain * error).
– I: Integral
• The integral term is the sum of past errors, so adding the
past errors will eventually drive the output closer to the
desired output
– D: Derivative
• Differentiator uses the derivative (rate of change) to predict
the future behavior.
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Lab 5: Controls and Feedback - Light Intensity Regulation with ATMEGA16L and more Slides Computer Science in PDF only on Docsity!

Lab 5: Controls and feedback

Lab 5: Control and Feedback

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

ATMEGA16L

VTG

10K

SW

VTG

10K

SW

PB0 PB

PC

RXDTXD

To Computer

Serial Port

LED

VCC

VTG

10K

VTG

10K

SW

PC

PB

VTG

10K

SW

PB

VTG

10K

SW

PB

LED

VCC

VTG

10K

LED

VCC

VTG

10K

LED

VCC

VTG

10K

LED

VCC

VTG

10K

PC

PC

PC

OC

(PD7)

Sensor200K

LED

ADC0(PA0)

VTG

V_Feedback

R

R

Lab 5: Controls and Feedback

PID control

– P: Proportional

• The error signal (error = desired – current) multiplied by a

constant and fed out to the drive. (proportional = gain * error).

– I: Integral

• The integral term is the sum of past errors, so adding the

past errors will eventually drive the output closer to thedesired output

– D: Derivative

• Differentiator uses the derivative (rate of change) to predict

the future behavior.

Docsity.com

Lab 5: Controls and 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.

Lab 5: Controls and Feedback

The choice of a controller depends on theapplication’s requirements.

This lab builds an application that uses the dutycycle of the PWM signal to dynamically adjustambient light levels.

The controller increases the duty cycle of thePWM in order to apply more power to the LEDand thereby increase its intensity. The PWM isthe control, u(t), that is fed into the plant (that is,LED).

Lab 5: Controls and Feedback

Changes to the LED’s intensity can occur as fast as themcu computes and updates the PWM duty cycle register(OCR2). For this application one updates every 100milliseconds is more than sufficient. One milli-second isvery slow compared to how fast ambient light fills aroom.

At speeds of human perception 100 milliseconds is fastbut detectable. These timing considerations drive therequirement for only needing to use a proportionalcontroller. Hint: A maximum change of 2% to 4% to theduty cycle every 50 - 100 ms implements a nice smoothtransition of the LED’s intensity

Lab 5: Controls and Feedback

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

Docsity.com

Lab 5: Controls and Feedback

#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;

}

Lab 5: Controls and Feedback

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;

  • •

????/

Lab 5: Controls and Feedback

+5 V

Sensor

Ground

R

Vout

Delta V as a Function of R

R1 Value (Ohms)

Delta V (V)

Lab 5: Controls and Feedback

Theoretical Max Delta V as a Function of R

R1 Resistance (Ohms)

Delta V (V)

Docsity.com

Lab 5: Controls and Feedback

Response Time - Step Change from 30% LED Intensity to 80% LED Intensity

Time (s)

LED Intensity (ADC Integer Units)

iComiMeas

Lab 5: Controls and Feedback

R11kOhm R21kOhm

VCC

5V

Detector_Output

R

150 Ohm

LED

PWM_from_AVR

R41kOhm

R51kOhm

R61kOhm R71kOhm

VCC

5V

3_VDC_to_Aref

Lab 5: Controls and Feedback

If no switches are pushed, do the PID code.

Measure the LED intensity (iMeas)

Compare to commanded intensity (iCom)

Error = iCom – iMeas

Limit error to +/- 10

New value of duty = old value of duty + error * 1.2.

Limit duty to range of 0 to 255

Write duty to PWM register

Output iCom, iMeas and duty on UART

Wait 50 ms to give ~ 10 Hz control time

If the switch is pushed, then change duty to new valueas determined by switch number

..... .. etc

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

Docsity.com