Hier gibt es viele verschiedene, die meist ähnlich funktionieren. Man sollte aufpassen, dass man die richtige Spannung anlegt. Dies ist mit einem Spannungsteiler sehr einfach.
Den Ausgang des Moduls schliesst man am Anlaogport des NXT an (weisses Kabel). Für die Programmierung ist wichtig, und ob man einen invertierten (0V entsprechen logisch 1) oder „normalen“ (0V entsprechen logisch 0) Ausgang hat.
Ich habe das DCF1-Modul von Pollin verwendet. Dieser benötigt zusätzlich eine fallende Flanke am PON-Port (PowerOn/Down), damit das Modul beginnt zu arbeiten. Diese Flanke kann man mit einem Ausgang (z.B. DIGI0; gelbes Kabel) realisieren.
Generell sind die Module teilweise sehr störanfällig. Daher die Antenne möglichst weit vom Rechner, Monitor und NXT entfernt benutzen.
Prototyp:
Anschlussbelegung am DCF77-Modul (von links nach rechts):
- VCC: Spannungsteiler mit je 1K-Widerstand an Masse (schwarz) und 4,3V-Power (grün)
- GND: Masse (schwarz)
- Data: Analogeingang am NXT (Weiss)
- PON: mit 1K-Widersatnd an DIGI0 (gelb)
Hier ein Beispielprogramm in pbLua. Das sollte in anderen Sprachen ähnlich leicht sein.
-- test dcf77 module dcf1 on NXT -- 01.07.2013 -- pblua 2.0RC2 port = 1 nxt.InputSetType(port, 0x09) -- custom sync = false time1 = 0 dcf = {} sec = 0 min = 0 hour = 0 day = 0 month = 0 year = 0 threshold = 200 -- threshold between logical 0 and 1 at the ad sensor function delay(ticks) local t = nxt.TimerRead() repeat until(t+ticks < nxt.TimerRead() ) end -- activate DCF module with falling edge of the signal at PON nxt.InputSetDir(port, 1, 0) nxt.InputSetState(port, 1, 0) delay(500) nxt.InputSetState(port, 0, 0) -- test signal repeat print( nxt.TimerRead(), nxt.InputGetStatus(port) ) delay(50) button = nxt.ButtonRead() until( 8 == button ) -- read DCF77 signal nxt.InputSetDir(port, 0, 0) oldTimer = nxt.TimerRead() repeat value = nxt.InputGetStatus(port) if (value > threshold) then newState = 0 else newState = 1 end if not (newState == oldState) then newTimer = nxt.TimerRead() if newState == 1 then time1 = newTimer - oldTimer elseif (time1 > 0) then time0 = newTimer - oldTimer -- print (string.format("%4i %4i", time0, time1)) -- debug if (time0 > 1800) and (time0 < 2000) then sec = 0 if sync then min = dcf[21] + 2*dcf[22] + 4*dcf[23] + 8*dcf[24] + 10*dcf[25] + 20*dcf[26] + 40*dcf[27] hour = dcf[29] + 2*dcf[30] + 4*dcf[31] + 8*dcf[32] + 10*dcf[33] + 20*dcf[34] day = dcf[36] + 2*dcf[37] + 4*dcf[38] + 8*dcf[39] + 10*dcf[40] + 20*dcf[41] month = dcf[45] + 2*dcf[46] + 4*dcf[47] + 8*dcf[48] + 10*dcf[49] year = dcf[50] + 2*dcf[51] + 4*dcf[52] + 8*dcf[53] + 10*dcf[54] + 20*dcf[55] + 40*dcf[56] + 80*dcf[57] else sync = true end elseif (time1 > 50) and (time1 < 150) and (time0 > 850) and (time0 < 950) then dcf[sec] = 0 sec = sec + 1 elseif (time1 > 150) and (time1 < 250) and (time0 > 750) and (time0 < 850) then dcf[sec] = 1 sec = sec + 1 else sync = false end if sync then print(string.format("%02i.%02i.%04i %02i:%02i:%02i", day, month, year, hour, min, sec)) else print("scanning...") end end oldState = newState oldTimer = newTimer end button = nxt.ButtonRead() until( 8 == button )