Forum: Mikrocontroller und Digitale Elektronik DMX Demultiplexer (Atmega8515-16)


von Rouven F. (Firma: Keine) (madmax1973)


Angehängte Dateien:

Lesenswert?

Hallo Leute ich brauche mal etwas Hilfe von den Programmieren unter 
euch.
Ich bin gerade dabei mir einen DMX Demultiplexer aufzubauen.
Projekt habe ich im Netz gefunden allerdings möchte ich das ding etwas 
modifiziert haben. Und zwar ist das ein Analog Demux Spannung am Ausgang 
von 0-5V je nach DMX Wert. Ich möchte es aber so haben das der Ausgang 
TTL wird dh. ab dem DMX wert 127 einfach an dh. auf den Ausgang 5V. 
Dafür müsste der Code umgeschrieben werden bzw angepasst. Der Code ist 
offiziell verfügbar und darf auch geändert werden.

1
;**** A P P L I C A T I O N   N O T E   ************************************
2
;*
3
;* Title    : 8ch DMX512 Demultiplexer 
4
;* Version    : v1.2
5
;* Last updated          : 02.11.07
6
;* Target    : Transceiver Rev.3.01 [ATmega8515]
7
;*
8
;* written by hendrik hoelscher, www.hoelscher-hi.de
9
;***************************************************************************
10
; This program is free software; you can redistribute it and/or 
11
; modify it under the terms of the GNU General Public License 
12
; as published by the Free Software Foundation; either version2 of 
13
; the License, or (at your option) any later version. 
14
;
15
; This program is distributed in the hope that it will be useful, 
16
; but WITHOUT ANY WARRANTY; without even the implied warranty of 
17
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
18
; General Public License for more details. 
19
;
20
; If you have no copy of the GNU General Public License, write to the 
21
; Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
22
;
23
; For other license models, please contact the author.
24
;
25
;***************************************************************************
26
27
.include "m8515def.inc"
28
29
;Register and Pin definitions
30
31
.def tempL         = r16
32
.def tempH        = r17
33
.def Flags        = r18
34
.def DMXstate      = r19
35
.def null        = r2
36
.def status        = r3
37
.def IndPat        = r4
38
.def dimm_count      = r20
39
.def SREGbuf      = r5
40
41
.equ DMX_FIELD=    0x60     ;SRAM-Beginn
42
.equ DMX_CHANNELS= 8
43
.equ PWM_FIELD=     0x68
44
.equ F_OSC=        8000
45
.equ WIDTH=        105      ;Offset zwischen Steps
46
.equ IND_OFFSET=   550       ;Offset für indicator-Timer (14Hz)
47
48
;***** special Flags
49
50
#define  VALID_DMX       (0)
51
#define  SIGNAL_COMING  (1)
52
53
#define  DO_IND      (6)
54
#define  DATA_REFRESHED (7)
55
#define  DATA_IND    (7)
56
57
58
59
;interrupt vectors
60
  
61
  rjmp init     ;reset vector address
62
  reti      ;External Interrupt0 Vector Address
63
  reti      ;External Interrupt1 Vector Address
64
  reti      ;Input Capture1 Interrupt Vector Address
65
  rjmp LED_indicator    ;Output Compare1A Interrupt Vector Address
66
  reti      ;Output Compare1B Interrupt Vector Address
67
  reti      ;Overflow1 Interrupt Vector Address
68
  reti      ;Overflow0 Interrupt Vector Address
69
  reti      ;SPI Interrupt Vector Address
70
  rjmp get_byte  ;UART Receive Complete Interrupt Vector Address
71
  reti      ;UART Data Register Empty Interrupt Vector Address
72
  reti      ;UART Transmit Complete Interrupt Vector Address
73
  reti      ;Analog Comparator Interrupt Vector Address
74
  reti      ;External Interrupt2 Vector Address
75
  rjmp pwm    ;Output Compare0 Interrupt Vector Address
76
  reti      ; EEPROM Interrupt Vector Address
77
  reti      ; SPM complete Interrupt Vector Address
78
  reti      ; SPM complete Interrupt Vector Address
79
80
; INIT
81
82
init:
83
84
; Stack
85
  ldi    tempH,high(RAMEND)
86
  ldi    tempL,low(RAMEND)
87
  out    SPH,tempH
88
  out    SPL,tempL
89
90
; WATCHDOG
91
  wdr
92
  ldi   tempL, (1<<WDE)|(1<<WDCE)
93
  out   WDTCR, tempL
94
  ldi   tempL, (1<<WDE)|(1<<WDCE)|(1<<WDP2)|(1<<WDP1)
95
  out   WDTCR, tempL
96
  wdr                        ;set prescaler @0,5s
97
98
; PortA
99
  ser   tempL
100
  out   DDRA, tempL
101
  clr   tempL
102
  out   PortA, tempL               ;low Outputs
103
104
; PortB
105
  ;**unused**
106
107
; PortD
108
  ldi   tempL, 0b10000100
109
  out   DDRD, tempL
110
  ldi   tempL, 0b01111000
111
  out   PortD, tempL               ;DMX & Spare , LED1 on
112
113
; PortE
114
  ldi   tempL, 0b00000001
115
  out   DDRE, tempL
116
  ser    tempL
117
  out   PortE, tempL               ;LED2 off, BIT9 & OPTION Pullup
118
119
; Timers
120
  ldi   tempL, (1<<CS00)|(1<<WGM01)        ;set counter0 @clock frequency, CTC mode
121
  out   TCCR0, tempL
122
  ldi    tempL, WIDTH
123
  out    OCR0, tempL
124
  clr    tempL
125
  out    TCCR1A, tempL
126
  ldi   tempL, (1<<CS10)|(1<<CS12)|(1<<WGM12)   ;set counter1 @clock/1024 frequency
127
  out   TCCR1B, tempL
128
  ldi    tempL, low(IND_OFFSET)
129
  ldi    tempH, high(IND_OFFSET)
130
  out    OCR1AH, tempH
131
  out    OCR1AL, tempL
132
  ldi   tempL,   (1<<OCIE0)|(1<<OCIE1A)      ;aktivate compare interrupts
133
  out   TIMSK, tempL
134
    
135
  rcall  init_dmx
136
  rcall  init_indicate
137
  
138
; set Register
139
  clr   null
140
  ldi   dimm_count, 0xFF
141
  ldi    Flags, 0                ;clear Flags
142
  
143
; memory
144
    ldi    ZH, high(PWM_FIELD)
145
    ldi    ZL,  low(PWM_FIELD)
146
    ldi   tempL, DMX_CHANNELS
147
  write_mem:  
148
    st     Z+, null
149
    dec    tempL
150
    brne  write_mem    
151
152
    wdr
153
    sei
154
155
    clr   tempL                ;wait for perepherials 
156
    clr    tempH
157
  init_loop:
158
    dec    tempL
159
    brne  init_loop
160
    dec    tempH
161
    brne  init_loop
162
163
main:   sbrs  Flags, DO_IND
164
    rjmp  main
165
    cbr    Flags, (1<<DO_IND)
166
    rcall  indicate_flags            ;LED indicator
167
168
    rjmp  main
169
170
; ***************************PWM-Ausgabe ****************************************
171
pwm:              ; CALLED EVERY 12.5µs (80kHz)
172
    in      SREGbuf, SREG
173
    push  tempL
174
175
176
    ldi    ZH,high(PWM_FIELD)      ;set data-pointer  
177
    ldi    ZL,low(PWM_FIELD);
178
179
180
      ld    tempL,Z+          ;1
181
    cp    tempL, dimm_count
182
    ror    status
183
    ld    tempL,Z+          ;2
184
    cp    tempL, dimm_count
185
    ror    status
186
    ld    tempL,Z+          ;3
187
    cp    tempL, dimm_count
188
    ror    status
189
    ld    tempL,Z+          ;4
190
    cp    tempL, dimm_count
191
    ror    status
192
    ld    tempL,Z+          ;5 
193
    cp    tempL, dimm_count
194
    ror    status
195
    ld    tempL,Z+          ;6 
196
    cp    tempL, dimm_count
197
    ror    status
198
    ld    tempL,Z+          ;7 
199
    cp    tempL, dimm_count
200
    ror    status
201
    ld    tempL,Z            ;8 
202
    cp    tempL, dimm_count
203
    ror    status
204
205
206
      sbic  PinD, PD4
207
      com    status
208
      out   PORTA,status  ;fire
209
      
210
    sbrc  dimm_count, 7
211
    rjmp  pwm_inc
212
    sbr    dimm_count, (1<<7)      ;toggle msb
213
     pwm_exit:
214
    pop    tempL
215
    out     SREG, SREGbuf
216
    reti
217
218
  
219
  pwm_inc:
220
    inc    dimm_count
221
    cbr    dimm_count, (1<<7)
222
    tst    dimm_count
223
    brne  pwm_exit
224
225
    ldi    dimm_count, 0x80
226
    out    TCNT0, null
227
228
    ldi    ZH,high(DMX_FIELD)      ;refresh  
229
    ldi    ZL,low(DMX_FIELD);
230
    ld    tempL, Z+
231
    std    Z +7, tempL
232
    ld    tempL, Z+
233
    std    Z +7, tempL
234
    ld    tempL, Z+
235
    std    Z +7, tempL
236
    ld    tempL, Z+
237
    std    Z +7, tempL
238
    ld    tempL, Z+
239
    std    Z +7, tempL
240
    ld    tempL, Z+
241
    std    Z +7, tempL
242
    ld    tempL, Z+
243
    std    Z +7, tempL
244
    ld    tempL, Z
245
    std    Z +8, tempL
246
247
    rjmp  pwm_exit
248
249
    
250
;****************************** LED INDICATOR ***********************************
251
252
LED_indicator:
253
    in      SREGbuf, SREG
254
    wdr            ;reset Watchdog
255
    sbr    Flags, (1<<DO_IND)
256
    out    SREG, SREGbuf
257
    reti
258
259
260
nix: rjmp nix
261
262
263
.include "lib_dmx_in.asm"
264
.include "lib_indicate.asm"

im Anhang auch mal die drei original Dateien die dem Projektarchiv 
angehören.

schönen Gruss

von Max D. (max_d)


Lesenswert?

Willst du einen fertigen DMX-Demultiplexer haben ?
oder willst du verstehen wie alles funktioniert ?

von Rouven F. (Firma: Keine) (madmax1973)


Lesenswert?

Klar möchte ich verstehen was am Code geändert werden muss :-) die 
Platine ist fertig geht jetzt nur noch um den geänderten Code

: Bearbeitet durch User
von Max D. (max_d)


Lesenswert?

Der Code in diesem Projekt ist optimierter Assemblercode und dafür 
ausgelegt an PORTA die Soft-PWM zu machen. Als Anfangspunkt nicht ideal. 
Wenn es nur um das "geht irgendwie" geht, dann kann man die PWM-Funktion 
unterdrücken indem man dem "dimm_count" register einen festen 
Schwellwert (127) zuweißt anstatt es zu inkrementieren.


Die "saubere" Lösung wäre allerdings den Code entsprechend neu zu 
schreiben.

Wenn du das Gesamtkonzept verstehen willst, dann würde ich dir empfehlen 
ein komplett eigenes Projekt zu basteln. DMX ist von den Ansprüchen ja 
relativ überschaubar.

von Rouven F. (Firma: Keine) (madmax1973)


Lesenswert?

Komplett neu schreiben wäre sicherlich die beste Lösung und auch um es 
zu verstehen. Das würde ich im zweiten schritt machen. Im moment geht es 
mir erstmal darum zu testen ob das was ich mit dem Demux vor habe so 
überhaupt läuft. Darum würde mir für den Anfang hauptsache geht erstmal 
reichen.

von Max D. (max_d)


Lesenswert?

Dann würde ich wie gesagt einfach dimm_count mit 127 laden und die 
increment routine rausschmeißen.

Ist aber wie gesagt etwas pfuschig, aber sollte funktionieren.

von Rouven F. (Firma: Keine) (madmax1973)


Lesenswert?

Hast du ein Beispiel wie ich das im Code ändern muss ?
Kenne mich mit assembler nicht aus

von janku88 (Gast)


Lesenswert?

Hallo,

bin beim Suchen auf diesen Beitrag gestoßen, da ich das gleiche machen 
will um Relais für ein Switchpack damit anzusteuern.

Mit den Denkanstößen von hier bin ich am Ende drauf gekommen. Die 
Änderungen sind ziemlich übersichtlich.
Vieleicht ist das Problem hier ja noch aktuell ;)

Im Bereich "PWM-Ausgabe" Unterprogramm pwm:
Für alle Känle Die Zeilen "cp tempL, dimm_count" (vergleiche DMX Wert 
mit PWM Counter) auskommentieren oder löschen und "cpi tempL, 0x80" 
(vgl. DMX mit Konstante) an der gleichen Stelle einfügen. Die Konstante 
kann für jeden Kanal unterschiedlich, je nachdem wo der Schaltpunkt hin 
soll, angepasst werden (0 bis 255; hier im Beispiel 128)

  ld tempL, Z+          ;1
  ;cp tempL, dimm_count
  cpi tempL, 0x80
  ror status

Zusätzlich kann zum Umschalten aller Kanäle zwischen low/high aktiv die 
Zeile "com status" aus-/einkommentiert werden.

Viele Grüße

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.