Professional Documents
Culture Documents
systems
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:
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; }
}
ADC2- for setting dimming time
}
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;}