Glaas2

DoubleDabble

Sep 5th, 2022 (edited)
1,573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 1.71 KB | Source Code | 0 0
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company: Universidad Autonoma Metropolitana Unidad Azcapotzalco
  4. // Engineer: Angel Guerra Esquivel
  5. //
  6. // Create Date:    19:20:38 05/09/2022
  7. // Design Name:
  8. // Module Name:    DoubleDabble
  9. // Project Name:   ALU
  10. // Target Devices: Nexys4
  11. // Tool versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21. module DoubleDabble
  22. #( parameter                BITS = 12)  // input width
  23.   ( input      [BITS-1:0] bin   ,  // binary
  24.     output reg [15:0] bcd   );
  25.  
  26.      
  27.      reg [3:0] i;  
  28.      
  29.      always @(bin)
  30.         begin
  31.             bcd = 0; // inicializando el registro bcd a ceros.
  32.             for (i = 0; i < BITS; i = i+1) // # de iteraciones = al # de BITS
  33.             begin
  34.                 bcd = {bcd[14:0],bin[(BITS-1)-i]}; //realiza el corrimiento descartando el ultimo bit de bcd concatenando con bin de derecha a izq
  35.                    
  36.                 //DoubleDabble, alguna de las partes es >= a 5, suma 3  
  37.                      
  38.                 if(i < (BITS-1) && bcd[3:0] >= 5) //unidades
  39.                     bcd[3:0] = bcd[3:0] + 3;
  40.                          
  41.                 if(i < (BITS-1) && bcd[7:4] >= 5) //decenas
  42.                     bcd[7:4] = bcd[7:4] + 3;
  43.                          
  44.                 if(i < (BITS-1) && bcd[11:8] >= 5)//centenas
  45.                     bcd[11:8] = bcd[11:8] + 3;  
  46.                          
  47.                     if(i < (BITS-1) && bcd[15:12] >= 5)//millares
  48.                     bcd[15:12] = bcd[15:12] + 3;  
  49.             end
  50.         end    
  51.                
  52. endmodule
Advertisement
Add Comment
Please, Sign In to add comment