What you want to do is called a Numerically Controlled "Oscillator", or NCO. It works like this...
Create a counter that can increment by values other than 1. The inputs to this counter are the master clock, and a value to count by (din). For each clock edge, count <= count + din. The number of bits in din is the same as the number of bits in the counter. The actual count value can be used for many useful things, but what you want to do is super simple.
You want to detect every time the counter rolls over, and output a pulse to your motor when that happens. Do this by taking the most significant bit of the counter and running it through a single flip-flop to delay it by one clock. Now you have two signals that I'll call MSB, and MSB_Previous. You know if the counter has rolled over because MSB=0 and MSB_Prev=1. When that condition is true, send a pulse to the motor.
To set the pulse frequency, the formula is this: pulse_rate = main_clk_freq * inc_value/2^n_bits
Where inc_value is the value that the counter is being incremented by and n_bits is the number of bits in the counter.
An important thing to note is that adding bits to the counter does not change the range of the output frequency-- that is always 0 Hz to half of main_clk_freq. But it does change the accuracy that you can generate the desired frequency. Odds are high that you won't need 32-bits for this counter, and that maybe just 10 to 16 bits will be enough.
This method of generating pulses is nice because it is super easy, the logic is small and fast, and it can often generate frequencies more accurately and with better flexibility than the type of counter+comparator design that you have in your question.
The reason why the logic is smaller is not only because you can get by with a smaller counter, but you do not have to compare the entire output of the counter. You only need the top bit. Also, comparing two large numbers in an FPGA usually requires a lot of LUTs. Comparing two 32-bit numbers would require 21 4-Input LUTs and 3 logic levels, where as the NCO design requires 1 LUT, 2 Flip-Flops, and only 1 logic level. (I'm ignoring the counter, since it is basically the same for both designs.) The NCO approach is much smaller, much faster, much simpler, and yields better results.
Update: An alternative approach to making the rollover detector is to simply send out the MSB of the counter to the motor. If you do this, the signal going to the motor will always be a 50/50 duty cycle. Choosing the best approach depends on what kind of pulse your motor needs.
Update: Here is a VHDL code snippet for doing the NCO.
signal count :std_logic_vector (15 downto 0) := (others=>'0);
signal inc :std_logic_vector (15 downto 0) := (others=>'0);
signal pulse :std_logic := '0';
. . .
process (clk)
begin
if rising_edge(clk) then
count <= count + inc;
end if;
end process;
pulse <= count(count'high);
I think from your question you already understand this, but for clarification, this is my usual terminology:
- Programming implies altering some non-volatile device
- Configuration is what the FPGA does when it starts up - it loads its volatile internal memory from non-volatile external memory.
So, as you surmise, the system needs a non-volatile device of some sort which you program on the production line. To Clarify your comment on the USB blaster, it is not a chip... it's a "pod", so you'd have one for your programming station, not one per board:
Anyway, back to the non-volatile storage options:
The "Almost-zero-engineering required" approach uses Altera's configuration flash devices, which are JTAG programmable using something like a USB blaster. You just wire them up like the datasheet says, and away you go. They cost more per MBit than other options, though, so are not often used in volume production.
One more usual approach is a "normal" SPI flash chip. The Cyclone user guide configuration section will list some which are compatible with it, and I believe you can also use the Quartus software to program them via the JTAG of the FPGA they are connected to. More engineering involved, checking you have the right device etc. Also, if you are in volume production, you may not want to be using Quartus on the production line, which which case you may have to provide a separate programming header for the flash chip, and some hardware+software to drive that.
If you have a microcontroller in your system (even on another board...) you could connect that up to the FPGA's JTAG or configuration pins and store the FPGA bitstream in the micro's flash. More engineering involved as you have to have some software to "boot" the FPGA. however, it can make in-field upgrades easier, as often the micro is set up to receive software upgrades already, whereas updating the flash when it hangs directly off the FPGA is often an "opening the box" experience!
Best Answer
There are two ways of doing it.
1. Pin Planner
The first approach is in the Pin Planner tool. This is the GUI that allows you to select which pin goes where. From the main window with your project open, go to the Assignments menu and select Pin Planner (or press Ctrl+Shift+N).
In the pin planner window, in the All pins view at the bottom, right click on any column header, and select "Customise Columns":
In the window that opens, scroll down in the left hand side and find "Weak Pull-up Resistor" (it's third one up from the bottom on mine). Click on that, then click the right arrow button to add it to the visible columns. Then click OK.
Now back in the Pin Planner window, you should see a new column called Weak Pull-Up Resistor. For each pin you wish to enable it on, simply click in the box for that column and select "On" (you can also type On into the box). By default it is turned "Off" - so if the column is blank, it means the same as if it says off.
2. Assignment Editor
You can also assign it manually with the "Assignment Editor" tool. This is useful if, say, you want to enable it for all pins in a bus, or even just all pins. You can use wildcards here.
Open the assignment editor tool in the main window by going to the "Assignments" menu and selecting "Assignment Editor" (or press Ctrl+Shift+A)
At the bottom of the list of assignments, there is a row where all entries are
<<New>>
. Click in the "Assignment Name" column and select "Weak Pull-Up Resistor". Then in the "Value" column, select "On". Finally in the "To" column, enter the pin name (which can include the wildcard character*
).This will enable the pull-up for any pin matching the name in the "To" column.