PWM Generation for LED Brightness control

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWM Generation for LED Brightness control

1,350 Views
testuers234
Contributor I

Hey,

I've got my KL25Z evaluation board a couple of weeks ago and I've decided not to use any of this HAL software like MCUexpresso or Kinetis SDK. I've been coding in Keil in bare metal. So, I have some problem with my PWM signal generation....I am not able to control the brightness of LED. The moment i power up my board the led is glowing with very feeble brightness that I could barely notice it glowing. I have attached my code here. 

Please do tell me what's so wrong in my code for controlling the brightness of LED?? Suggest me the correction, Thanks in advance.

0 Kudos
1 Reply

1,145 Views
mjbcswitzerland
Specialist V

Hi

See http://www.utasker.com/kinetis/FRDM-KL25Z.html


"Emulated FAT and TSI Slider
The following µTasker V1.4 application uses two channels of the TSI (Touch Sensor Interface) to realise a slider control on the FRDM-KL25Z (SUPPORT_KEY_SCAN and USE_SLIDER). When the slider area is touched the green LED stops blinking and the LED color is controlled by PWM outputs instead. When the slider position is moved the LED color changes from blue to red (color mixture according to the position). When the slider is no longer touched the color is held for one second before the LED starts blinking green again.
The % slider position is shown on the debug output when the slider area is touched.

Furthermore, this application also includes emulated FAT, meaning that it appears as a hard drive to a PC host and allows viewing linear data content. The application is discussed in the document µTasker - FAT Emulation, although this configuration doesn't use a large area of the internal flash for data storage and formatted viewing (due to smaller size of Flash in the KL25) but instead allows a raw display of its entire internal Flash memory and a snap-shot of its internal RAM.
To achieve this configuration it uses (USB_INTERFACE, USE_USB_MSD and FAT_EMULATION)

    uTaskerV1.4.10_FRDM-KL25Z_Slider_Em-FAT_8080.bin. Linked to 0x8080, this binary image can be loaded with drag-and-drop onto the upload disk that appears when the serial loader is operating or using the KBOOT loader's USB or UART connections. [34.6k]
    uTaskerV1.4.10_FRDM-KL25Z_Slider_Em-FAT.bin stand-alone version that can be loaded using the FRDM-KL25Z's USB-MSD (OpenSDA) boot loader [35.6k]"

You can get its open source code, which includes Keil compatibility, at https://github.com/uTasker/uTasker-Kinetis
and allows simulation of the chip, the PWM, etc. in Visual Studio for ease of debugging, coding and learning.

Some general HW timer/PWM tips at: http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF


The problem with your code is that you haven't set up a clock to be used by the TPM in the SIM_SOPT2 register:

pastedImage_2.png
 pastedImage_3.png

The default is disabled clock and so no operation.

Regards

Mark

Complete Kinetis solutions for professional needs, training and support:http://www.utasker.com/kinetis.html
Kinetis KL25:
- http://www.utasker.com/kinetis/FRDM-KL25Z.html
- http://www.utasker.com/kinetis/TWR-KL25Z48M.html
uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market

0 Kudos