Hallo, ich probiere mit dem Atmega 8 und dem SN75176 ein DMX-Signal zu
Empfangen und damit 3 LED´s über PWM zu steuern.
Problem: Die LEDs leuchten wie gewollt je 1s auf, dannach geht die
Valid-LED an und die 3 LEDs Leuchten wie über DMX eingestellt.
Allerdings nur für ca. 1s, dannch gehen sie aus und machmal geht nach
ca. 5 weiteren Sekunden die ValiD-LED auch aus oder der Mega Resetet.
Am Atmega ist ein 16MHz Grundton mit 2 mal 22pF nach GND. Zwischen VCC
und GND ist ein 100nF und die Pins die für die DMX Adressen Einstellung
sind, liegen auf VCC, außer PinC.5 der liegt auf Ground, damit die
DMX-Adresse=1 ist. Restet ist über ein 10K Widerstand mit VCC verbunden.
1 | $regfile = "m8def.dat"
|
2 | $crystal = 16000000
|
3 | $baud = 250000
|
4 | 'USART auf DMX512 einstellen
|
5 | Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 2 , Databits = 8 , Clockpol = 1
|
6 | On Urxc Empfang
|
7 |
|
8 | Config Timer2 = Timer , Prescale = 1
|
9 | On Timer2 Soft_pwm
|
10 |
|
11 |
|
12 | Dim Dmx_tmp As Integer
|
13 | Dim X As Byte
|
14 | Dim Buffer(512) As Byte
|
15 | Dim Kanal As Word
|
16 | Dim Spwm1 As Byte
|
17 | Dim Spwm2 As Byte
|
18 | Dim Spwm3 As Byte
|
19 | Dim Valid As Byte
|
20 | Valid = 0
|
21 |
|
22 |
|
23 | Dim Count As Byte
|
24 | Config Portb.0 = Output
|
25 | Config Portb.1 = Output
|
26 | Config Portb.2 = Output
|
27 | Config Portb.3 = Output
|
28 |
|
29 | Config Portc.5 = Input
|
30 | Config Portc.4 = Input
|
31 | Config Portc.3 = Input
|
32 | Config Portc.2 = Input
|
33 | Config Portc.1 = Input
|
34 | Config Portc.0 = Input
|
35 | Config Portb.5 = Input
|
36 | Config Portb.4 = Input
|
37 | Config Portd.6 = Input
|
38 |
|
39 | Softpwm1 Alias Portb.1
|
40 | Softpwm2 Alias Portb.2
|
41 | Softpwm3 Alias Portb.3
|
42 |
|
43 | 'Alles LED´s Kurz zun Testen anmachen
|
44 | Softpwm1 = 1
|
45 | Wait 1
|
46 | Softpwm1 = 0
|
47 | Softpwm2 = 1
|
48 | Wait 1
|
49 | Softpwm2 = 0
|
50 | Softpwm3 = 1
|
51 | Wait 1
|
52 | Softpwm3 = 0
|
53 |
|
54 |
|
55 | Enable Interrupts
|
56 | Enable Urxc
|
57 | Enable Timer2
|
58 |
|
59 |
|
60 | Do
|
61 | Dmx_tmp = 0
|
62 | If Pinc.5 = 0 Then Dmx_tmp = Dmx_tmp + 1
|
63 | If Pinc.4 = 0 Then Dmx_tmp = Dmx_tmp + 2
|
64 | If Pinc.3 = 0 Then Dmx_tmp = Dmx_tmp + 4
|
65 | If Pinc.2 = 0 Then Dmx_tmp = Dmx_tmp + 8
|
66 | If Pinc.1 = 0 Then Dmx_tmp = Dmx_tmp + 16
|
67 | If Pinc.0 = 0 Then Dmx_tmp = Dmx_tmp + 32
|
68 | If Pinb.5 = 0 Then Dmx_tmp = Dmx_tmp + 64
|
69 | If Pinb.4 = 0 Then Dmx_tmp = Dmx_tmp + 128
|
70 | If Pind.6 = 0 Then Dmx_tmp = Dmx_tmp + 256
|
71 |
|
72 | If Dmx_tmp > 0 Then
|
73 |
|
74 | Spwm1 = Buffer(dmx_tmp)
|
75 | Spwm2 = Buffer(dmx_tmp + 1)
|
76 | Spwm3 = Buffer(Dmx_tmp + 2)
|
77 |
|
78 | Else
|
79 |
|
80 | Spwm1 = 0
|
81 | Spwm2 = 0
|
82 | Spwm3 = 0
|
83 | Valid = 0
|
84 |
|
85 | End If
|
86 |
|
87 | If Valid = 1 Then Portb.0 = 1 Else Portb.0 = 0
|
88 |
|
89 |
|
90 | Loop
|
91 |
|
92 |
|
93 | '--------------------------------------------------------------
|
94 | '
|
95 | 'Empfang:
|
96 | '
|
97 | 'steht in der USART ein Byte an, wird ein Interrupt
|
98 | 'ausgelöst und folgender Code abgearbeitet:
|
99 | '--------------------------------------------------------------
|
100 | Empfang:
|
101 | X = Udr
|
102 | If Ucsra.fe = 1 Then
|
103 | Kanal = 0
|
104 | If X = 0 Then Valid = 1 Else Valid = 0
|
105 | Else
|
106 | Incr Kanal
|
107 | If Kanal < 513 And Kanal > 0 Then Buffer(kanal) = X
|
108 | End If
|
109 |
|
110 | Return
|
111 |
|
112 | '--------------------------------------------------------------
|
113 | '
|
114 | 'SoftPMW:
|
115 | '--------------------------------------------------------------
|
116 |
|
117 | Soft_pwm:
|
118 |
|
119 | Incr Count
|
120 | If Count = 254 Then Count = 0
|
121 | If Count >= Spwm1 Then Softpwm1 = 0 Else Softpwm1 = 1
|
122 | If Count >= Spwm2 Then Softpwm2 = 0 Else Softpwm2 = 1
|
123 | If Count >= Spwm3 Then Softpwm3 = 0 Else Softpwm3 = 1
|
124 |
|
125 | Return
|