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.
8 years, 1 month ago.
Creating a single pulse from clock when using TPM channels KL25Z
I'm working on something right now where I need a 10us pulse to trigger a device. I am using TPM0 and the internal clock which is at 41.94Mhz and the output set to a high pulse. I added a push button set up so when it is pushed there is output on another specified pin. I have had no problem creating a waveform that has a 10us period, but the problem I can't figure out is how I can isolate it and get just one of those pulses? Right now when the button is pushed I get the 100kHz square wave that is at 50% duty cycle, which I specified. Can someone tell me how I can get it to do just one pulse and stop?
1 Answer
8 years, 1 month ago.
You could try this, very basic but should give you a 10uS pulse. Not sure which pins are interruptible on the KL25.
Best not to put a 'wait' in your interrupt callback.
snip
#include "mbed.h" InterruptIn button(PTC1); // switch to ground. DigitalOut pulse(PTB0); int IRQ; void IRQ_callback() { IRQ=1; } int main() { button.mode(PullUp); button.fall(IRQ_callback); while(1) { if (IRQ==1) { // Button is pressed pulse=1; wait_us(10); pulse=0; while(!button){} //add some debounce, wait till button released after pulse has fired IRQ=0; } } }