20 Band Audio Spectrum Analyzer
December 14th, 2010

Logic Analyzer on PicKit2

Pretty much every time I tried to work with some sort of digital interface I run into some kind of trouble where a logic analyzer would have saved me hours of blind debugging and posting to various forums. Same thing happened when I decided to try the TMP121 temperature sensor from TI which has an SPI interface. It was the first time I worked with SPI on a pic32 and as expected nothing worked for the first try. The code for setting the SPI interface and reading from it seemed correct, I took it from the “32 bit peripheral lib user guide” from Microchip.

 //configure SPI
OpenSPI1(SPI_MODE16_ON | SPI_SMP_ON | SPI_CKE_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_HIGH | SEC_PRESCAL_8_1 | PRI_PRESCAL_16_1, SPI_ENABLE);
 
//start reading T1
mPORTEClearBits(BIT_0);		// pull CS low to prepare for reading
while(!DataRdySPI1());
T1 = ReadSPI1();		// read 16 bit word
mPORTESetBits(BIT_0);		// pull CS high

So what else could be wrong ? Well at this point it could be a faulty sensor or incorrect use of the SPI interface maybe I wasn’t generating the clock correctly or maybe some wiring issue. This is the point where you need to have a logic analyzer. While I don’t have a proper logic analyzer I do have a PicKit2 and it can emulate a 3 channel, modest logic analyzer. I hooked up one of channels to the SCK pin and I noticed I wasn’t getting any clock signal. But why isn’t the clock being generated ? The answer came from the Microchip forums, the guys there pointed out that in order to generate the clock signal you have to issue a dummy write. By issuing a dummy write you start generating the clock and you can do the reading. So I added a new line to the code and tried again:

//configure SPI
OpenSPI1(SPI_MODE16_ON | SPI_SMP_ON | SPI_CKE_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_HIGH | SEC_PRESCAL_8_1 | PRI_PRESCAL_16_1, SPI_ENABLE);
 
//start reading T1
mPORTEClearBits(BIT_0);		// pull CS low to prepare for reading
SPI1BUF = 0x00;			// this sends a 0x00 just to make the clock toggle in order to read
while(!DataRdySPI1());
T1 = ReadSPI1();		// read 16 bit word
mPORTESetBits(BIT_0);		// pull CS high

This time I also connected a second channel from the logic analyzer to the SDI pin on the pic32 (data in) and it worked :) , here is the capture:Capture of TMP121 output data on SPI bus

As you can see on channel 2 there are 16 clock cycles corresponding to the 16 bit word sent by the TMP121 and on channel 3 connected to SDI(data in on pic32) is the actual binary temperature. If we analyze the data on Ch3, for every falling SCK edge we get 0001101010100000 we can discard the first bit cause its the sign bit (0 = positive , 1 = negative) and plug the rest of the bits in a calculator just to check the data.

binary data in windows calculator

note: windows calc discards the leading 0's

Next we convert to decimal and we get a value of 6816.

decimal data in windows calculator

6816 is not quite the number that we were looking for, but remember the data is represented in two’s complement so we have to divide it by 256 to get the actual temperature in degrees C.

actual temperature in windows calculator

The result after division by 256 is 26.625 degrees C. This was the room temperature at the time of this test. From here on everything is simple, I know I’m getting the right data out of the sensor its just a matter of processing and using it. And here is a picture of the PCB I made for the TMP121 in SOT23-6 package. Probably one of the smallest PCB I made at home, 30×10 mm.

TMP121 temperature sensor PCB

Now I’m seriously thinking about getting the Logic Sniffer from Dangerous Prototypes, it’s a must have.

The Logitech Z-2300 is a 200 watt THX®-certified 2.1 speaker system with a 8-inch long-throw subwoofer. I’m not going to tell you about how good or bad the system is because this is not a review, there are plenty of good reviews out there, just google for one. My Z-2300 worked perfectly for about 2 years but during the thirds year or so I started noticing a small hum coming out of the subwoofer no matter if I was a low or high volume, input connected or disconnected. It bothered me for quite some time but then I got used to it, until recently when I felt that the hum had increased its intensity and I couldn’t stand it anymore.

In the past few weeks I was constantly thinking that I need to fix it someday but I was thinking that I’m going to need to replace some capacitors that’s going to need some de-soldering, getting the right replacement soldering back together, this proved to be a wrong assumption as the fixing was much easier.

First of all you should start by removing the front grill. I used some small flat screwdrivers inserted between the grill and the plastic ring, first lfet-right, next top-bottom. I think the grill was glued a bit and took some force to get it to move. I managed to take mine out without any visible scratches or dents. There’s also a video on youtube, the guy recommends a hair drier: http://www.youtube.com/watch?v=cqbkMGPtZUU

Logitech Z-2300 Subwoofer

Next you have to remove the 8 screws holding the woofer in place, after those are out slowly take out the woofer, hold it strongly cause the big magnet on the back might jump&stick to the toroidal transformers on the bottom of the subwoofer case. Remove the connectors and take the woofer out, this will allow us to pull the PCB on the back further out so we can work on it. If the zip ties holding the cable secured to the box are too tight you can cut them, but be careful not to cut any cable, and make sure you have replacements cause you don’t want the cable to be moving around synchronized with the bass :-)

Logitech Z-2300 Subwoofer

Next move on to the back of the subwoofer. Here you’ll have to take out all of the screws(22 of them) surrounding the metal plate. Now the backplate is kind off glued and stuck if you never opened it before so you’re gonna have to grab the heatsink firmly and give it a good twist as well as pulling on it, but be careful cause all the wires are attached to it and you can only pull it back about ~4 inches. After it pops out, look for the wires that are keeping you from pulling it further back. I had the woofer wires (black+red), I had to cut some more zip-ties to release them, and I could finally take a look at the board.

Logitech Z-2300 Subwoofer

Although its hard to spot in the picture above, I spotted a potential problem. It’s circled in red in the photo. It should help you understand whether your problem is the same as what I have experienced, it’s one of those crimping connectors used to secure 2 cables together.The black cable (ground) originally comes from the toroidal transformer placed on the other side of the box. Then when it comes close to the PCB I don’t why the guys from Logitech decided to split it, and have another small piece of black wire going to the PCB. I really don’t understand, couldn’t they’ve just used a whole piece of cable? Anyway as I was talking to a friend of mine, this seems to be a very common cause for getting noises in amplifiers, broken ground circuit.In my case the crimping connector wasn’t holding the cables tight anymore so there was an imperfect ground connection from the transformer to the PCB.

Logitech Z-2300 Subwoofer

In the above pictures you can see how I removed the crimping connector and I soldered the two ground wires together. Next some heat shrink tubing to protect the connection and the noise was gone. Put everything back together and now I can even  pump up the volume to the max with the input disconnected and there is very little noise coming out of the speakers. No wonder the z-2300 has SNR >100 dB and they’re  THX®-certified. I hope this helps you if you have the same problem.

October 30th, 2010

ST1S10 calculator

ST1S10 calculator

Since I was working with the ST1S10 for an upcoming project I decided to publish this little calculator. The ST1S10 is one of the cheapest if not the cheapest 3 A, 900 kHz, monolithic synchronous step-down regulator. The high frequency switching allows the use of tiny SMD components so the board space taken by this regulator its pretty tight. The calculator is written in OpenOffice Calc and saved as XLS, so you can open it with both MS Office and OpenOffice. The calculator works for Vout > 2.5V. You have to enter the requested values on brown boxes and you’ll get the result in the yellow boxes. If you notice any mistake in the formulas please let me know.

Download here: ST1S10 calculator

October 26th, 2010

Magnetic-Less Ethernet

I wanted to test if its possible to have a magnetic-less ethernet connection for an upcoming project. Why magnetic-less? you might ask, well space & weight is critical for my application and since both devices will be present on the same PCB, why not skip the magnetics and reduce space & weight. I have to admit it was allot easier than I imagined it would be. When I first thought about it I imagined I would need to simulate the impedance of the transformer with some inductors, this way before I did any reading on the subject.

Thankfully I had a friend who helped me with some network switches from his junk box. The switches were running ok but its clear that they once had some reliability issues which got them into the junk box, but it was enough for my little experiment. I decided to use the following configuration to test the magnetic-less connection:

  • both switches will have the transformers removed from one of the ports.
  • computer1 connects to switch1 with standard connection.
  • switch1 connects to switch2 with magnetic-less connection(no transformer).
  • computer2 connects to switch2 with standard connection.

After the setup is made and link is up I would ping computer2 from computer1 and if the link is ok the result should be obvious.

network switch test configuration

Now, at this step I still haven’t done any reading on magnetic-less ethernet connections, so I took the bad choice of connecting the two magnetic-less ports wire to wire, “wire coupling” :-) . I knew i had slim chances to make it work, but I said nothing can go wrong. I hooked the two ports, and nothing happened, no link, no LED turned on. Probably somewhere in this process I damaged the two network switches(RTL8309SB) because they were both working before I did surgery on them, and they were both not working when I finished the surgery :-) So directly coupling the two interfaces is a bad idea, it should of ringed a bell the first time I thought about it but it didn’t, I learned it the hard way.

two 10/100 ethernet switchesremoved magnetic transformer from ethernet lineremoved magnetic transformer from ethernet line

This is where I knew I had to do some reading on the subject. Luckily every manufacturer of ethernet interfaces such as ATT ethernet services has an application note on how to couple them magnetic-less for exactly the same situation that I have: both chips on the same pcb. I picked up another 2 switches and opened them up. Since they both had Realtek controllers I used this application note from Realtek. The app note provides a simple solution, capacitive coupling.

schematic for magnetic-less ethernet

I got to work, once again I removed 1 transformer from each network switch but this time I used capacitive coupling. I soldered wires to where the transformer used to be and I connected those wires to a mini breadboard. The resistors+capacitor pair which sit between the lines on the schematic are still on the board, they’re needed with or without the magnetic transformer. All I had to add was one 0.1uF capacitor on each line. I didn’t even used the pull-up 1.8V as suggested by the app-note. I did the connections as mentioned above, the link activity LED’s signaled immediately, I assigned the computers some ip addresses and success I had the link up & working in no time. I only did a ping test which resulted in under 1ms replies. Perhaps I should of tested the bandwidth too, but I don’t think it suffered from the change.

wires going from the port to the breadboard and on to the next switchwires going from the port to the breadboard and on to the next switchremoved magnetic transformers and replaced with capacitive couplingless than 1ms link with magnetic-less ethernet link

 

Now that I know its working I can save space & weight by implementing the real thing.

In this article I continue my project where I needed a constant current source. In the previous article I talked about the first approach the LM317 constant current source which didn’t worked out that well but could of been improved as suggested by some of my readers in the comments. So I decided to use a dc-dc converter and turn it into a constant current source. Since I’m using the TPS54232 in another project and I have it around I decided to use it. This technique can also be applied to other dc-dc converters with a bit of reading on the subject.

I’ve started by reading SLVA374 app report from TI which is a Step-Down LED Driver Design Guide based on the TPS54160 dc-dc converter, normally used as a buck voltage regulator. The schematic from the app report can be easily adapted to our device with a few changes like adding a sense resistor and an output capacitor:

TPS24232 constant current source schematicTPS24232 constant current source board

If you remember from my last post I needed 1.12 A to power the two led packs that I’ve  build connected in parallel. We have a simple equation that we use to find out the feedback resistor value: R=Vref/Io In our case Vref is 0.8V taken from TPS54232 datasheet, Io is our desired current of 1.12 A. Doing the math we get the R value = 0.71 ohms. This is not a standard value, but we can use two 1.5 ohms resistors in parallel(R1 and R2) to get 0.75 ohms which is pretty close. With 0.75 ohms feedback resistor I have 1.06A at the output which divided by 56(the number of white LED’s) means 18.9 mA for each white led.

We must consider the power dissipation for this resistor and we can calculate it : Pdis = Vref^2/R In our case we have Pdis = 0.8^2/0.75 = 0.85W. The only 1.5 ohms resistors that I could find locally were 5 W so I had to work with a bigger package. The EN pin is used to enable and adjust the Undervoltage Lockout but I’m not going to use that feature since my input voltage is always gonna be high enough not to cause any problems. The resistors are placed on the pcb anyways so you could use those pads and soldere the necessary resistors.

We also must consider the power dissipation in the low side diode. During the converter on time, the output current is provided by the internal switching FET. During the off time, the output current flows through the catch diode. The average power in the diode is given by: Pdiode = (1-Voled/Vin) * Vfd * Io , where: Vfd is the led forward voltage, Voled is the supplied output voltage and is approximated by: Voled = Nled * VLed + Vref where : Nled = number of LEDs, Vled = forward voltage drop of each LED. In my case Pdiode = (1-(4.2/12))*0.75*1.06=0.51W so I used a 2A 40V schottky diode part number CDBA240-G.

You would also have to consider the inductor and the input and output capacitors, but you can read all about that in the datasheet of the TPS54232 or in the app report mentioned above. After I had all of my circuit figured out, I routed the board and etched it using my photo etching technique. For such a small board its not worth taking out the solder paste so I soldered it using the soldering iron, as you can see its a mix of through hole and surface mount parts but they fit together quite nice.

TPS54232 LED constant current source pcb assembledTPS54232 constant current source pcb back side

The solder drops that you can see on the back of the board are a sort of DIY thermal vias. I’m not sure how efficient they are but I gave them a try with this board, probably because I had too much time available :-) . First when I designed the board I included a area of copper in the top layer right beside the resistors. Next I drilled some 0.7 mm holes and I placed 0.7 copper wire in the wholes securing it by soldering on both sides. The trick is to make the solder joint as small as possible so it doesn’t spaces your component from the board. As I’ve said I don’t know their efficiency but I think they work, I can feel the heat transferring from one side to the other faster. If you like them you can try them.

The testing went smooth, the LED’s light up perfectly, no problems at all. During the testing I noticed one bug though: if the input wires are not firmly attached or secured and there is an imperfect contact the converter will tend to output less current than the programmed 1.02A. I’m not sure why this is happening, it might have something to do with the Undervoltage Lockout feature that I skipped on but I’m not sure. Anyway its not that much of a problem since once in place the power source will have the cables firmly attached so no worries. That’s why I used the cable connectors on the PCB in the first place, I knew it would save me some trouble later.

56 white LED

Now I had one last thing to do. Since this circuit is going to be operated in the outdoors the corrosion would set in pretty quickly so I improvised once again. I had this idea for quite a long time but never actually tried it. So I used my Bison universal hobby glue, which is transparent, and covered the copper traces on the PCB in glue. After it hardened, it looks like you could dip these board into water and nothing would happen to them. Well, except from the terminals which stick out of the PCB :-) . Nonetheless I think these boards will run no problems even after a few years. If you’re wondering where the bubbles come from, they form when the glue dries out :-) .

TPS54232 constant current source covered in gluewhite led packs pcb's covered in glue

I’m pretty happy how this project ended up and I feel like I know more about LED’s and ways to power them. I’ll definitely need to experiment more with some high power LED’s, maybe use them to light my workbench. As for the efficiency of this circuit I don’t know if I’m calculating the right way because I’m using the equations from page 16 of TPS54232 datasheet, and those are clearly stated to be used only under continuous conduction mode. Since the circuit has been modified to act as a constant current source I’m not sure the same equations apply. But I did the math anyway and I got an efficiency of 75.36% and according to the same equation if I would connect the two led packs in series I would get an efficiency of 79.01%. Once again I’m not sure these calculations are correct and I ask the readers to comment on these.

There is more that you can do to improve the efficiency of this circuit. It turns out you can reduce the power losses in the current sense resistor by lowering the voltage across the resistor. The solution is to inject a bias voltage, but I’m not going to try this solution since I’m already happy with my design. You can read more about it in SLEA004 app report from TI.

Downloads:



© 2007-2011 YourITronics | Any logo, trademark and project represented here are property of their respective owners | Wordpress | Privacy Policy    RSS