Active7 years, 5 months ago
FPGA Implementation of distance Measurement with Ultrasonic Sensor Ask for Price The main objective of project is Find distance of the obstacle in front of any automation system, a Spartan3 FPGA Image Processing kit is used to measure trigger input and display the echo output result.
$begingroup$I am writing a Verilog driver for a simple temperature sensor connected to an FPGA. (The temperature sensor datasheet is available here.) Communications occur over one pin, the
sda
pin, where the slave or master sends a byte, which is then 'acknowledged' by the other at the end of the byte (between the clock cycles 9 and 1).I imagine that the best way to model this is making
sda
an inout wire
, where both the master and the slave drive sda
using an assign
statement. It is unclear to me how collisions can be avoided.What happens when the same
Jon Linout wire
is driven by both the source and the master? What is the best way to model send-acknowledge cycles over one pin in Verilog?3,93811 gold badge1818 silver badges3333 bronze badges
RandomblueRandomblue4,5602323 gold badges8282 silver badges156156 bronze badges
$endgroup$2 Answers
$begingroup$In I2C, when it's their turn to talk, either the master or slave will drives the data line low for a logic 0 or becomes a high impedance input for a logic 1.
When it becomes high impedance, it essentially floats the line and allows the pull-up resistor to pull the line high (logic one). When it is a high impedance input it can detect if the line is being driven low - if it tried to 'write' a logic 1 in this clock cycle, then we know some kind of contention occurred. Note that this is the only case that we care about. If contention occurs but does not end up changing the resulting bit stream then we actually just go about our business without giving any error. If contention does occur, the party that concedes the bus is the one that detected a logic 0 when it was trying to put out a logic 1.
I don't know Verilog, but in VHDL, if we're using the STD_LOGIC type, we can assign it as 'inout' and in a process, assign it the 'Z' value (high-impedance) and then sample the pin for a high or a low.
If you are writing an I2C master, it is your responsibility to detect if the I2C line is in use, specifically, looking for start and stop conditions to signal the start and end of usage by another possible master.
NOTE: it says two-wire interface in the datasheet, I'm pretty sure this means I2C so the above should still be relevant.
Jon LJon L3,93811 gold badge1818 silver badges3333 bronze badges
$endgroup$$begingroup$Your temperature sensor doesn't use just 1 wire to communicate, it uses 2. The clock wire is equally important as the data wire in communicating correctly.
The I2C bus is fairly complex, especially if all its bells and whistles are implemented. Luckily most chips don't implement every capability, and that's why datasheet-level documentation is often inconsistent. For complete and definitive information, you can get the full specification from NXP.
It is unclear to me how collisions can be avoided.
If the temperature sensor is the only other device on the bus, your FPGA will always be the master in the communication protocol. That means you control the clock signal, and you will always know whether the slave is allowed to drive the bus at any given moment.
Typically, you would write a state machine in your FPGA that manages the data in and out of the slave device, and knows when to send data out and when to receive data in.
Note that some slave devices will also assert control of the clock signal at certain specific times in the transaction, as described by the standard. They will do this to 'stretch' the low periods of the clock and give themselves time to complete a measurement or calculation before the master starts clocking out the actual data. If your master design doesn't account for this, it could cause a 'collision'.
What happens when the same inout wire is driven by both the source and the master?
Since I2C devices can only drive low, it generally won't damage either chip if there's a conflict. When you want to send a logic '1', you don't drive the line high, you put it in high-Z state and let an external resistor pull it up. If the slave drives a '0' at the same time, there won't be any damage to either device. Megaman x8 cheats ps4.
What is the best way to model send-acknowledge cycles over one pin in Verilog?
Your Verilog won't 'model' a send-acknowledge cycle. It will describe logic that generates the correct signals from the master device.
If you want to simulate the protocol before committing to hardware, you would write a second module that has another state machine that responds to the master's signals and produces the correct signals for the slave device.
The PhotonThe Photon93.8k33 gold badges113113 silver badges222222 bronze badges
$endgroup$Not the answer you're looking for? Browse other questions tagged fpgatemperatureverilogi2c or ask your own question.
Posted by1 month ago
Hi all! I've been working on a design that includes a ring oscillator as an onboard temperature sensor. Unfortunately, as I've been doing some more testing on the code, I havent been able to get a frequency using the some code that was written by the person who worked on the project before me. So, in order to make sure the oscillator is actually oscillating, I want to output the signal to an Oscope (I have a 2GHz scope which should do the trick). My main question is actually about what sort of things sort things should I take into account when interfacing with the Oscope? For example, are there specific settings I should be aware of when trying to drive something like an Oscope? Also, if the frequency is too high to see the signal on the scope, can I use a counting program that sets the output to the scope after a certain amount of counts, read out the frequency on the scope, and then divide by that counting to get an average frequency?
6 comments