Saturday, June 22, 2013

FRDM-K20D50M - Light Sensor

Recently I have been introduced with the Freescale KL25Z ARM Cortex-M0+ MCU for my 8-bit to 32-bit MCU transition projects at work. I was given a FRDM-KL25Z during training and I was extremely impressed by the ease of hardware initialization process using the supplied Processor Expert Driver Suite. What attracted me more is the CodeWarrior IDE which is based on the Eclipse, and its focus on portability. Without any doubt I bought the board's big brother, the FRDM-K20D50M, which is mounted with an ARM Cortex-M4 MCU, in my favorite PCB color.



Control Overview

To familiar myself with this board I made a project which uses the on-board light sensor, Q1 (which you can't find on the FRDM-KL25Z). The light sensor output is read using ADC0_DM0 (pin 10), and the result is converted to duty ratio for a PWM pin output (pin 44).


The PWM output is then connected to an external interrupt back to MCU (pin 43) to control the on-board LED using the PWM duty cycle. To connect the PWM output to an external interrupt pin, I shorted p_2 and p_4 of J10.


Both the rising and falling edges of the PWM output were used to trigger the external interrupt, and it changes the states of the blue LED (pin 24) states according to the PWM level.

At the same time, I used the Console UART port to send out ADC data read from the light sensor.
As a result, the brightness of the blue LED changes according to ambient brightness, perceived by the light sensor. To make the result more readable, a delay using Erich Styger's Wait component is used, to make the last line stays longer in view.



Problem with Light Sensor Output

When acquiring the light sensor output using ADC, I noticed the data fluctuates too much. And in the end causing the blue LED to flicker. A probe at J12 revealed that the output voltage fluctuates, even with steady ambient lighting. Capacitor came to mind immediately.


A search on the ALS-PT19-315C-L177 light sensor datasheet also shows that a load capacitor Cexists in the application circuit, which is missing on the FRDM-K20D50M board.

I added a 2.2uF capacitor across the light sensor output. It was an easy solder work thanks to the Freescale exposed pads of its logo (GND). The result was more stable and the blue LED stopped flickering.


Under indoor fluorescent lighting condition, the voltage only swings from 3.3V/65535 ADC (darkest) and 2.5V/50000 ADC (brightest), hence I made adjustments so the PWM duty ratio is scaled to 50000-65535 range for better result. This option can be toggled using Option #1 via console UART.

 I also added an exponential transformation of the ADC data, to make values at both extreme darkness and brightness change more rapidly, to provide a more pleasant LED brightness change. This option can be toggled using Option #2 via console UART.

Finally, Option #3 provides reversed LED control.

Problem with CodeWarrior's Terminal Window

During development, I found out the Terminal integrated in CodeWarrior is having problem with escape sequence, which I used to update the ADC values by overwriting the last line.


Summary

The Processor Expert Suite and CodeWarrior IDE  provide a rapid development environment compared to conventional proprietary IDEs/workbenches with focus on code portability and compatibility with other IDEs. I felt uneasy when using function calls to control MCU hardware, as I had been accessing hardware registers directly all along.

In this test project I faced problem with the fluctuating output of the on-board light sensor, and found problem with CodeWarrior's integrated terminal not recognizing escape sequences.

Thursday, June 20, 2013

Samsung Galaxy Tab GT-P1000 - Boot from External SD (Part 1)

I was asked to fix a Galaxy Tab P1000 which stucked at Samsung boot logo. At first I thought it was just a simple file system corruption where flashing a factory ROM will get the job done, but it's not that simple.

As usual being an ORD I rebooted the Tab into recovery mode but was greeted with mounting error. Factory resetting did not help so the next logical step was to fired up Odin and started flashing the latest Gingerbread for the Tab, and (of course) Odin failed to complete the process. When I tried to restart the Tab, what greeted me was the infamous black screen of death!
I've seen that on my i9000, luck was on my side back then but not this time. Still, I was extremely excited because it's a chance to try out the unbrickable mod! The hardware mod is required to resurrect the device to enable the processor booting from USB, and a software can be used to boot the Tab into Download mode. I was excited because the Tab has the same Hummingbird ARM Cortex-A8 processor as my i9000, which I have no courage to apply the mod.

Further Googling my friend and I came to a deduction that the internal SD of the Tab has failed, where symptoms were similar to what described in this page. The way to fix this Tab is to first resurrect it from the black screen of death, and then modify a custom firmware to mount the /data, /cache, and /sdcard partitions on the external SD.

First step, ifixit time. With the help of another friend (and without referring to ifixit), we opened up the Tab.

Back casing was the hardest to remove to preserve cosmetics. The failed internal SD -  SanDisk NAND Flash IC rest under the GT-P1000 sticker, which is strangly not covered by EMI shield (maybe it's the reason it failed so easily?)

Battery removed:

The processor and the xOM5 resistor sit under the EMI shield which was secured with screws from beneath. We had no choice but to take out the main board to remove the EMI shield:

Main board up close:

We followed the guide and removed xOM_5 resistor, and soldered a jumper wire from its non-ground pad to the same side of xOM_3 resistor:

The Tab was assembled while I prepare for its resurrection.

(To be continued in Part 2)


Thanks to:
[Guide] Samsung P1000 with a corrupt internal sdcard
[GSM] P1000 GTab Dev Platform AKA UnBrickable Mod And Software Resurection

Wednesday, April 24, 2013

Fix Computer Power Supply

After a week of holiday with AC mains turned off, one of my PC was unable to powered up. I guessed the cause is the PSU. To confirm the rest of the system was OK, I swapped the PSU with a working one proving the PSU is faulty when the PC powered up successfully.

Knowing little about computer PSU, my best bet was to open up and see if there was any burned components that can be replaced. Before opening the PSU, I googled up and concluded that the start-up circuit was probably the culprit, mainly because the symptom was that the PSU is OK if you power cycle the PC without turning off the AC supply, but failed to power on if AC is cut off for a long time.

Next step, I opened up the PSU (keeping in mind that capacitors might still hold charges when handling the PSU). With Tyche at my side, there was one blown capacitor which seemed easy to get replaced.

I replaced the original 1000uF/10V/105°C capacitor with a 1000uF/25V/85°C one since it was the closest thing I could find, knowing that the lower temperature tolerance will cause a much shorter lifetime for the capacitor.

Next thing, power up test. Things you need to test your PSU are a load (I never thought a dead HDD is still useful), a conductor shorting pin 15 & 16 of the ATX power connector, and observe the fan spinning and checking each 12V, 5V, and 3.3V outputs are normal. I used my daily tweezers to do the job.


And the PSU has revived and back to her PC and the capacitor suffers from hot temperature but lived happily ever after. And I forgot to check the capacitor lies in which part of the PSU circuit!

Turn NUSB to USB

We all know the 'U' in USB stands for Universal (though unlikely ET is using it), but some times companies like to make their own universe, even though they know that there can only be one universe in this..universe, they still do so. Some may argue that there are parallel universes but hey, we are talking about USB, S is serial, not parallel!

So, what does NUSB stands for? Read on.

Most electronic devices come with a micro USB cable and a separate charger. Some likes the idea of sharing and using the USB cable for data transfer and charging (save cost?), like my trustworthy HTC charger with a USB receptacle here:

With this you only need to bring one USB cable when travelling. When I got my Sony PSVita, it used the same idea of sharing the cable, but, it had a NUSB receptacle, the Non-Universal Serial Bus. Well in this case I'm talking about the mechanical design (two notches) of the charger the prevent standard USB plug from plugging in, while the pin-out remains the same. Only the supplied Vita cable with special cut-out at both sides is able to plug into the charger.


The urge to bypass the limitation arose when I need to power up my Raspberry Pi, where >1A supply current is recommended for use with a WiFi dongle, and The Vita charger supplied a nice 1.5A current.

The solution? A very simple+short+naked USB extender.


The extender has no problem plugging in to any USB receptacle. And any USB cable can be easily plugged into the Vita charger now.

With this, I only needed to bring one charger and one USB cable when travelling to charge my phone and the Vita. I also made and option for selecting between USB and AC charging using a jumper shorting the D+ and D-. The purpose of picking USB charging is to protect the charger when your device requires more amperes the charger can supply. When USB charging selected, the maximum current draw is limited to 500mA, which are the standard output of older charger.

Wednesday, April 17, 2013

Speaker Volume Buttons Replacement

I have a pair of Sonic Gear speakers gifted by a dear friend some years ago. After a year serving my ears, the volume buttons started to go wild. The volume will suddenly be increased to maximum levels by itself. For this I had retired them since then, until today I decided to have a look to see whether I can fix the problem. When I checked it, even the Vol- button had failed, both the Vol+ and Vol- button cannot register any pressing action anymore, they failed before reaching 1000 pressing? If I am correct push buttons can last from 100,000 to 1,000,000 times of mechanical life.

Here goes.

The back view of the main (right) speaker:

Opened up to see the PCB & the two dead switches:
Started with removal of the dead switches:

Here were the replacement switches I chose (I did not have much choices). I planned to use the diagonals terminal of these switches to align the switch shaft to the center of the footprints, hence 2 of the terminals have to be cut.

After some usual soldering job, the results were satisfying:

The top view, we can see that the shaft is near the center. The switches will have no problem getting pressed.


Since the replacement switches are higher, the buttons have to be modified next. Luckily it was an easy process to remove one layer of the soft material used to give a premium feel when the buttons are pressed.

And the testing showed the replacement switches worked perfectly:

The truth is, I messed up the terminals of the switches which I was so familiar with, I have to redo the replacement job once more to arrived at the correct mod. You can see that the orientation of the switches in the last picture are different from the previous pictures, and the shafts are exactly on the center now.

Case closed.