You are on page 1of 13

AUTO3230 Embedded

systems

Staircase Light Project

By kabinad & osama

Dec 15 2010
Resourse used
Hardware software
Arduino Uno Use AVR GCC (WinAVR )
Bread board Programmers

Push button
LED
Potentiometer
Transistor
Relay
Basic working principle
Basic working principle:

1. Light switch LED on, relay off


 Set the dimming time using pottentiometer
2. Push a light switch (push button)
3. Turn on the relay (with transistor)
Start timer 0
4. Start the LED dimming
 start timer 1
5. After a while, turn off the relay.
Main function

// Turn on the lamp


PORTB = (1<<PB2);
// set compare register initially
to maximum
OCR1A=ICR1;
While loop
while(1)
{
// Turn off the LED
PORTB = 0x01;

if(debounce(&PINB,PB3))
{
// set compare register initially to maximum
OCR1A=ICR1;
// set on the relay
PB2=0X02
//Timer/Counter1, Output Compare A Match Interrupt Enable
TIMSK1 |=(1<<OCIE1A);

}
}
16-bit Timer/Counter Block Diagram
Timer 0- for delay to switch of Relay
void initialise_timer0 (void)
ISR(TIMER0_OVF_vect)
{ { //set overflow point
TCNT0 = 0x38;//200
//Set Timer and prescaler to 8 count++;
TCCR0B|=(1<<CS01); if (count==50000)
{
//initialize the timer/counter register
TCNT0=0x00;
PORTB &= ~(1<<PB2);
count=0;
//enable the timer/counter overflow }
interrupt }
TIMSK0 |=(1<<TOIE0);

}
Timer 1- for dimming a led
ISR(TIMER1_COMPA_vect)
void initialise_timer1 (void) {
{

//Clear OC1A/OC1B on Compare Match (Set // //if the bulb is off start the dimming
output to low level). if( ~(1<<PB2)==1)
//select fast PWM
//selecte prescaler to 8
TCCR1A=((0x01<<COM1A0)| {
(0x01<<WGM11)); // if OCSRA is bigger than 0 decrease the
TCCR1B=((0x01<<CS11)| value by 1000
(0x01<<WGM13)|(0x01<<WGM12)); if(OCR1A > 0)
//Set ICR1 to determine the period T {
//ICR1=read from pinc2
//Set the output compare Set OCR1A OCR1A-=100;
register (OCR1A) }
//OCR1A=ICR1; }

//enable the timer/counter overflow


interrupt }
TIMSK1 |= (1<<OCIE1A) ;

}
ADC2- for setting dimming time

void ADC_initialize (void)


{
//select channel 2
ADMUX|=(1<<MUX1);

//Enable ADC, set ADSC, enable interrupt, set prescaler


ADCSRA|=(1<<ADEN)|(1<<ADIE)|(1<<ADPS2)|(1<<ADSC);

}
ADC CH 2- for setting dimming time
ISR(ADC_vect)
Input volt OCR1A
{
uint16_t data;
From pote..meter
data=ADCL;
data+=(ADCH<<8);
0-1 12000
if( (data<(1*1023/5)) )|( (data>0) )
{ ICR1=12000;}

if( (data<(2*1023/5)) |( (data>(1*1023/5)) ) 1-2 24000


{ ICR1=24000;}

if( (data<(3*1023/5)) |( (data>(2*1023/5)) ) 2-3 36000


{ ICR1=36000;}

if( (data<(4*1023/5)) |( (data>(3*1023/5)) )


{ ICR1=48000;} 3-4 48000

if( (data<(5*1023/5)) |( (data>(4*1023/5)) )


{ ICR1=60000;} 4-5 60000
ADCSRA|=(1<<ADSC);
}
Debounce function
static inline uint8_t debounce(volatile uint8_t *port, const uint8_t pin)
{
if(!(*port & (1 << pin)))
{
// pin grounded, wait 100 ms
_delay_ms(100);
if(*port & (1 << pin))
{
// give the user time to release the button
_delay_ms(100);
return 1;
}
}
return 0;
}

You might also like