7 years, 9 months ago.

Why can I not independently PWM control pins PTA5 and PTD2 on the FRDM-KL25Z?

On the FRDM-KL25Z, when pins PTA5 and PTD2 are declared as PwmOut pins, they are locked together and can not be independently controlled. It doesn't matter if I change the PWM of PTA5 or PTD2. Whichever one I change, the other one follows it.

The simple code here: https://developer.mbed.org/users/skanderian/code/FRDM-KL25Z_PWM_PTA5_PTD2/file/76be39e5d5ab/main.cpp

should keep pin PTD2 at 0% pwm while pin PTA5 should switch between 50% and 0% every 0.5 seconds. Pin PTA5 does alternate between 50% and 0% pwm, but instead of staying at 0% pwm, pin PTD2 follows pin PTA5.

If I switch pin PTD2 to PTD0, there is no issue, pins PTA5 and pins PTD0 can be independently PWM controlled. Unfortunately I am stuck using preset pins PTA5 and PTD2 as I am using pcbs that connect to these pins.

I would appreciate any help on why this may be and how to resolve it without having to switch pins.

Thanks!

Sami Kanderian

1 Answer

7 years, 9 months ago.

Here you can see the KL25 PWM pinmap (at the bottom): https://github.com/mbedmicro/mbed/blob/master/hal/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PeripheralPins.c

Those two pins have the same underlying hardware and will always behave exactly the same. Nothing you can really do about it.

Accepted Answer

Thanks Erik! Your response helped. I just reassigned the PwmOut pins.

Based on the PeripheralPins.c file, the following pins listed on the same line can not be independently controlled as PwmOut:

  • TPM0,CH0: PTA3,PTC1,PTD0,PTE24
  • TPM0,CH1: PTA4,PTC2,PTD1,PTE25
  • TPM0,CH2: PTA5, PTD2, PTC3, PTE29
  • TPM0,CH3: PTC4,PTD3,PTE30
  • TPM0,CH4: PTC8,PTD4,PTE31
  • TPM0,CH5: PTA0,PTC9,PTD5,PTE26
  • TPM1,CH0: PTB0, PTE20,PTA12
  • TPM1,CH1: PTA13,PTB1,PTE21
  • TPM2,CH0: PTA1,PTB2,PTB18,PTE22
  • TPM2,CH1: PTA2,PTB3,PTB19,PTE23

Does the issue I posted in the link below also have to do with pins with the same underlying hardware?: https://developer.mbed.org/forum/platform-16-KL25Z-community/topic/26197/?page=1#comment-50102

posted by Sami Kanderian 12 Jul 2016

Half yes. It might have been fixed, but I am not 100% sure about it, you would need to check it. You got ADC pins connected to both channels of the ADC (where it picks B), to channel A, or to channel B. PTE21 and PTE23 are the only two connected to channel B. At least in the past it only set the channel correctly in the init code, so if afterwards you initialized a different ADC it would convert from channel B again.

A quick check of the source code gives me the idea it now sets the channel right before a conversion correctly, but I am not 100% sure about this.

posted by Erik - 13 Jul 2016