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 CL exists 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.
No comments:
Post a Comment