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.
11 years, 3 months ago.
Can DigitalOut generate a short-pulsewidth pulse?
in the code above, I tried to generate a pulse every 5 seconds. So how small can p be set to? It seemed like that if I set p less than 10us, there's no pulse coming out. Do you know why? Could you give me some specific reasons? Thanks!
Hi Shenghao,
The minimum wait time for the wait function is ultimately fixed by the clockspeed of the LPC1768 chip that you are using. By default, it is clocked at 12MHz, however you will find that the minimum time of the wait function is much greater than 8.3 * 10-8, which you could consider your theoretical maximum. It couldn't get this low because in the wait function there are actually a few things going on which take up clock pulses. Unfortunately, I wouldn't be able to give you a definitive answer about this, however you could try reducing it and measuring the pulses on an oscilloscope to see what you get.
posted by Matthew Else 07 Aug 2013Thanks for your reply! Yes, I did reduce the wait time, and measured the pulse with an oscilloscope. I couldn't remember what the pulse looked like. But I am that pulse had distortion and the pulse width was still about 10us. Do you think if it has something to do with the DigitalOut interface? Maybe DigitalOut limit the frequency?
posted by Shenghao Feng 08 Aug 2013The LPC1768 runs at 96MHz. The crystal is 12MHz, but a PLL increases that to 96MHz. DigitalOut isn't as fast as you can get it by directly writing the required registers. But if you completely remove the wait it should take about 100ns iirc. It is also a bit slower when you move 'myled = 0' directly below 'myled = 1', then it doesn't need to jump back first.
However what is your goal? Using for example PWM will be superior for generating short pulses.
posted by Erik - 08 Aug 2013Thanks! I was trying to generate a non-periodic signal, where I can set it to high or low and control the pulse width. That's why I tried DigitalOut instead of PWM, which can only generate periodic signal. Do you by any chance know how to achieve the goal?
posted by Shenghao Feng 08 Aug 2013What are your requirements for period and pulse widths?
posted by Erik - 08 Aug 2013