| Author |
Message |
victorf
Joined: 01 Jan 2006
Location: Schenectady, New York
|
|
Posted: 11 November 2006, 14:01 PM Post subject: Using SPI for pressure sensor |
|
|
I would like to interface to this pressure sensor:
http://www.sparkfun.com/commerce/product_info.php?products_id=8161
I have no knowledge of how to do the SPI stuff and would like to know
if this is a feasible thing to do with a ZX-24.
The product data sheet can be found on the VTI Technologies web site:
www.vti.fi
I am considering attaching two of these units and use one in the high
resolution mode for measuring altitude and the other in high speed mode acting as a variometer.
Any enlightenment and guidance will be greatly appreciated.
Vic
|
|
| Back to top |
|
 |
mwf
Joined: 06 Oct 2006
Location: Boulder, CO
|
|
Posted: 11 November 2006, 17:45 PM Post subject: |
|
|
I had a quick look at the specs. It looks like the chip is relatively easy to use. You can use the ZX-24 SPI interface and SPICmd with one byte of output and one or two bytes of input/output as needed by the command you sent. The ZX-24e has the SPI bus available on the dip pins while the ZX-24 has the SPI on pinless pads that require soldering to the ZX-24.
ShiftIn and ShiftOut are too fast to use with this chip so don't go there. Be sure to select a clock rate in OpenSPI that is slow enough (divide by 32 or more). The mode bits should be 00.
Use a 74HC125 operating at 3.3v Vcc to level translate the ZX 5v logic to the 3v logic of the transducer (MOSI, Sclk, CSbar). Direct connection will kill the transducer. Use a 74HCT125 operating at 5v Vcc to translate MISO from the transducer up to ZX voltage levels. The 3 state control on this buffer should be connected to CSbar for the transducer. If you use multiple transducers you will need separate buffers for each on MISO. The CSbar for each transducer will also need to be a seperate pin on the ZX-24. MOSI and Sclk can be shared.
If you have any more questions about SPI I will be happy to answer. I have used SPI a lot on many chips. I haven't used your transducer, but the data sheet makes it look as easy as it gets except for the level translation.
|
|
| Back to top |
|
 |
stevech
Joined: 23 Feb 2006
|
|
Posted: 12 November 2006, 5:23 AM Post subject: |
|
|
couldn't he just run the ZX module at 3.3V?
(by-pass the regulator using the Vcc input pin)
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 12 November 2006, 17:42 PM Post subject: |
|
|
| stevech wrote: | couldn't he just run the ZX module at 3.3V?
|
Doing so is not in conformance with the specifications. The mega32/mega644 are specified to run above 8MHz only with a supply voltage of 4.5 to 5.5V. That said, I have successfully run a ZX on 3.3V for extended periods of time but only at room temperature.
|
|
| Back to top |
|
 |
mwf
Joined: 06 Oct 2006
Location: Boulder, CO
|
|
Posted: 12 November 2006, 18:29 PM Post subject: |
|
|
| It makes me wonder how many people could use a ZX-xx with a half speed crystal and a 3.3v regulator. Is there enough interest to justify a new version of the virtual machine? The hardware changes are fairly easy, maybe the user could do it. I could use a few for some one-off projects but not enough to justify the software effort.
|
|
| Back to top |
|
 |
mdown
Joined: 03 Feb 2006
Location: Dallas, Texas
|
|
Posted: 13 November 2006, 14:19 PM Post subject: |
|
|
We run our ZX24 & a and ZX44 & a cpus at 3.4-4.2 v without any noticeable problems, and we have been for more than a year on some of our units.
All our peripheral devices operate in the 2.8-3.6v range so it was just a no brainer for us to forgo all the level shifter pains and just run the cpu's at lover voltage levels.
We have even stuck one in the freezer (I had a temperature sensor and radio on-board) to test the a temp sensor and it still works fine to this day.
The worst you can do is try and it not work, running the cpu's at lower voltages won't damage them.
-Mike
|
|
| Back to top |
|
 |
mwf
Joined: 06 Oct 2006
Location: Boulder, CO
|
|
Posted: 13 November 2006, 18:39 PM Post subject: |
|
|
| If the CMOS process used to make the micro is the one I think it is, the speed drops off at high temperatures. Somewhere around 40c the chip starts slowing down and at 70c it is about half the 20c speed. So there should be a temperature above which the micro makes errors at low voltage. If someone who is setup to do it could warm up a ZX-24 running on 3.3v until it quits or 70c is reached and report the results, we could determine the maximum temperature for reliable operation. Ideally this should be done with several ZX-24s from different batches, but I wouldn't expect a lot of variation. This should be a safe test that does no harm as long as the temperature is kept below the upper limit for the parts on the board. Even that can be exceeded for a couple minutes without harm.
|
|
| Back to top |
|
 |
mdown
Joined: 03 Feb 2006
Location: Dallas, Texas
|
|
Posted: 13 November 2006, 18:47 PM Post subject: |
|
|
I can do this, we need to test that anyway.
-Mike
|
|
| Back to top |
|
 |
victorf
Joined: 01 Jan 2006
Location: Schenectady, New York
|
|
Posted: 14 November 2006, 18:43 PM Post subject: |
|
|
First, let me thank everyone who responded to my query.
To have to go through the level shifting seems somewhat klunky and I get the impression that running the ZX at 3.3 volts would give up some performance and is also iffy. I assume from the responses that there is really no alternative.
Having said that, my next question:
Can I leave CSBar on the sensor permanently grounded and request data by enabling the proper CSBar on the ZX which ultimately sends data requests to the proper sensor or do I need to propagate the ZX CSBar through the level shifter to the proper sensor in order to get data? I don't know if this makes sense or not
It is not clear in my mind how the various signal lines must be handled. Can someone explain the MOSI, MISO and the SCK lines to me. Do commands go over the MISO line to the sensor? Don't forget that I confessed to not knowing how to use the SPI interface in my original post. Be gentle
Any further enlightenment will be gladly appreciated.
Vic
Last edited by victorf on 14 November 2006, 19:11 PM; edited 1 time in total |
|
| Back to top |
|
 |
mwf
Joined: 06 Oct 2006
Location: Boulder, CO
|
|
Posted: 14 November 2006, 18:58 PM Post subject: |
|
|
| Each sensor needs a seperate CSbar from the ZX. If you grounded the pin on the sensor it would pay attention to all the SPI traffic and get into some wierd state where it doesn't do what you want it to. Further it's MISO pin would be driving the bus all the time which would mess up all the other chips on the bus. The latter could be avoided by using a 3 state buffer that could be turned off when you don't want to hear from the sensor. The first problem might be avoided by gating the SClk signal with a select that is true when you want to talk to the sensor. You might as well use CSbar on the sensor in terms of resources used. Some serial interface chips don't have a CSbar pin and then you have to resort to the extra parts.
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 14 November 2006, 20:04 PM Post subject: |
|
|
| victorf wrote: | | I get the impression that running the ZX at 3.3 volts would give up some performance and is also iffy. |
There is no performance hit incurred by running a ZX at 3.3V. It's just that the mega chip is not specified to run at 14.7MHz when its Vcc is under 4.5V. It was suggested that a special "low voltage" version of the ZX could be made that would run at 7.37MHz. In that scenario, the execution speed would be lower but the chip would be operating within specs.
| victorf wrote: | | Can someone explain the MOSI, MISO and the SCK lines to me. Do commands go over the MISO line to the sensor? |
The SPI interface provides for a Master and one or more Slaves. The ZX can only operate as a Master - devices that you connect to a ZX will operate as Slaves. The Master controls the timing of data transfer by outputting the SCK signal. Clearly, SCK is an input to all Slaves.
The MISO line (Master In, Slave Out) is an input to the Master and an output of the Slaves. Only one slave should drive the MISO line at a time. Generally, a Slave will only drive the MISO line when its CS line is active.
The MOSI line (Master Out, Slave In) is an output from the Master and input to the Slaves. A Slave will generally ignore the MOSI and SCK lines when its CS line is inactive.
The SPI interface is full duplex, meaning that data is exchanged in both directions simultaneously. Typically, the Master will send a command, possibly followed by some data, on the MOSI line. If it expects data back it then continues to toggle the SCK line outputting additional data on the MOSI line while collecting the data sent by the Slave on the MISO line. Depending on the nature of the Slave device, it may ignore the data transmitted to it when it is transmitting data to the Master.
To get a feel for what's going on you'll probably have to study the datasheet for an SPI device. It will show what commands the device responds to and describe how the device uses the data sent to it and the data it should send to the Master, if any, in each case.
|
|
| Back to top |
|
 |
victorf
Joined: 01 Jan 2006
Location: Schenectady, New York
|
|
Posted: 20 November 2006, 14:21 PM Post subject: |
|
|
I have sketched up a preliminary schematic for my Altimeter/Variometer and would like to know if I handled all the level shifting stuff properly. My library symbols ending in either a 5 or 3 indicate their voltage level, i.e. MOSI5 would be a 5 volt signal. I have attached the ExpressPCB schematic and would like comments/suggestions.
Any enlightenment will be appreciated.
Vic
|
|
| Back to top |
|
 |
victorf
Joined: 01 Jan 2006
Location: Schenectady, New York
|
|
Posted: 20 November 2006, 14:44 PM Post subject: |
|
|
Guess you cannot attach a .SCH file. So here is the attachment in a .ZIP file. Perhaps .SCH files should be allowed.
Vic
| Description: |
| Altimeter/Variometer preliminary schematic |
|
 Download |
| Filename: |
Altimeter.zip |
| Filesize: |
25.95 KB |
| Downloaded: |
276 Time(s) |
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 20 November 2006, 18:19 PM Post subject: |
|
|
1) You should probably use a 74HCT125 for converting 3.3V signals to 5V signals (U4) and a 74HC125 (or 74AHC125) for converting 5V signals to 3.3V (U2 and U3). The schematic shows 74HS125 in all three positions; I'm not familiar with such a device.
2) I think that the enable inputs to U2 and U3 should be connected to ground so that the devices always see the 3.3V versions of CS, SCK and MOSI. On the other hand, the enable inputs to U4 should be driven by the CS output from the ZX. This prevents the MISO line to the ZX from being driven except when the devices are selected. You'll probably want to use two sections of U4 with the enables independently driven by the two CS outputs from the ZX. The inputs and outputs of the two sections should be connected together. You could use a single section of U4 if you produce an enable that combines the two CS signals but it's probably simpler to just use two sections.
3) You'll probably want to use a regulator to produce 3.3V from 5V. The output from a voltage divider as shown on the schematic will vary depending on the load. If the current requirement is less than 100mA, the LE33CZ-TR (DigiKey 497-4258-2-ND) may work.
|
|
| Back to top |
|
 |
spamiam
Joined: 13 Nov 2005
|
|
Posted: 20 November 2006, 19:04 PM Post subject: |
|
|
We discussed these considerations in other threads here about interfacing to a SD/MMC card.
The SD card is a little special in that it can not tolerate loss of /CS between SPICmd()'s of the same "transaction".
Other than this, the considerations are the same.
The suggestions you got in this thread are great, and should result in a very robust interface. So, here is quick and dirty way to interface. I would use this mainly for testing.....
I had good luck, especially at low data rates, with just using a resistor divider to reduce the voltage of the signals from the ZX to the SPI device.
I also had good luck with using the 3.3V MISO signal going directly to a ZX pin.
Under adverse conditions, and at high data rates (an adverse condition of its own), this system may not be adequate.
For the 3.3v power supply, you might get away with a couple of diodes in series. Each one may contribute about 0.4 - 0.7V ( or more) drop (depends on the individual diode, its general type, and how much current you are pulling). You might want to run the SPI device near its upper limit of supply voltage so it will have a better MISO signal to the ZX. At the lower end of the rated supply voltage, the MISO signal willprobably not be reliable at all.
Two standard Vf = 0.7V diodes will probably give a supply voltage around 3.6v. Use a multimeter and a resistor simulating the current draw of the SPI device to see what supply voltage the device will get. If you find that the voltage is within spec, then use the actual device rather than a resistor and see how it works.
-Tony
|
|
| Back to top |
|
 |
|