Altera_Forum
Honored Contributor
21 years agouser logic peripheral
I'm just having a play with a basic (very basic!) peripheral (1 bit output, a few registers etc), but I can't get it to behave correctly.
module my_pwm (address, chipselect, clk, reset_n, write_n, writedata, readdata, pwm_out);
output pwm_out;
input address;
input chipselect;
input clk;
input reset_n;
input write_n;
input writedata;
output readdata;
reg readregister;
reg divider;
reg counter;
reg width;
reg period;
always @(posedge clk or negedge reset_n)
begin
if (reset_n==0)
begin
counter <= 0;
width <= 0;
period <= 0;
divider <= 0;
end
else
begin
if (chipselect && ~write_n)
begin
case(address)
3'b000 : width <= writedata;
3'b001 : period <= writedata;
3'b010 : divider <= writedata;
default :;
endcase
end
if (chipselect && write_n)
begin
case(address)
3'b000 : readregister = width;
3'b001 : readregister = period;
3'b010 : readregister = divider;
3'b011 : readregister = ~width;
default : readregister = 32'b10001111000010100000000000001010;
endcase
end
end
end
assign readdata = readregister;
endmodule I added this as a user logic peripheral in SOPC builder. I created a small program using the IDE which basically did: IOWR(base, 0, 123456) reg = IORD(base, 0) <- reads back as 0 reg = IORD(base, 0) <- reads back as 123456 What exactly have I missed here, I can't see anything wrong with the logic, I've looked at the led & button peripherals and cant see anything wrong, wiggling the appropriate lines up & down in modelsim (just with my verilog source, not simulating the cpu) looks like it should work. I thought maybe it was some sort of cache issue, but the programmers manual says that the IOWR & IORD macro's specifically prevent cache issues from occuring. Can anybody see what I'm doing wrong here? Thanks. Adrian