Pulse Generation

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
sontung
Posts: 1
Joined: Thu Jul 20, 2017 5:58 am

Pulse Generation

Post by sontung » Thu Jul 20, 2017 6:07 am

Hi,
is there any way to generate microsecond pulses on a GPIO line using MP where the pulse width could be configurable in multiples of micro seconds?
The minimum is one pulse.

I have an idea to use the timer callback to trigger a GPIO line but I am not sure if the processing is fast enough to do that.

Any thoughts?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Pulse Generation

Post by dhylands » Thu Jul 20, 2017 4:33 pm

The timer class for the pyboard doesn't currently expose the one-shot mode. I'm pretty sure that the underlying hardware does support it though.

Here's some code which initializes PWM mode (so repetitive pulses, controlled with a microsecond resolution:
https://github.com/dhylands/upy-example ... .py#L6-L13

You could then use the stm module to flip appropriate bits to make this one-shot instead of PWM, but I'm not sure exactly how to do this off the top of my head. I normally consult the datasheet.

Post Reply