| 1 |
library ieee; |
| 2 |
use ieee.std_logic_1164.all; |
| 3 |
use ieee.numeric_std.all; |
| 4 |
|
| 5 |
--library work; |
| 6 |
-- use work.nco_p.all; |
| 7 |
|
| 8 |
library nuand; |
| 9 |
-- use nuand.util.all; |
| 10 |
use nuand.constellation_mapper_p.all; |
| 11 |
|
| 12 |
entity atsc_tx is |
| 13 |
generic( |
| 14 |
INPUT_WIDTH : positive := 32; |
| 15 |
OUTPUT_WIDTH : positive:= 16; |
| 16 |
SYMBOL_DOWNLOAD_WIDTH : positive := 4; |
| 17 |
SPS : natural := 3; |
| 18 |
CPS : natural := 2 |
| 19 |
); |
| 20 |
port( |
| 21 |
clock : in std_logic; |
| 22 |
reset : in std_logic; |
| 23 |
|
| 24 |
-- |
| 25 |
tx_enable : in std_logic; |
| 26 |
|
| 27 |
data_in : in std_logic_vector(INPUT_WIDTH-1 downto 0); |
| 28 |
data_in_request : out std_logic; |
| 29 |
data_in_valid : in std_logic; |
| 30 |
|
| 31 |
sample_out_i : out signed(OUTPUT_WIDTH-1 downto 0); |
| 32 |
sample_out_q : out signed(OUTPUT_WIDTH-1 downto 0); |
| 33 |
sample_out_valid : out std_logic |
| 34 |
); |
| 35 |
end entity; |
| 36 |
|
| 37 |
|
| 38 |
architecture arch of atsc_tx is |
| 39 |
|
| 40 |
--bit stripper signals |
| 41 |
signal strip_enable : std_logic; |
| 42 |
signal symbol_bits : std_logic_vector(SYMBOL_DOWNLOAD_WIDTH-1 downto 0); |
| 43 |
signal symbol_bits_request : std_logic; |
| 44 |
signal symbol_bits_valid : std_logic; |
| 45 |
|
| 46 |
--constellation mapper |
| 47 |
signal map_inputs : constellation_mapper_inputs_t; |
| 48 |
signal map_outputs : constellation_mapper_outputs_t; |
| 49 |
|
| 50 |
--new mixed signal |
| 51 |
signal symbol_mixed : complex_fixed_t; |
| 52 |
signal symbol_mixed_valid : std_logic; |
| 53 |
|
| 54 |
--new upsampled signal |
| 55 |
signal symbol_mixed_up : complex_fixed_t; |
| 56 |
signal symbol_mixed_up_valid : std_logic; |
| 57 |
|
| 58 |
--filtered signal |
| 59 |
signal filtered_sample : complex_fixed_t; |
| 60 |
signal filtered_sample_valid : std_logic; |
| 61 |
|
| 62 |
--filtered signal |
| 63 |
signal tx_symbol : complex_fixed_t; |
| 64 |
signal tx_symbol_valid : std_logic; |
| 65 |
|
| 66 |
--filtered signal |
| 67 |
signal registered_symbol : complex_fixed_t; |
| 68 |
signal registered_symbol_valid : std_logic; |
| 69 |
|
| 70 |
--pilot |
| 71 |
signal tx_pilot : complex_fixed_t; |
| 72 |
|
| 73 |
-- todo:create tone dynamically |
| 74 |
function create_tone( fs, ftone : real) return complex_fixed_t is |
| 75 |
variable rv : complex_fixed_t := (to_signed(0,16),to_signed(0,16)); |
| 76 |
begin |
| 77 |
return rv; |
| 78 |
end function; |
| 79 |
|
| 80 |
|
| 81 |
constant atsc_lo_table : complex_fixed_array_t := ( (to_signed( integer(4096.0*1.5/7.0),16), to_signed( integer(1.5/7.0 * 0.0),16)), |
| 82 |
(to_signed( integer(1.5/7.0 * 3547.0),16), to_signed( integer(1.5/7.0 * (-2048.0)),16)), |
| 83 |
(to_signed( integer(1.5/7.0 * 2048.0),16), to_signed( integer(1.5/7.0 * (-3547.0)),16)), |
| 84 |
(to_signed( integer(1.5/7.0 * 0.0),16), to_signed( integer(1.5/7.0 * (-4096.0)),16)), |
| 85 |
(to_signed( integer(1.5/7.0 * (-2048.0)),16), to_signed( integer(1.5/7.0 * (-3547.0)),16)), |
| 86 |
(to_signed( integer(1.5/7.0 * (-3547.0)),16), to_signed( integer(1.5/7.0 * (-2048.0)),16)), |
| 87 |
(to_signed( integer(1.5/7.0 * (-4096.0)),16), to_signed( integer(1.5/7.0 * 0.0),16)), |
| 88 |
(to_signed( integer(1.5/7.0 * (-3547.0)),16), to_signed( integer(1.5/7.0 * 2048.0),16)), |
| 89 |
(to_signed( integer(1.5/7.0 * (-2048.0)),16), to_signed( integer(1.5/7.0 * 3547.0),16)), |
| 90 |
(to_signed( integer(1.5/7.0 * 0.0),16), to_signed( integer(1.5/7.0 * 4096.0),16)), |
| 91 |
(to_signed( integer(1.5/7.0 * 2048.0),16), to_signed( integer(1.5/7.0 * 3547.0),16)), |
| 92 |
(to_signed( integer(1.5/7.0 * 3547.0),16), to_signed( integer(1.5/7.0 * 2048.0),16) )); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
function cmult( a, b : complex_fixed_t; q : natural ) return complex_fixed_t is |
| 97 |
variable rv : complex_fixed_t := (to_signed(0,16),to_signed(0,16)); |
| 98 |
begin |
| 99 |
rv.re := resize(shift_right(a.re * b.re,q) - shift_right(a.im * b.im, q),rv.re'length); |
| 100 |
rv.re := resize(shift_right(a.re * b.re,q) + shift_right(a.im * b.re, q),rv.im'length); |
| 101 |
return rv; |
| 102 |
end function; |
| 103 |
|
| 104 |
function cmult_fs4(a : complex_fixed_t; fs_4 : natural) return complex_fixed_t is |
| 105 |
begin |
| 106 |
case fs_4 is |
| 107 |
when 0 => return (a.re,a.im); |
| 108 |
when 1 => return (a.im,-a.re); |
| 109 |
when 2 => return (-a.re,-a.im); |
| 110 |
when 3 => return (-a.im, a.re); |
| 111 |
when others => return a; |
| 112 |
end case; |
| 113 |
end function; |
| 114 |
|
| 115 |
|
| 116 |
constant ATSC_FIR : real_array_t := ( |
| 117 |
0.000952541947487, |
| 118 |
0.001021339440824, |
| 119 |
0.000713161320156, |
| 120 |
0.000099293834852, |
| 121 |
-0.000631484665308, |
| 122 |
-0.001227676654677, |
| 123 |
-0.001457043942307, |
| 124 |
-0.001190147219421, |
| 125 |
-0.000456941151589, |
| 126 |
0.000545581017437, |
| 127 |
0.001502219876242, |
| 128 |
0.002074087248050, |
| 129 |
0.002011614083297, |
| 130 |
0.001249974660528, |
| 131 |
-0.000046895490230, |
| 132 |
-0.001513860357388, |
| 133 |
-0.002682283457258, |
| 134 |
-0.003123186912762, |
| 135 |
-0.002593740652748, |
| 136 |
-0.001139501073282, |
| 137 |
0.000885746160816, |
| 138 |
0.002897996639881, |
| 139 |
0.004244432533851, |
| 140 |
0.004405493902086, |
| 141 |
0.003177417184785, |
| 142 |
0.000774939833928, |
| 143 |
-0.002187174361577, |
| 144 |
-0.004841259681936, |
| 145 |
-0.006310376881971, |
| 146 |
-0.005982741937804, |
| 147 |
-0.003734744853560, |
| 148 |
-0.000027621448548, |
| 149 |
0.004166072719588, |
| 150 |
0.007602382204908, |
| 151 |
0.009117175655313, |
| 152 |
0.007993866438765, |
| 153 |
0.004237744374945, |
| 154 |
-0.001336553068967, |
| 155 |
-0.007251920699642, |
| 156 |
-0.011732810079681, |
| 157 |
-0.013203082387958, |
| 158 |
-0.010786054755306, |
| 159 |
-0.004660238809862, |
| 160 |
0.003849830264059, |
| 161 |
0.012505380718689, |
| 162 |
0.018680222433748, |
| 163 |
0.020069392108675, |
| 164 |
0.015404316532634, |
| 165 |
0.004979659322029, |
| 166 |
-0.009171254616962, |
| 167 |
-0.023537317903158, |
| 168 |
-0.033804674326444, |
| 169 |
-0.035814465077870, |
| 170 |
-0.026588972738348, |
| 171 |
-0.005178629408275, |
| 172 |
0.026889883444145, |
| 173 |
0.065699566102954, |
| 174 |
0.105575674164579, |
| 175 |
0.140146665827966, |
| 176 |
0.163608592331722, |
| 177 |
0.171912865925582, |
| 178 |
0.163608592331722, |
| 179 |
0.140146665827966, |
| 180 |
0.105575674164579, |
| 181 |
0.065699566102954, |
| 182 |
0.026889883444145, |
| 183 |
-0.005178629408275, |
| 184 |
-0.026588972738348, |
| 185 |
-0.035814465077870, |
| 186 |
-0.033804674326444, |
| 187 |
-0.023537317903158, |
| 188 |
-0.009171254616962, |
| 189 |
0.004979659322029, |
| 190 |
0.015404316532634, |
| 191 |
0.020069392108675, |
| 192 |
0.018680222433748, |
| 193 |
0.012505380718689, |
| 194 |
0.003849830264059, |
| 195 |
-0.004660238809862, |
| 196 |
-0.010786054755306, |
| 197 |
-0.013203082387958, |
| 198 |
-0.011732810079681, |
| 199 |
-0.007251920699642, |
| 200 |
-0.001336553068967, |
| 201 |
0.004237744374945, |
| 202 |
0.007993866438765, |
| 203 |
0.009117175655313, |
| 204 |
0.007602382204908, |
| 205 |
0.004166072719588, |
| 206 |
-0.000027621448548, |
| 207 |
-0.003734744853560, |
| 208 |
-0.005982741937804, |
| 209 |
-0.006310376881971, |
| 210 |
-0.004841259681936, |
| 211 |
-0.002187174361577, |
| 212 |
0.000774939833928, |
| 213 |
0.003177417184785, |
| 214 |
0.004405493902086, |
| 215 |
0.004244432533851, |
| 216 |
0.002897996639881, |
| 217 |
0.000885746160816, |
| 218 |
-0.001139501073282, |
| 219 |
-0.002593740652748, |
| 220 |
-0.003123186912762, |
| 221 |
-0.002682283457258, |
| 222 |
-0.001513860357388, |
| 223 |
-0.000046895490230, |
| 224 |
0.001249974660528, |
| 225 |
0.002011614083297, |
| 226 |
0.002074087248050, |
| 227 |
0.001502219876242, |
| 228 |
0.000545581017437, |
| 229 |
-0.000456941151589, |
| 230 |
-0.001190147219421, |
| 231 |
-0.001457043942307, |
| 232 |
-0.001227676654677, |
| 233 |
-0.000631484665308, |
| 234 |
0.000099293834852, |
| 235 |
0.000713161320156, |
| 236 |
0.001021339440824, |
| 237 |
0.000952541947487); |
| 238 |
|
| 239 |
|
| 240 |
begin |
| 241 |
|
| 242 |
|
| 243 |
--map outputs |
| 244 |
sample_out_i <= registered_symbol.re; |
| 245 |
sample_out_q <= registered_symbol.im; |
| 246 |
sample_out_valid <= registered_symbol_valid; |
| 247 |
|
| 248 |
strip_enable <= tx_enable; |
| 249 |
|
| 250 |
U_stripper : entity work.bit_stripper(arch) |
| 251 |
generic map( |
| 252 |
INPUT_WIDTH => 32, |
| 253 |
OUTPUT_WIDTH => 4 |
| 254 |
) |
| 255 |
|
| 256 |
port map( |
| 257 |
clock => clock, |
| 258 |
reset => reset, |
| 259 |
|
| 260 |
enable => strip_enable, |
| 261 |
|
| 262 |
in_data => data_in, |
| 263 |
in_data_request => data_in_request, |
| 264 |
in_data_valid => data_in_valid, |
| 265 |
|
| 266 |
out_data => symbol_bits, |
| 267 |
out_data_request => symbol_bits_request, |
| 268 |
out_data_valid => symbol_bits_valid |
| 269 |
); |
| 270 |
|
| 271 |
--strip symbols |
| 272 |
pull_symbols : process(clock,reset) |
| 273 |
constant DOWNCOUNT_RESET : natural range 0 to 5 := 2; |
| 274 |
variable downcount : natural range 0 to 5 := DOWNCOUNT_RESET; |
| 275 |
begin |
| 276 |
-- |
| 277 |
if (reset = '1') then |
| 278 |
symbol_bits_request <= '0'; |
| 279 |
downcount := DOWNCOUNT_RESET; |
| 280 |
elsif rising_edge(clock) then |
| 281 |
|
| 282 |
if strip_enable = '1' then |
| 283 |
|
| 284 |
symbol_bits_request <= '0'; |
| 285 |
if(downcount = 0) then |
| 286 |
symbol_bits_request <= '1'; |
| 287 |
downcount := 5; |
| 288 |
else |
| 289 |
downcount := downcount - 1 ; |
| 290 |
end if; |
| 291 |
end if; |
| 292 |
|
| 293 |
end if; |
| 294 |
end process; |
| 295 |
|
| 296 |
map_inputs.bits(map_inputs.bits'length -1 downto 3) <= (others => '0'); |
| 297 |
map_inputs.bits(2 downto 0) <= symbol_bits(2 downto 0); |
| 298 |
map_inputs.modulation <= VSB_8; |
| 299 |
map_inputs.valid <= symbol_bits_valid; |
| 300 |
|
| 301 |
--map bits to constellation point |
| 302 |
U_mapper : entity work.constellation_mapper(arch) |
| 303 |
generic map( |
| 304 |
MODULATIONS => (VSB_8, MSK) |
| 305 |
) |
| 306 |
port map( |
| 307 |
clock => clock, |
| 308 |
|
| 309 |
inputs => map_inputs, |
| 310 |
outputs => map_outputs |
| 311 |
); |
| 312 |
|
| 313 |
--apply fs/4 multiply to center |
| 314 |
generate_nco_phase : process(clock,reset) |
| 315 |
subtype phases_t is natural range 0 to 3; |
| 316 |
variable dphase : phases_t; |
| 317 |
begin |
| 318 |
if (reset = '1') then |
| 319 |
dphase := 0; |
| 320 |
symbol_mixed_valid <= '0'; |
| 321 |
symbol_mixed <= ((others=> '0'), (others => '0')); |
| 322 |
elsif (rising_edge(clock)) then |
| 323 |
symbol_mixed_valid <= '0'; |
| 324 |
|
| 325 |
if map_outputs.valid = '1' then |
| 326 |
|
| 327 |
symbol_mixed <= cmult_fs4(map_outputs.symbol, dphase); |
| 328 |
symbol_mixed_valid <= '1'; |
| 329 |
|
| 330 |
if dphase = phases_t'high then |
| 331 |
dphase := 0; |
| 332 |
else |
| 333 |
dphase := dphase + 1; |
| 334 |
end if; |
| 335 |
end if; |
| 336 |
end if; |
| 337 |
end process; |
| 338 |
|
| 339 |
--zero stuff to interpolate since this isn't available in the fir yet |
| 340 |
upsample : process(clock,reset) |
| 341 |
variable downcount : natural range 0 to 2; |
| 342 |
variable cps_downcount : natural range 0 to 2; |
| 343 |
begin |
| 344 |
if (reset = '1') then |
| 345 |
downcount := 0; |
| 346 |
symbol_mixed_up_valid <= '0'; |
| 347 |
elsif rising_edge(clock) then |
| 348 |
symbol_mixed_up_valid <= '0'; |
| 349 |
|
| 350 |
if symbol_mixed_valid = '1' then |
| 351 |
symbol_mixed_up <= symbol_mixed; |
| 352 |
downcount := SPS-1; |
| 353 |
cps_downcount := CPS-1; |
| 354 |
symbol_mixed_up_valid <= '1'; |
| 355 |
|
| 356 |
elsif downcount > 0 then |
| 357 |
symbol_mixed_up <= ((others => '0'), (others => '0')); |
| 358 |
if cps_downcount = 0 then |
| 359 |
symbol_mixed_up_valid <= '1'; |
| 360 |
downcount := downcount -1; |
| 361 |
cps_downcount := CPS-1; |
| 362 |
else |
| 363 |
cps_downcount := cps_downcount -1; |
| 364 |
end if; |
| 365 |
end if; |
| 366 |
end if; |
| 367 |
end process; |
| 368 |
|
| 369 |
--filter to bandwidth |
| 370 |
U_filter_re : entity work.fir_filter(systolic) |
| 371 |
generic map ( |
| 372 |
CPS => 1, |
| 373 |
H => ATSC_FIR |
| 374 |
) |
| 375 |
port map( |
| 376 |
clock => clock, |
| 377 |
reset => reset, |
| 378 |
|
| 379 |
in_sample => symbol_mixed_up.re, |
| 380 |
in_valid => symbol_mixed_up_valid, |
| 381 |
|
| 382 |
out_sample => filtered_sample.re, |
| 383 |
out_valid => filtered_sample_valid |
| 384 |
); |
| 385 |
|
| 386 |
U_filter_im : entity work.fir_filter(systolic) |
| 387 |
generic map ( |
| 388 |
CPS => 1, |
| 389 |
H => ATSC_FIR |
| 390 |
) |
| 391 |
port map( |
| 392 |
clock => clock, |
| 393 |
reset => reset, |
| 394 |
|
| 395 |
in_sample => symbol_mixed_up.im, |
| 396 |
in_valid => symbol_mixed_up_valid, |
| 397 |
|
| 398 |
out_sample => filtered_sample.im, |
| 399 |
out_valid => open |
| 400 |
); |
| 401 |
|
| 402 |
add_pilot : process(clock,reset) |
| 403 |
variable pilot : natural range atsc_lo_table'range; |
| 404 |
begin |
| 405 |
if(reset = '1') then |
| 406 |
tx_symbol <= ((others=>'0'),(others=>'0')); |
| 407 |
tx_pilot <= ((others=>'0'),(others=>'0')); |
| 408 |
tx_symbol_valid <= '0'; |
| 409 |
pilot := 0; |
| 410 |
elsif rising_edge(clock) then |
| 411 |
tx_symbol_valid <= '0'; |
| 412 |
|
| 413 |
if filtered_sample_valid = '1' then |
| 414 |
tx_symbol.re <= filtered_sample.re + shift_right(atsc_lo_table(pilot).re,2); |
| 415 |
tx_symbol.im <= filtered_sample.im + shift_right(atsc_lo_table(pilot).im,2); |
| 416 |
|
| 417 |
tx_pilot.re <= shift_right(atsc_lo_table(pilot).re,1); |
| 418 |
tx_pilot.im <= shift_right(atsc_lo_table(pilot).im,1); |
| 419 |
tx_symbol_valid <= '1'; |
| 420 |
|
| 421 |
if pilot = atsc_lo_table'high then |
| 422 |
pilot := 0; |
| 423 |
else |
| 424 |
pilot := pilot +1; |
| 425 |
end if; |
| 426 |
end if; |
| 427 |
end if; |
| 428 |
end process; |
| 429 |
|
| 430 |
register_output : process(clock,reset) |
| 431 |
begin |
| 432 |
if (reset = '1' ) then |
| 433 |
registered_symbol <= ((others=> '0'),(others=>'0')); |
| 434 |
registered_symbol_valid <= '0'; |
| 435 |
elsif rising_edge(clock) then |
| 436 |
registered_symbol.re <= shift_right(tx_symbol.re,2); |
| 437 |
registered_symbol.im <= shift_right(tx_symbol.im,2); |
| 438 |
registered_symbol_valid <= tx_symbol_valid; |
| 439 |
end if; |
| 440 |
end process; |
| 441 |
|
| 442 |
end architecture; |