SPI Clock Frequency vs FPGA Internal Clock Frequency - fpga

Treating the FPGA as a SPI Slave, I've read that on the FPGA it is easier to sample the SPI Clock with the internal clock as opposed to trying to cross the clock domain within the logic.
With that being said, I have a 100Mhz clock and I am trying to implement a 20Mhz SPI clock to read data.
I am having issues with higher SPI clock rates, could it possibly be my internal FPGA clock is too slow?
Which leads to my next question ... Is there a standard to how much faster the FPGA clock should be compared to the SPI clock if one were to take the approach of syncing the SPI clock with the internal FPGA clock?
Thank you

Related

FPGA what clock frequency

I have a fpga that is taking in serial data at a bit rate of say 4.8 kbps.
Now I am not sure what clock frequency my fpga should run at to properly handle the data.
Will the clock speed simply need to be at minimum 4800 Hz?
It goes the other way round: you first have to determine how many clock cycles you need to process a single input "tick". If one cycle is enough to complete your processing, then 4800 Hz might be fine.
But if you need two cycles, then you would probably go with double speed.
This is a pretty generic answer, but your question is also pretty generic, so this is probably the best you can hope for without enhancing your input.
Will the clock speed simply need to be at minimum 4800 Hz?
Theoretical: yes, practical: no.
Theoretical.
You can receive a 4800 Hz signal with a 4800Hz clock but only if the clock is the exact right frequency. (The 4800 Hz will deviate, no clock is perfect). For that you would need something like a PLL which is in a measurement feedback loop looking at the signal en keeping the clock in step.
Practical.
Much easier is to use e.g. a 1MHz FPGA clock and use over-sampling. Even then you have the same problems as with a dedicated clock: you need to know where the bit boundaries are. Again some sort of clock locking or edge recognition mechanism is required. In fact you have to build the equivalent of a PLL but you can do it all using registers and counters.
When running at 1MHz (which is very slow for an FPGA) you have plenty of clock cycles to process your data.
Both methods depend on the protocol you are using which you did not mention. They are only possible for some type of signals/serial protocols. For example if signals are low or high for many clock cycles that would cause problems for either method.

How to work with DDR in synthesizeable Verilog/VHDL?

I am working on implementing a DDR SDRAM controller for a class and am not allowed to use the Xilinx MIG core.
After thrashing with the design, I am currently working synchronously to my system clock at 100MHz and creating a divided signal "clock" (generated using a counter) that is sent out on the IO pins to DDR SDRAM. I have some logic that feeds me the "rising" edge strobes of this signal clock as I am aware that I cannot use a signal to clock a process. However, this divided clock method runs very slow and I have concerns that I am not meeting the minimum required frequency of the external DDR SDRAM. I am hoping to speed up my read/write bursts, but to do so, my spartan3e will struggle with anything higher than 100MHz. After looking around online, I found this code from EDA Board:
process(Input_Clk,Reset_Control)
begin
if (Reset_Control = '1') then
Output_Data <= (others => '0');
elsif rising_edge(Input_Clk) then
Output_Data <= Input_Data1;
elsif falling_edge(Input_Clk) then
Output_Data <= Input_Data2;
end if;
end process ;
I have written a lot of VHDL, but have never seen something like this before. I'm sure this works fine in simulation, but it doesn't look synthesizable to me. The poster said this should be supported by 1076.6-2004. Does this infer two flip-flops, one clocked on the rising edge and one on the falling edge whose outputs both feed into a 2:1 mux? Does Xilinx support this? I want to avoid having to instantiate a DCM as crossing these clock domains will definitely slow me down and will add undesired complexity. Is there a way to safely generate my DDR data that is being sent to and received from DDR SDRAM without the Xilinx primitive for the MIG? How would I perform the receiving of DDR data in Verilog?
For reference, we have to code in Verilog, so I'm not too sure on how to translate that VHDL process to a Verilog always block if it is synthesizable. We are using the Micron MT46V32M16 if that is relevant.
Here are the timing diagrams for what I am trying to replicate:
I would say that implementing a DDR controller 'for class' is rather challenging. In the companies I worked for they where left for senior engineers to build.
First about the Verilog code shown:
Yes, you are right that can not be synthesized.
The approach to double-clocking inputs is to have two data paths. One on the rising edge and one on the falling edge. In a second stage the two are put in parallel but with double the data width. Thus a 32-bit wide DDR produces 64 data bits per 'system' clock.
More difficult is to clock the arriving data at the right time. As your read diagram shows the data arrives in the middle of the clock edge. For that you need a delayed clock. In an ASIC that is done using a 'tune-able' delay line which is calibrated at start-up and regularly checked for the phase. In an FPGA that would requires some esoteric logic.
I have not been close to DDRs chips for a while, but I think all the modern ones (DDR2 and up?), output a clock themselves to help with the read data.
Also after you have clocked the read data in, using that shifted clock, you have to get the data back to the system clock which requires an asynchronous FIFO.
I hope that gets you started.

Clock Management Altera DE 1

I am designing a processor based on the Altera DE1 board. My biggest concern is power management. I understand that DE1 board has 3 clock inputs and an external clock input that may be used in my design. However, I would be using only one of these at a time.
Is there any way to turn unused clocks off and only turn them on once they are needed? From the user manual, clock enable for the 3 clock inputs are shorted to Vcc.
The power consumption of the 3 external clock generators are unlikely to be the biggest power drains in a system using the DE1 boards, since you are very likely to have many other unused parts on the DE1 board that will consume even more power than the extra clock generators.
If the a clock is unused inside the FPGA, then the power consumption in the FPGA by having a clock signal input is going to be minimal, since the clock is not distributed internally in the FPGA, thus not burning much power.

SPI Module with SCK same as SPI Module Clock - VHDL

Since I see only SPI modules that have an input clock of 2xSCK I want to ask if it's possible to realize an SPI module that have an SCK of same frequency as SPI module.
Depending on whether you are the SPI master or slave, you may be able to come up with something, but the best solution would be to simply increase your clock rate. If your hardware supports them you can use DDR (double data rate) input or output registers to register inputs or drive outputs on both clock edges. If you're the slave you can assign the SPI clock as a clock input, and latch the data using the incoming clock edge. However you will then have to cross clock domains inside your logic.
I would highly recommend increasing your logic clock rate if at all possible.
Having input clock >= 2×SCK is a physical boundary. It's called the Nyquist rate.
Have a look for Shannons sampling theorem.

connecting avr atmega32 to shift register using USART?

I want to connect ATMEGA32 microcontroller to a shift register using USART via TXD pin, the shift register then performs serial to parallel conversion on the received data. but as you know, the shift register needs clocking , this clocking is fed via the microcontroller at baud rate frequency via XCK pin (here the USART acts as master synchronous clock generator).
My problem is that i don't know how to get these clock signal out of XCK, so how to do that???
thanks
RS-232 is self-clocking (fix baud rate) - it typically uses x16 clock supplied to a UART which syncs to the incoming data start bit edge. Rather than use a bare shift register you would probably be better off just using a simple UART chip as your serial to parallel converter - it would save a lot of effort.
I don't think using the UART for the shift register would be a good idea. It would be better to use the SPI mode of communication as it also provide the clock you require for the shift register. But if you want to use UART then you would have to provide a separate clk in sync with the baud rate you've selected for the UART mode which I think would be very hard and inaccurate.

Resources