Technické údaje:
Napájanie: 12V (9-30V)
Kľudový odber <15mA
Odber v zopnutom stave <100mA
Popis:
Po naštartovaní auta sa zvýši napätie nad 13V a svetlá sa nám automaticky rozsvietia. Najskôr sa rozsvietia parkovacie svetlá a sekundu na to sa zapnú stretávacie svetla.
Pri poklese napätia pod 13V nastane akustická signalizácia. Svetla však ostanú svietiť. To môže nastať napríklad, ak nám motor nechtiac zhasne. Ak po zapnutí zapaľovania, do minúty napätie neprekročí hodnotu 13V, nastane akustická signalizácia.
Činnosť automatického zapnutia môžeme deaktivovať pomocou vypínača svetiel - treba zapnúť a následne vypnúť parkovacie svetla.
Srdcom celého zariadenia je MCU Atmega8, do ktorej je potrebné napáliť firmware, ktorý je priložený v prílohe. Na nápalenie použijeme programátor ISP. Schéma celého zapojenia je na obrázku nižšie.
Schéma :
Kód v c:
/*****************************************************
Project : AUDI AutoLight
Version : 5
Date : 20/12/2012
Author : miko
Company : MKelectronic
Comments:
Chip type : ATmega8
Program type : Application
Clock frequency : 1.000000 MHz (internal RC)
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
#include <delay.h>
#define FIRMWARE_VERSION 5
#define ADC_VREF_TYPE 0xC0
#define CHARGING_VOLTAGE 13000 //mV
#define MEAS_CYCLE 128 //voltage measure samples
#define INT0_CYCLE 255 //int0 samples
#define ALARM PORTD.1 //buzzer
#define STATUS PORTD.4 //led
#define SW_LIGHT1 PORTD.5 //main lights
#define SW_LIGHT2 PORTD.6 //parking lights
#define EXT1 PIND.2 //int0 - manual parking switch
void alarm(const unsigned char repeat);
void lights(const unsigned char enable);
// global variables
bit engine=0;
bit lights_on=0;
bit force_off=0;
unsigned int measured_voltage[MEAS_CYCLE];
unsigned char measure_cycle=0;
unsigned char pre_start=255;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
unsigned char valid_int0=INT0_CYCLE;
//1'st ext0 = switch on parking lights manually.
//Change interrupt sense (falling edge -> rising edge)
if(!(MCUCR&0x03))
{
while(--valid_int0)
{
delay_ms(3);
if(EXT1)
return;
}
//parking lights already switched on => DON'T SWITCH ON LIGHTS
if(!lights_on)
force_off=1;
MCUCR|=0x03;
return;
}
//2'nd ext0 = switch off parking lights manually.
//disable lights
if((MCUCR&0x03)==0x03)
{
while(--valid_int0)
{
delay_ms(3);
if(!EXT1)
return;
}
force_off=1;
GICR&=0xBF; //disable INT0
return;
}
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
if(--pre_start==0)
TCCR0=0;
}
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
TCCR1B=0;
}
// Timer 2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
STATUS=~STATUS;
#asm("cli")
delay_ms(100);
#asm("sei")
}
// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{
unsigned int adc_data;
unsigned char i;
unsigned char voltage_ok=0;
unsigned char voltage_ng=0;
// Read the AD conversion result
adc_data=ADCW;
//store measured voltage [mV]
measured_voltage[measure_cycle]=(int)(adc_data*2.56*6.5); //5.681 - calculated voltage divider
//check measured conditions
for(i=0;i<MEAS_CYCLE;i++)
{
if(measured_voltage[i]>CHARGING_VOLTAGE)
voltage_ok++;
else
voltage_ng++;
}
//reset array index
if(++measure_cycle==MEAS_CYCLE)
measure_cycle=0;
// check charging voltage condition (all samples must be valid)
if(voltage_ok==MEAS_CYCLE)
{
engine=1;
STATUS=0; //Status LED
}
if(voltage_ng==MEAS_CYCLE)
{
engine=0;
STATUS=1;
}
}
void alarm(const unsigned char repeat)
{
unsigned char i;
//ignore alarms less than 1min after start
if(pre_start)
return;
for(i=0;i<repeat;i++)
{
// Beeper
#asm("cli")
ALARM=1;
delay_ms(150);
ALARM=0;
delay_ms(80);
#asm("sei")
}
TCCR1B=0x03;
while(TCCR1B);
}
void lights(const unsigned char enable)
{
switch(enable)
{
//turn off
case 0:
SW_LIGHT1=0; //disable xenon lights
SW_LIGHT2=0; //disable parking lights
TCCR2=0x07; //blink status led
lights_on=0;
break;
//turn on
case 1:
#asm("cli")
SW_LIGHT2=1; //switch on parking lights
delay_ms(1000); //delay for sure :)
SW_LIGHT1=1; //switch on xenon lights
ALARM=1;
delay_ms(700);
ALARM=0;
lights_on=1;
#asm("sei")
break;
}
}
void main(void)
{
unsigned char j;
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=Out Func5=Out Func4=Out Func3=In Func2=In Func1=Out Func0=In
// State7=T State6=0 State5=0 State4=1 State3=T State2=T State1=0 State0=T
PORTD=0x10;
DDRD=0x72;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 0.977 kHz
TCCR0=0x05;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 15.625 kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 0.977 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: Off
GICR|=0x40;
MCUCR=0x00;
GIFR=0x40;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x45;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 7.813 kHz
// ADC Voltage Reference: Int., cap. on AREF
ADMUX=ADC_VREF_TYPE | 0x04;
ADCSRA=0xEF;
//signalize FW version
for(j=0;j<FIRMWARE_VERSION;j++)
{
STATUS=0;
delay_ms(80);
STATUS=1;
delay_ms(150);
}
// Global enable interrupts
#asm("sei")
while (1)
{
//MANUAL MODE
if(force_off)
{
//manual switch on then off parking lights -> TURN OFF LIGHTS!
lights(0);
}
//AUTO MODE
else
{
//engine is running, ligths aren't lighting yet -> TURN ON LIGHTS!
if(engine && !lights_on)
lights(1);
//low voltage during engine run -> ALARM!
if(lights_on && !engine)
alarm(3);
//low voltage after 1min of engine run -> ALARM!
if(!lights_on && !engine)
alarm(5);
}
};
}
Model a hotový výrobok :
Zapojenie do auta :
Pred samotnou montážou odpojíme akumulátor (autobateriu) . Kombinovaný spínač svetiel vyberieme zatlačením otočného prepínača a ľahkým pootočením do prava.
Zapojenie konektora :
| 58R ( Parking_R) | 1 |
| 30 (+BAT) | 2 |
| 58L (Parking_L) | 3 |
| 31 (GND) | 4 |
| 56 (LIGHT) | 5 |
| 58 (osvetlenie EČV) | 6 |
| Xz | 7 |
Záver :
Toto zariadene inštalujeme do svojho auta na vlastne riziko. Autor tohto článku nenesie žiadnu zodpovednosť za spôsobené škody.







