pigtwo
Member level 4
Hello all,
I have a pretty quick question about basic Verilog naming and coding conventions. My goal is to try to make my code look professional so I'd like to make sure I'm not doing stuff that makes me look like I don't know what I'm doing.
The first question I have is about naming conventions is regards to types of registers/wires(or even parameters and other stuff). Currently I use this convention that I made up right when I first started but I don't know if it makes sense. I use all caps and underscores for the inputs/outputs of a module. I capitalize the first letter of each word in states. And finally I use no caps and underscores of registers and wires. I have an example lower down. What do you guys use? Is there a convention that is widely used professionally?
Next, when naming signals that have similar functions but are going to different places how do you name these? This is probably more easily described through example. Say you have a PROM and a SRAM both with data inputs. How would you name these data in signals? Would you do PROM_DATAIN, SRAM_DATAIN or DATAIN_PROM, DATAIN_SRAM ? Generically {function}_{destination} or {destination}_{function}?
Here's example of a RS232 TX module I recently wrote which shows how I currently do it. Any general criticism is also welcome.
Thank you!
I have a pretty quick question about basic Verilog naming and coding conventions. My goal is to try to make my code look professional so I'd like to make sure I'm not doing stuff that makes me look like I don't know what I'm doing.
The first question I have is about naming conventions is regards to types of registers/wires(or even parameters and other stuff). Currently I use this convention that I made up right when I first started but I don't know if it makes sense. I use all caps and underscores for the inputs/outputs of a module. I capitalize the first letter of each word in states. And finally I use no caps and underscores of registers and wires. I have an example lower down. What do you guys use? Is there a convention that is widely used professionally?
Next, when naming signals that have similar functions but are going to different places how do you name these? This is probably more easily described through example. Say you have a PROM and a SRAM both with data inputs. How would you name these data in signals? Would you do PROM_DATAIN, SRAM_DATAIN or DATAIN_PROM, DATAIN_SRAM ? Generically {function}_{destination} or {destination}_{function}?
Here's example of a RS232 TX module I recently wrote which shows how I currently do it. Any general criticism is also welcome.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 `timescale 1ns / 1ps module RS232_SENDER( // Basic signals input wire CLOCK_50, input wire RESET, // Data and control signals input wire[7:0] DATA_IN, input wire EXECUTE, output reg READY, // RS232 signals output reg RS232_TX ); // Internal registers reg start_counter; reg[7:0] counter; reg[9:0] data_send; // Define sequential logic always @(posedge CLOCK_50) begin if(!RESET) begin RS232_TX <= 1; READY <= 0; data_send <= 8'b11111111; counter <= 0; start_counter <= 0; end else begin if(!READY && !start_counter) // This should handle the start up/reset condition READY <= 1; if(READY && EXECUTE) begin // Detect execute signal(only when ready is high) READY <= 0; start_counter <= 1; data_send <= {1'b1, DATA_IN, 1'b0}; // Read data and include start and stop bits end else if(counter == 156) begin // All data sent, go back to ready READY <= 1; start_counter <= 0; end if(start_counter) counter <= counter + 1; // Count when ready not high else counter <= 0; // Write out data at approrate times if( counter == 1 || counter == 24 || counter == 40 || counter == 56 || counter == 72 || counter == 88 || counter == 104 || counter == 120 || counter == 136 || counter == 155) begin RS232_TX <= data_send[0]; data_send <= {1'b0, data_send[9:1]}; end else if(counter == 0) RS232_TX <= 1'b1; else RS232_TX <= RS232_TX; end end endmodule
Thank you!