Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years ago.
KL25Z PWM problem on the smallest pin header
Hello, newbie here. The PWM on the smallest pin header down left does not work at all. The program gets stuck after i call
PwmOut motor_pwm2(PTE29);
for example. On the other headers it works fine. What am I doing wrong?
Please see this picture. The non working header is marked there. http://i.nahraj.to/f/PDx.png
When I use the longest pin header on top right, then everything works fine. I am controlling a Brushed DC electric motor (with PWM) and a brushless step motor. It works fine as expected. By the way, here is my project. http://youtu.be/wocUC18Q1C8
EDIT: Pin changed to PTE29.
1 Answer
9 years, 12 months ago.
I verified that using latest mbed lib both PTC1 and PTE29 work fine with PwmOut using:
#include "mbed.h" PwmOut pwm(PTE29); DigitalOut gnd(PTE30); int main() { gnd = 0; while(1) { pwm = pwm+ 0.01; wait(0.02); if (pwm > 0.99) pwm = 0; } }
(Don't judge me, I needed a ground pin for my LED :P).
Your code does not work with PTC1 and PTE29 on my FRDM-KL25Z. But it works with pins from the biggest header like PTD5. I think that there is a PWM hardware problem on my smallest pin header (marked red on the upper picture). Yes, I updated the mbed.h library.
Thank you anyway
BTW the biggest pin header works OK, as seen on my project. But I must use one wire for 5V supply voltage from the opposite pin header. Here: http://youtu.be/sALln11ezXA
posted by 26 Nov 2014The weird thing is that the pins to that connector all use different PWM peripherals. Since my code doesn't work for you it also rules out Leon's suggestion that there is a clash between different PwmOuts.
If you use DigitalOut, does that header work properly? Otherwise it makes me think there is a PCB issue. And how do you verify the header does not work with my code? (LED?)
posted by 26 Nov 2014***And how do you verify the header does not work with my code?***
Yes, I use LEDs.
posted by 26 Nov 2014****If you use DigitalOut, does that header work properly?*** Yes, it works properly.
posted by 27 Nov 2014So this works as expected.
<<<<<<<<<<<<<<<<<<<<<<<
- include "mbed.h"
PwmOut pwm(PTD5);
DigitalOut out2(PTE21); DigitalOut out(PTE20);
int main() {
while(1) { out2 = 0; wait(0.02); out2 = 1; wait(0.02);
out = 0; wait(0.02); out = 1; wait(0.02);
pwm = pwm+ 0.02; wait(0.02); if (pwm > 0.99) pwm = 0.1; }
}
<<<<<<<<<<<<<<<<<<<<<<<<<
posted by 27 Nov 2014But when I change the PWM to PTB2 for example, the program stops and does not do anything.
<<<<<<<<<<<<<<<<<<<<<<<<<<<
- include "mbed.h"
PwmOut pwm(PTB2);
DigitalOut out2(PTE21); DigitalOut out(PTE20);
int main() {
while(1) { out2 = 0; wait(0.02); out2 = 1; wait(0.02);
out = 0; wait(0.02); out = 1; wait(0.02);
pwm = pwm+ 0.02; wait(0.02); if (pwm > 0.99) pwm = 0.1; }
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
posted by 27 Nov 2014
Hi Tur,
Can you please clarify which pin on the circled header you are using. In your sample code fragment you are referring to PTA12 but that pin isn't on the header you have circled.
Also, what do you mean by "gets stuck"? Does the program stop running there or does it just not perform what you want it to do? If you aren't using the correct pin then it won't do what you want. If it stops running the problem may be more serious.
Leon
posted by Leon Ree 24 Nov 2014Leon:++++++Can you please clarify which pin on the circled header you are using. +++++
I tried all the pins like PTB0, PTB1, PTE29, PTE21....
Leon:++++++Does the program stop running there++++++
Yes, the program stops.
posted by Tur Domaci 24 Nov 2014Have you checked to make sure the PWM support on that pin isn't being used by another PWM pin in your project? Looking in the mbed source code PeripheralPins.c for the KL25Z shows that PTE29 uses the same module as PTA5, PTC3 and PTD2.
Are you able to provide more of a code snippet to where you are calling PwmOut motor_pwm2(PTE29) to help get a better idea on how you are calling it in your program?
Also, if you make a very simple program that only has the PTE29 pin as a PwmOut does it work by itself? This also would help identify if there is a conflict with something else in your program.
posted by Leon Ree 25 Nov 2014Later I will look into it.
posted by Tur Domaci 25 Nov 2014