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.

Saturday, December 22, 2018

Check-in before christmas



This is just a small check-in to show that I haven't abandoned the project. I am still waiting for those PCBs that I ordered. For a moment I was afraid that they had gotten stuck somewhere, but according to their tracking they have “arrived in country”. Hopefully “country” means Sweden. Since it’s the holidays they they will not arrive before christmas, but it’s still nice to have some sort of confirmation that they are not forgotten in some box in China.

Next time I post will be after christmas so I wish you happy holidays!
Bildresultat för tomte

Monday, December 10, 2018

Tunneling Current Update

So I constructed a feedback circuit to make it easier to achieve a tunneling current, and after a lot of testing I think that I finally did it!

Feedback control

The feedback loop was built on the same circuit board as the transimpedance amplifier. I will probably make several changes to the final version as this one has a few flaws in its performance.

It starts by inverting the amplified tunnel signal. This now positive voltage is summed with a negative set voltage to produce an error signal. The error signal is then fed into an op amp integrator. The integrator takes the integral of the error signal, meaning that it rises and falls when the error signal is above or below zero. The resulting output voltage Is then used as a Z signal to control the height of the tip.

Tip attachment

In order for the feedback loop to do anything at all the tip needs to be attached to a piezo element. The piezo element is what does the actual movement, and needs to hold the tip firmly while still keeping it electrically isolated. I achieved this with a small piece of glass between the piezo and the tip. I also used a small piece of prototyping board and a M2 nut to make it more rigid. Epoxi glue was used to hold everything together. If I need to change tip I simply solder it in the prototyping board.

What I got

When I tested this setup, I simply turned the adjustment screw to get the tip and sample as close as possible while keeping an eye on the outputs through my pc oscilloscope. I had it set up so that the green trace showed the height signal going to the piezo and the red trace showed the amplified current signal going from the tip. Each division in the vertical axis represents 3 volts and each division in the horizontal axis represents one second. When I got what I was looking for I took this screenshot:


This looked interesting to me because the signals usually looked different. When the tip and sample were shorted, the current signal would be steady at about -9V, and the height signal would be at about +9V, trying to raise the tip as much as possible. When they were completely disconnected the current signal would stay at zero, while the green line would be at about -9V, trying to lower the tip. During both of these cases the signals would be quite steady. Before I used any feedback loop, I could only get signals that looked like the tip and sample were either shorted, or completely disconnected. I was only able to get the effect shown above when using the new setup. This effect could be explained by quantum tunneling. The current is held at a non-zero voltage, which means that it could be caused by a small tunneling current, while the height signal is going up and down trying to compensate for any changes in tip-sample distance. The extra noise could also be explained by the fact that the system is very sensitive while tunneling. Any tiny changes in tip-sample distance will create a big difference in tunneling current.


Of course this is no proof that I actually got a tunneling current. Some other unforeseen imperfection in the system could have caused this effect. In order to get more evidence for quantum tunneling, I tried to rule out other causes. The signal seemed to be sensitive to mechanical forces, which would suggest that the cause is not purely electrical. I also tried cutting the wire going to the piezo disc, to see if the piezo disc had any effect on the signals, or if it just acted as a capacitor to ground. The results seem to show that it did have an effect.

These small experiments are still not enough to prove anything about quantum tunneling. Maybe the effect is caused by a bad solder joint somewhere, maybe the signal above just changed because I hit the setup when trying to cut the wire. While these screenshots are far from a proof of quantum tunneling it does give me confidence. I could not get anything like this before, and now I can replicate it. The electronics I bought have arrived and the pcbs should arrive soon. I am looking forward to doing more research with a more precise system.




Saturday, December 1, 2018

While I'm waiting for new parts

While waiting for the new materials to arrive I’ve been doing some testing with the components I already have access to. As mentioned in my last post I borrowed a few op amps from school. I used one of these to create a transimpedance amplifier circuit. While the components are not as nice as the ones I’ll use later this circuit will hopefully work good enough to measure a tunneling current.

Trying to Achieve Tunneling

In my first tests I used a multimeter to measure the transimpedance amplifiers output while bringing the tip close to a metal sample. The tip in this case was just a copper wire which was isolated from the scan head by two glass microscope slides. The tip was connected to the circuits current input. The sample was a piece of a circuit board with a gold plated pad. This was connected to a resistor divider which produced a bias voltage of about 0,8VDC. When the tip crashed into the sample and they shorted the multimeter showed a value of about -1,1V. When they were not connected the multimeter showed a value of -8 or -7 mV. The lower value stayed pretty consistent with sample distance so it could not have been a tunneling current. After a lot of touching and adjusting I was able to get an output that fluctuated between -500 and -300 mV. However, I got this by slightly tilting the top half of the scanhead. With how slowly the multimeter updates and how unstable the entire setup was I think that It was most likely due to some play between the tip and the sample.

In my later tests I also had an oscilloscope connected to get a higher update rate, but I was never able to recreate the effect. I tried to make the setup more rigid by adding a rubber band to keep the two halves of the scan head together. This was still not giving me any major results. I knew that I was going to have to think of noise and vibrations later on in the project, so I turned to that. I hanged the setup underneath a tripod to eliminate vibrations, and I even tried to get rid of some noise by adding a saucepan connected to ground.





While this setup is pretty funny, I realized that this was not really helping me. All the extra stuff made it really hard to spot problems or to do adjustments. Also, I haven’t studied shielding very deeply but I suspect that a big opening at the top might not be optimal. While they did not yield the results I was hoping for these experiments might have given me some useful experience for later on when focusing on stuff like vibration isolation and noise reduction. For now I have another idea for how to approach this problem.

Feedback Loop

In my first overview post I wrote that I was not planning on focusing on the feedback loop until after I’ve gotten images. However, I now realize that It might be a good idea to reschedule. A working control circuit connected to a piezo crystal is a much better adjuster than my human fingers on a screw. Instead of having to get the tip within a nanometer range of the sample I’d just have to get it within the piezo crystals travel range. A simpler version of this would be to simply have a potentiometer connected to the piezo so that it acts like a very fine, but still manual, adjustmer. I currently have no way of attaching a tip to the piezo crystal while keeping it isolated, which means more tunneling testing might have to wait until monday when I have access to my schools workshop, (and epoxy glue). If that's the case, I should still be able to do some electronics work tomorrow.

Saturday, November 24, 2018

Electronics are still slow

Currently Waiting for New Parts

Yesterday I placed an order for the parts that I was missing. This includes the 100Mohm resistor and a breakoutboard for my dac ic. The dac ic is a DAC8534, which has a tssop-16 package. I bought a conversion board for a ssop-48 package thinking that I could just leave out the extra pins (the 16 pin version came in a pack of 6 and was more expensive). This was however not the case as the tssop-16 proved to be too small to reach the pads.

When I realized that I was gonna have to buy new parts one of my first ideas was to work on the dac while I waited for them. It was pretty annoying to be met by this sight. The lesson is that packages are not necessarily the same just because they have the same lead pitch.




Making a Custom PCB
The board to the left is what I planned to use for the preamp. It has solder pads in a repeated square pattern which gives you a lego-like freedom when placing components. This board in particular also has the same pitch as a SO-8 package so I can solder the opa129 op amp to it without any conversion board. For simple circuits like the preamp I like these prototyping boards since they allow you to be more hands on.

That being said these prototype boards are not without limitations. While they work well for most simpel things they are not great for sensitive stuff like RF or low current circuits. When dealing with very low currents you have to take a lot more things into account. For example the fact that small currents can leak through the pcb material and affect the signal. Since the preamp needs to measure low currents a custom PCB might be a better choice than this prototype board.

Since I was buying stuff i decided that I might as well design and order a custom pcb that will give me a better end result than the prototype board. It might require some extra patience but in the end I think it will be worth it.

So after spending the week researching low current pcb design and learning EasyEDA I have designed the circuit board bellow.
EasyEDA is the software used to create this. It can also be used for other stuff like making schematics and simulating circuits. It would definitely have been convenient earlier in the project. That being said being able to do things manually is probably also something I value. 

The yellow square is a guard ring that encloses the low current input. These are used in many circuits that handle very small currents. The guard ring is driven close to the same voltage as the input signal (in this case ground) and has a low impedence path to ground. This way very little current can leak to the input node. External currents simply leak into the guard trace instead. 

I also designed the tssop-16 conversion board for the DAC8534 with this program. These boards cost less that the conversion board readily available.

In the Meantime...

Since I'm waiting for these circuit boards I can't really experiment with the DAC or the preamp. Both use a surface mount IC that can't be placed in a solderless breadboard is hard to desolder. I did however find some opamps at school with relatively low input bias currents. They will be enough for me to experiment with for the time being.