R2=7kΩ when light is ON / gdy światło jest włączone
VCC=5V
Vain1=R2/(R1+R2)
Vain0=1,2V internal source / źródło wewnętrzne
R1____R2: 3kΩ____7kΩ____15kΩ
43kΩ ____0,3V____0,7V____2V
20kΩ ____0,6V____1,4V____2,2V
for /dla R2=43kΩ Uain1=(0,3V-2V) trip point below 7kΩ / przełączenie poniżej 7kΩ
/*
file:Attiny_wyl.c
MCU: Attiny2313
Date: 05.III.2010
rev: 00
Author: Przemysław Sitek
Used ports:
PORTB 1 AIN1
PORTD 6 RELAY
CHANGES:
05.III.2010 project start */
#include "avr\io.h"
#include "avr\interrupt.h"
#define F_CPU 8000000UL // 8 MHz
#include "util\delay.h"
//delay 30min
void delay30min(void) {
uint8_t i;
uint8_t j;
for(j=0;j<240;j++) { // x/4 min 120/4=30min
for(i=0;i<100;i++) { //15s
_delay_ms(10);
}
}
}
//delay 4s
void delay4s(void) {
uint8_t i;
for(i=0;i<33;i++) { //4s
_delay_ms(10);
}
}
// INTERRUPT for analog comparator vector
ISR(ANA_COMP_vect) {
if bit_is_clear(ACSR, ACO){
delay4s();
if bit_is_clear(ACSR, ACO){
PORTD|=(0x01<<6); // relay is OFF
delay4s();
}
}
else {
delay4s();
if bit_is_set(ACSR, ACO){
PORTD&=~(0x01<<6); // relay is ON
delay30min();
PORTD|=(0x01<<6); // relay is OFF
ACSR&=~(0x01<<5); // AC output 0
delay4s();
}
}
}
int main(void) {
DDRD|=(0x01<<6); // relay as OUTPUT
PORTD|=(0x01<<6); // relay is OFF
DDRB&=~(0x01); // AIN0 as INPUT
DDRB&=~(0x01<<1); // AIN1 as INPUT
PORTB&=~(0x01); // AIN0 no pull-up
PORTB&=~(0x01<<1); // AIN1 no pull-up
// ANALOG COMPARATOR settings
ACSR|=(0x01<<6)|(0x01<<3)|(0x01<<1); // raising egde
ACSR&=~(0x01<<7)&~(0x01<<2)&~(0x01);
// ENABLE INTERRUPTS
sei();
while(1) { // Infinite loop
}
}
Light control / Sterownik Światła
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment