11 years, 4 months ago.

Does PwmIn work with KL25Z?

Hi guys! I'm trying to read a pwm input on the KL25Z, and so I imported the PwmIn library (here : https://mbed.org/users/simon/code/PwmIn/)

However, i have absolutely no readings coming from the pin... I have read here https://mbed.org/handbook/InterruptIn#interface that I have to use some input pin supporting InterruptIn so either PTAxx or PTDxx but that did not work... I would really appreciate any input (haha.)!

Here is the code i am currently using :

No readings for you!

#include "mbed.h"
#include "PwmIn.h"

PwmOut rled(LED_RED);
PwmOut gled(LED_GREEN);
PwmOut bled(LED_BLUE);
Serial pc(USBTX, USBRX);
PwmIn anal(PTD1);



int main() {
float tkread=0;
pc.baud(921600);
bled=1;
rled=1;
gled=1;

    while(1) {
        rled = 1;
        wait(0.02);
        rled = 0;
        wait(0.02);
        tkread=anal.dutycycle();
        pc.printf("%f \r\n",tkread);
    }
}

The outputs are : period is a constant 0.000 and dutycycle is a nan... Which is rather logical because dividing by zero is not socially acceptable.

Thank you!

2 Answers

11 years, 4 months ago.

Stupid question, but did you actually apply a signal? If yes, recheck. I just checked it, it works fine for me. (PTD1 probably not handiest choice since it is also LED_BLUE).

Accepted Answer

Well... Checked it again and everything is fine... Sorry about that. :)

posted by Aloïs Wolff 17 Jul 2013
11 years, 4 months ago.

Hi. You may try forcing the pin mode to PullNone or PullDown to get at least a signal. Your controller probably doesn't see rises but just falls.

Thanks. However, this is not an acceptable solution, is it?

posted by Aloïs Wolff 17 Jul 2013