From 74817f66643cbb78df5cf8913681fd75a20f4cd5 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 14 Jul 2016 19:54:48 -0400 Subject: [PATCH] With a history of three pulses, this can track up a 10% sine variation in a 1010101 stream. So I guess this'll do for now? --- .../Mac/Clock SignalTests/DPLLTests.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/OSBindings/Mac/Clock SignalTests/DPLLTests.swift b/OSBindings/Mac/Clock SignalTests/DPLLTests.swift index 042f22940..ada109d86 100644 --- a/OSBindings/Mac/Clock SignalTests/DPLLTests.swift +++ b/OSBindings/Mac/Clock SignalTests/DPLLTests.swift @@ -39,4 +39,23 @@ class DPLLTests: XCTestCase { let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, tolerance: 20, historyLength: 5) testRegularNibblesOnPLL(pll, bitLength: 110) } + + func testTenPercentSinePattern() { + let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, tolerance: 20, historyLength: 3) + var angle = 0.0 + + // clock in two 1s, a 0, and a 1, 200 times over + for _ in 0 ..< 200 { + let bitLength: UInt = UInt(100 + 5 * sin(angle)) + + pll.runForCycles(bitLength/2) + pll.addPulse() + pll.runForCycles((bitLength*3)/2) + + angle = angle + 0.1 + } + + let endOfStream = (pll.stream&0xffffff); + XCTAssert(endOfStream == 0xaaaaaa || endOfStream == 0x555555, "PLL should have synchronised and clocked repeating 0xa or 0x5 nibbles; got \(String(pll.stream, radix: 16, uppercase: false))") + } }