1212SERVO_PROFILES = 4 # number iir coefficient profiles per servo channel
1313SERVO_CHANNELS = 2 # number servochannels
1414
15+ ADC_DATA_WIDTH = 16 # bits per adc channel
1516
1617class PWM (Module ):
1718 """Pulse width modulation"""
@@ -46,6 +47,7 @@ def __init__(self, platform):
4647 platform .add_period_constraint (eem .data0_p , 4.0 * 8 )
4748 self .submodules .crg = CRG (platform , link = self .link .phy .clk )
4849 # Don't bother meeting s/h for the clk iserdes. We align it.
50+ platform .add_false_path_constraint (eem .data0_p , self .crg .cd_sys .clk )
4951 platform .add_false_path_constraint (eem .data0_p , self .crg .cd_sys2 .clk )
5052 self .submodules .decoder = Decode (
5153 b_sample = 14 , n_channel = 2 , n_mux = 8 , t_frame = 8 * 10
@@ -154,6 +156,27 @@ def __init__(self, platform):
154156 Register (read = False ),
155157 )
156158 )
159+
160+ # place holder for miqro register
161+ # 0x72 - 0x78 Miqro channel profile/window memories
162+ for i in range (7 ):
163+ phaser_registers .append (
164+ (
165+ f"miqro_mem{ i } " ,
166+ Register (),
167+ )
168+ )
169+
170+ # add adc data registers
171+ # 0x79-0x7c
172+ for ch in range (SERVO_CHANNELS ):
173+ for loc in ["lo" , "hi" ]:
174+ phaser_registers .append (
175+ (
176+ f"adc_data{ ch } _{ loc } " ,
177+ Register (write = False ),
178+ )
179+ )
157180
158181 self .decoder .map_registers (phaser_registers )
159182
@@ -242,7 +265,7 @@ def __init__(self, platform):
242265 # Note that there is one extra cycle (4 ns) at the end of a transaction.
243266 # Total: 264 ns -> 3.788 MSps
244267 adc_parameters = AdcParams (
245- width = 16 , channels = 2 , lanes = 2 , t_cnvh = 8 , t_conv = 3 , t_rtt = 6
268+ width = ADC_DATA_WIDTH , channels = 2 , lanes = 2 , t_cnvh = 8 , t_conv = 3 , t_rtt = 6
246269 )
247270
248271 self .submodules .adc = adc = Adc (platform .request ("adc" ), adc_parameters )
@@ -255,8 +278,8 @@ def __init__(self, platform):
255278
256279 # log2_a0 = 14 bit for an effective fixedpoint a0 of 0.5
257280 self .submodules .iir = iir = Iir (
258- w_coeff = 16 ,
259- w_data = 16 ,
281+ w_coeff = 16 ,
282+ w_data = ADC_DATA_WIDTH ,
260283 log2_a0 = 14 ,
261284 n_profiles = SERVO_PROFILES ,
262285 n_channels = SERVO_CHANNELS ,
@@ -266,6 +289,23 @@ def __init__(self, platform):
266289 iir .stb_in .eq (adc .done ),
267290 ]
268291
292+ # add adc data to adc data register
293+ for ch in range (SERVO_CHANNELS ):
294+ assert SERVO_CHANNELS <= len (adc .data )
295+ sample_reg = Signal ((16 , True ), name = f"adc_sample_reg_{ ch } " )
296+ self .sync += If (adc .done , sample_reg .eq (adc .data [ch ]))
297+ # self.sync += If(adc.done, sample_reg.eq(0xFFFF))
298+
299+ # expose the registered value to the decoder read ports combinatorially
300+ # split into low / high bytes to match the two Register() entries
301+ self .comb += [
302+ self .decoder .get (f"adc_data{ ch } _lo" , "read" ).eq (sample_reg [0 :8 ]),
303+ self .decoder .get (f"adc_data{ ch } _hi" , "read" ).eq (sample_reg [8 :16 ]),
304+ # self.decoder.get(f"adc_data{ch}_lo", "read").eq(0xaa),
305+ # self.decoder.get(f"adc_data{ch}_hi", "read").eq(0xbb),
306+ ]
307+
308+
269309 # connect iir to servo data registers
270310 for i in range (SERVO_CHANNELS ):
271311 for j in range (SERVO_PROFILES ):
@@ -368,39 +408,41 @@ def __init__(self, platform):
368408 ]
369409
370410 # use liberally for debugging
371- self .comb += [
372- Cat ([platform .request ("test_point" , i ) for i in range (6 )]).eq (
373- Cat (
374- ClockSignal ("clk125" ),
375- ClockSignal ("link" ),
376- # ClockSignal(),
377- # ResetSignal(),
378- # # self.link.slip.bitslip,
379- # # self.link.unframe.data[0],
380- # # self.link.unframe.data[1],
381- # # self.link.unframe.clk_stb,
382- # # self.link.unframe.marker_stb,
383- # # self.link.unframe.end_of_frame,
384- # self.link.checker.frame_stb,
385- # # self.decoder.bus.bus.we,
386- # # self.decoder.bus.bus.re,
387- # # self.decoder.bus.bus.adr[0],
388- # self.link.checker.miso,
389- # # self.dac.data_sync,
390- # self.dac.istr,
391- # dac_ctrl.alarm,
392- ClockSignal ("ret" ),
393- adc .cnvn ,
394- adc .sdo [0 ],
395- adc .data [1 ][0 ],
396- )
397- )
398- ]
411+ self .comb += [platform .request ("test_point" , 0 ).eq (adc .data [1 ][0 ])]
412+ # self.comb += [
413+ # Cat([platform.request("test_point", i) for i in range(6)]).eq(
414+ # Cat(
415+ # ClockSignal("clk125"),
416+ # ClockSignal("link"),
417+ # # ClockSignal(),
418+ # # ResetSignal(),
419+ # # # self.link.slip.bitslip,
420+ # # # self.link.unframe.data[0],
421+ # # # self.link.unframe.data[1],
422+ # # # self.link.unframe.clk_stb,
423+ # # # self.link.unframe.marker_stb,
424+ # # # self.link.unframe.end_of_frame,
425+ # # self.link.checker.frame_stb,
426+ # # # self.decoder.bus.bus.we,
427+ # # # self.decoder.bus.bus.re,
428+ # # # self.decoder.bus.bus.adr[0],
429+ # # self.link.checker.miso,
430+ # # # self.dac.data_sync,
431+ # # self.dac.istr,
432+ # # dac_ctrl.alarm,
433+ # ClockSignal("ret"),
434+ # adc.cnvn,
435+ # adc.sdo[0],
436+ # adc.data[1][0],
437+ # )
438+ # )
439+ # ]
399440
400441
401442if __name__ == "__main__" :
402443 from migen .build .platforms .sinara .phaser import Platform
403444
445+ # platform = Platform(speed_grade="-3")
404446 platform = Platform ()
405447 # platform.toolchain.additional_commands.extend([
406448 # "set argv phaser.bit",
0 commit comments