Hallo,
ich habe mir einen kleinen Dimmer gebaut der auch soweit sehr gut
funktioniert. Die Zero-Cross Erkennung und die Tryristor-Beschaltung
habe ich von http://www.hoelscher-hi.de/hendrik/light/dmxdimmer.htm
Hier mal mein Programm:
1 | #define F_CPU 8000000UL
|
2 | #include <avr/io.h>
|
3 | #include <avr/interrupt.h>
|
4 | #include <avr/pgmspace.h>
|
5 | #include <stdlib.h>
|
6 | #include <util/delay.h>
|
7 |
|
8 | volatile uint8_t i;
|
9 | volatile uint16_t ms;
|
10 | volatile uint8_t s;
|
11 | volatile uint8_t m;
|
12 | volatile uint16_t vorgabe;
|
13 | volatile uint16_t wert[160];
|
14 | volatile uint16_t B;
|
15 | volatile uint16_t B;
|
16 | volatile uint16_t C;
|
17 |
|
18 | ISR(INT0_vect)
|
19 | {
|
20 | TCNT1 = vorgabe; //Zündzeitpunkt vorgeben
|
21 | }
|
22 |
|
23 | ISR (TIMER1_OVF_vect)
|
24 | {
|
25 | PORTB=0x01; //Triac zünden
|
26 | _delay_us(20); //kurz warten bis Triac gezündet hat
|
27 | PORTB=0x00; //Triac Zündung ausschalten
|
28 | }
|
29 |
|
30 | ISR (TIMER0_OVF_vect)
|
31 | {
|
32 | TCNT0=131;
|
33 | ms=ms+1; //Millisekundenberechnung
|
34 | if (ms==1000){
|
35 | ms=0;
|
36 | s=s+1;
|
37 | }
|
38 | if (s==60){ //Sekundenberechnung
|
39 | s=0;
|
40 | m=m+1;
|
41 | }
|
42 | }
|
43 | int main(void)
|
44 | {
|
45 | B=64590;
|
46 | for (C = 0; C < 150; C++){ //Zündzeitpunkte
|
47 | B=B+5;
|
48 | wert[C]=B;
|
49 | }
|
50 | sei(); //Global Interrupt enable
|
51 | DDRB=0x01; //Portb.0 als Ausgang
|
52 | GICR |= (1<<INT0); //enable für Int0
|
53 | MCUCR |= (1<<ISC00); //Int0 bei fallender und steigender Flanke
|
54 | TCCR0 |= (1<<CS11) | (1<<CS10); //Prescale(64) für Timer0
|
55 | TCCR1B |= (1<<CS11) | (1<<CS10); //Prescale(64) für Timer1
|
56 | TIMSK |= (1<<TOIE0) | (1<<TOIE1); //Timer1 und Timer2 Overflow Interrupt enable
|
57 | i=1;
|
58 | while(1)
|
59 | {
|
60 | if (ms==30){ //langsames hochdimmen
|
61 | vorgabe=wert[i];
|
62 | i=i+1;
|
63 | ms=0;
|
64 | }
|
65 | if (i==150){
|
66 | TCCR0 &=0x00;
|
67 | i=0;
|
68 | }
|
69 | }
|
70 | }
|
Mein Problem ist das beim Timerwert zwischen 64890 - 64915 nur eine
Halbwelle von der Hardware angeschnitten wird obwohl das Programm es
richtig ansteuert. Kann mir vielleicht jemand bei diesem Problem helfen?