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