Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20705 Discussions

Help me with the code??

Altera_Forum
Honored Contributor II
1,887 Views

I AM A NEWBIE IN VERILOG AND JUST DONT KNOW WHAT IS WRONG WITH MY CODE. 

THIS IS THE CRAZY SIMPLE QUESTION :  

 

Develop a Verilog model for a thermostat that has two 8-bit unsigned binary inputs representing the target temperature and the actual temperature in degrees Fahrenheit (˚F). Assume that both temperatures are above freezing (32˚F). The detector has two outputs: one to turn a heater on when the actual temperature is more than 5˚F below target, and one to turn a cooler onwhen the actual temperature is more than 5˚F above target. 

 

AND THIS IS MY CODE: 

 

module*C2*(switch,clk,heater_on,cooler_on,enable_actual,enable_target); 

 

 

input clk; 

input enable_actual,enable_target; 

input*[7:0]*switch*; 

reg [7:0]*actual,target; 

output* heater_on,*cooler_on; 

 

always @(posedge clk)  

begin  

if (enable_actual) actual <= switch; 

 

else if (enable_target) target <= switch; 

 

end  

 

assign*heater_on*=*actual*<*target*-*5; 

assign*cooler_on*=*actual*>*target*+*5; 

 

endmodule 

 

IT DIDN'T SHOW ANY ERROR DURING COMPILATION.THE PROBLEM IS THAT THE OUTPUT WHICH HEATER_ON AND COOLER_ON DIDN'T ON CORRECTLY.WHAT IS WRONG WITH MY CODE??CAN SOMEBODY PLS HELP ME.:) 

 

PICTURE2 IS THE SIMULATION WHEN I WANT THE HEATER_ON ONLY TO BE ON 

PICTURE4 IS THE SIMULATION WHEN I WANT THE COOLER_ON ONLY TO BE ON 

 

BUT THE SIMULATION WAS NOT WHAT I EXPECTED FOR:HELP PLS:cry:
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
797 Views

Obviously, your stimulus waveforms can't set actual and target registers as intended. Please consider, that the last value during active enable signals is clocked in, so you get zero for both. As a hint, internal signals, e.g. registers can be also visualized with the Quartus simulator. By doing so, you can better realize what's going wrong.

0 Kudos
Altera_Forum
Honored Contributor II
797 Views

mean i have to learn more??

0 Kudos
Altera_Forum
Honored Contributor II
797 Views

sorry, but i don't undersrand for your code!! 

why did you use this "*" in your code??
0 Kudos
Altera_Forum
Honored Contributor II
797 Views

i dnt use the *.when i post it is just there.i tink it means the space between the code.

0 Kudos
Altera_Forum
Honored Contributor II
797 Views

I tink the simulatin is OK now.But i need to assign inputs and outputs to pin planner coz need to display it on DE-series board .If v see the simulation, when i first enter the value for enableactual heater on become 1.Then i entered value of enabletarget and the final output is cooler on.The final output is ok bcoz i wanna cooler to be on. 

My question is can i hold the heater_on output from on bcoz everytime i enter the actual target the heater must be on first. i JUST wanna final result to be displayed on the board.
0 Kudos
Reply