Friday, March 8, 2019

Getting Arduino to talk SPI

As I wrote in my previous post I will be using a DAC to control a few analog voltages with an Arduino. The DAC that I've chosen is the DAC 8534 from texas instruments. It has four channels, meaning that it has four different outputs on which different voltages can be generated. I have now managed to control these four outputs. The digital instructions that the chip receives are sent from my Arduino using the SPI protocol. SPI stands for Serial Peripheral Interface and is a digital communication standard. In other words it describes a way to send digital information between devices. The rules for this standard are pretty loose which means that It is up to the device manufacturers to specify exactly how the communication will occur. In the case of the DAC 8534, the datasheet specifies rather specific communication rules, which happen to fall within the SPI standard. For this reason SPI, along with some other similar protocols, are listed as compatible interfaces for the DAC 8534. Since it's compatible, I could use the SPI library when programming my Arduino, which meant that a lot of the code was already written for me.



Communicating with the DAC 8534

The DAC 8534 takes three signals. One Data signal, one clock signal and one sync signal. During data transfer the clock signal is simply a square wave of a certain frequency. This tells the chip how often it should take in data from the data signal. At each falling edge of the clock signal the chip stores one bit. If the Data signal has a high voltage during this time, the bit is stored as a 1, and if it has a low voltage, the bit is stored as a 0. When 24 bits have been stored this way, the transfer is complete, and the DAC 8534 will ignore the clock and data signals until a new transfer is started. The sync signal simply tells the chip when a transfer starts, and can also be used to cancel a transfer before it's complete.

(When talking about digital logic, a "high" voltage is usually around the supply voltage, which in this case is 5Vdc. A "low" voltage is typically close to 0V) 




How the DAC 8534 interprets information

The Image above shows the data and clock signals during a typical data transfer. The green trace is the data signal and the red trace is the clock signal. The sync signal is not shown, but it stays low during the entire transfer. As described above, the data signal is stored as a bit on each falling edge of the clock signal. I've written the value of each bit under the clock signal and assigned them into five groups. When telling the DAC 8534 to generate a certain voltage on one of its outputs, these five groups of bits control different parameters.

Group A
The bits in group A are addressing bits. The DAC 8534 has two addressing pins, which can be tied to a high or a low voltage to select an address. If the address bits do not match the address of the chip, the transfer will be ignored. This way up to four DAC 8534 chips can be used on a single communication bus. I only use a single chip, with both address pins tied to ground. Hence, the address bits are both 0 in this example. 

Group B
The Dac 8534 has a data buffer on each channel, these can store instructions for later use. When data is transferred, the bits in group B control whether the data should be used to generate a voltage on the channel output, or if it should just be saved to the data buffer. When a voltage output is generated, all other channels can be told to simultaneously generate an output based on their data buffers previously stored instructions. The group B bits can also be used to broadcast, so that all channels receive the same instructions. Broadcast also overwrites the address bits, so If several DAC 8534s are used on the same spi bus, the broadcast instructions reach each chip. In this example, these bits hold the value 01, which simply tells the chip to generate an output on the receiving channel.


There is one bit between groups B and C, This bit is a "don't care bit" and can be either 1 or 0.


Group C
The value of the bits in group C determines which channel should receive the instructions. In this case, They hold the value 2 (10 in binary), which corresponds to channel C. 

Group D
When the bit in group D is set to 1, the receiving channel enters one of three power down modes. All power down modes disconnect the output from the rest of the chip. Two of the modes also connect the output to ground through a 1kohm or 10kohm resistor. When a power down command is transmitted the first two bits in group E determines which mode is used. These power down instructions can be stored and updated for all channels just like regular voltage data. In this example I want the DAC to operate normally and produce a voltage output, so the bit in group D is a 0.

Group E
When no power down instructions are being sent the 16 bits in group E control the actual output voltage. They can hold a value between 0 and 65 535 (2^16 - 1). in this example, their value is 4040, which in my test circuit corresponds to an output of about 0,3V.

Why use a DAC?

The Arduino board does have a few "Analog" outputs on its own, but those are actually not true analog, those are what's called pwm, or Pulse Width Modulation. It's a technique used to emulate analog, and works well for controlling motor speed or the brightness of a led.


This picture shows the difference between PWM and a true analog signal. The PWM signal tries to emulate the analog signal with pulses at a certain frequency. In order to imitate a strong or weak signal the duration of each pulse is varied. It's essentially like turning something on and off really quickly to make it seem analog.


I could probably get a decent signal by filtering the pwm signal, which would make it smoother, but a dedicated DAC works better as it outputs a steady voltage to begin with. The DAC 8534 also has a higher, 16 bit resolution, compared to Arduinos 8 bit.

Next time

I'm getting closer to generating an image now! before I can start interfacing my electronics with a computer I need to create a piezo driver. the piezo driver is an analog circuit that takes the X, Y and Z signals and converts them into four signals that move the piezo disc accordingly. I am almost certain that I'll also have to improve the feedback loop, and eventually the mechanics, if I want to produce a nice image. 


Tuesday, February 5, 2019

New preamp!

I have completed the new preamp with the custom PCB and high quality op-amp. It is a lot more sensitive than the one I used for my previous tests. Previously I used a 10Mohm feedback resistor. What that means is that the output voltage in an ideal world is always 10 million times the input current. (as long as it's within the supply voltage). It sounds like a lot, and would probably be usable, but not ideal for this stuff.The new preamp uses a 100Mohm meaning that it's 10 times more sensitive. Additionally, the new op amp is higher quality. We don't live in an ideal world, so the output voltage will have some noise, and some offset. The op amp that I'm using now, the OPA 129, will stay closer to that "ideal world" output. The most important difference, is that it has a much lower input bias current (Iib). Any input current below the Iib rating will be entirely undetectable for an op amp. This means that the OPA can detect much smaller currents than the tl072 that I used before.


I tested this preamp with a feedback circuit similar to the one I used previously. After some adjustments I managed to get this result which looks like it could be a tunneling current. I talked about this in a previous post I will not go into very much detail here.
Like before The green trace here shows the output height signal going to the piezo and the red trace shows the amplified tunnel current from the tip.

Next goals

Now that I have an ok working feedback loop it is time to start looking into the digital side of things. The X, Y, set-current and bias voltages vill be controlled by the DAC 8534 chip. DAC stands for Digital-to-Analog-Converter. As the name implies the chip takes in digital instructiones (ones and zeroes), and outputs an analog voltage. I plan to send the digital instructions with an arduino, which will also read the data to produce a picture in the end. I don't have a lot of experience with this stuff so it should be interesting. The DAC datasheet describes the digital interface and what standards it's compatible with. I think that there are some Arduino libraries to help me out with this as well, so it should be doable.

I still have some analog stuff left however. When I get the DAC to follow my command I will need to build a piezo driver circuit. I also plan to make a better feedback circuit when I have the other systems in place.

Friday, January 11, 2019

The epic jurney of the PCBs is over!

Yes! About a week ago I got my parts in the mail, all the way from China! I had some work then which is why I haven't posted about it earlier.



I designed and ordered 3 different PCBs. two of them are conversion boards from DIP to Tssop-16 and So-8 packages. The last one is what I'll build the preamp on. It has a guard ring around the input node, which minimizes leakage currents. I have 10 copies of each board so I don't have to worry about breaking them.

What I do have to worry about is breaking components. For many of them, such as the DAC and OPA129 i do not have any extras, so when I solder them in place I gotta be carefull not to overheat them. The good thing is that I should now have all I need to complete the project. Since I said that I will probably end up needing more parts anyway, but they will hopefully have a shorter delivery time than these boards.