1. Ok, you also need to learn how VHDL works as a language. A signal can only be updated when a process suspends. A process is also only run when a signal in the sensitivity list is updated. An assignment to a signal outside of a process is really just a process that is sensitive to all the signals on the RHS. In a sensitity list, it waits for a 'event to occur on one of the signals. So lets consider some code:
Code:
signal a, b : std_logic;
a <= b;
this is the equivolent of writing
process(b)
begin
a <= b;
end process;
So now you see the problem. The shared variable cannot have a 'event, so it cannot be placed in a sensitivity list, hence it cannot update a signal outside of a process using a shared variable.
2. This code works just fine, and generates your output clock. If you want it at 1MHz, you'll have to get the specs correct. It currently generates a 50Hz clock. Ill leave you figure out why
3. See 2. Its a 50Hz clock.
The overall problem with using variables is placement in the code is key because of the rules you just read. Whereas with signals, you're more likely to get what you expect in terms of registers. A good guide when learning is to use variables for combinatorial logic and signals for registers. look at this code:
Code:
process(clk)
variable a,b,c,d : std_logic;
begin
if rising_edge(clk) then
a := ip
b := a;
c := b;
d := c;
op <= d;
--is exactly the same as writing:
op <= ip;
end if;
end process;
Now conside the same with signals:
Code:
process(clk)
begin
if rising_edge(clk) then
--Order of assignemnts is irrelavent for signals
c <= b;
a <= ip;
op <= d;
b <= a;
d <= c;
--is the same as writing:
op <= d;
d := c;
c := b;
b := a;
a := ip;
--But the order is very important
end if;
end process;
So, especially as a beginner, I would recommend only ever using signals. I probably use signals about 95% of the time - it makes life much easier when working out whats a register and what's not. This is not programming - its hardware DESCRIPTION.
On another note, you would definatly NOT generate a clock using logic on an FPGA. It is prone to all sorts of timing issues. Its much better to generate clock enables instead and use the system clock for everything.
- - - Updated - - -
On another side note, please stop posting code in PDF files - its very annoying. Use the code or syntax tags instead.