{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/2091","repository_url":"https://api.github.com/repos/micropython/micropython","labels_url":"https://api.github.com/repos/micropython/micropython/issues/2091/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/2091/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/2091/events","html_url":"https://github.com/micropython/micropython/pull/2091","id":155960312,"number":2091,"title":"esp8266: Add machine.time_pulse_us function, to time input pulses.","user":{"login":"dpgeorge","id":6187689,"avatar_url":"https://avatars.githubusercontent.com/u/6187689?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2016-05-20T13:13:49Z","updated_at":"2016-05-30T19:20:32Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/micropython/micropython/pulls/2091","html_url":"https://github.com/micropython/micropython/pull/2091","diff_url":"https://github.com/micropython/micropython/pull/2091.diff","patch_url":"https://github.com/micropython/micropython/pull/2091.patch"},"body":"Here is a proposal for a function/method to time input pulses on a pin.\r\n\r\nCurrent API is:\r\n```\r\nmachine.time_pulse_us(pin, level, timeout=1000000)\r\n```\r\n`level` is the level on the pin to measure a pulse of (eg level=1 means measure a high pulse).  All units are in microseconds (although timeout could probably be converted to milliseconds for compatibility with other timeout args).\r\n\r\nIt first waits while the pin input is different to the given level, then times the duration that the pin is equal to the given level.  Will raise an OSError if either of those waits is longer than the given timeout value.\r\n\r\nThis function could easily be made a method of the Pin class (no change to the C code would be needed).  It seems sensible to make it a method of Pin because the function does not work on any other objects.\r\n\r\nNote also that if the timeout is too large (eg 10 seconds) and no pulse is detected, then the ESP will reset due to WDT timeout.  It's not clear how to fix this while still retaining accuracy of timing the pulse (and also be portable to other ports).\r\n\r\nTested by making a PWM output on one pin and connecting it to another, and timing the PWM pulses.\r\n\r\nSee #2052."},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/222543669","html_url":"https://github.com/micropython/micropython/pull/2091#issuecomment-222543669","issue_url":"https://api.github.com/repos/micropython/micropython/issues/2091","id":222543669,"user":{"login":"pfalcon","id":500451,"avatar_url":"https://avatars.githubusercontent.com/u/500451?v=3","gravatar_id":"","url":"https://api.github.com/users/pfalcon","html_url":"https://github.com/pfalcon","followers_url":"https://api.github.com/users/pfalcon/followers","following_url":"https://api.github.com/users/pfalcon/following{/other_user}","gists_url":"https://api.github.com/users/pfalcon/gists{/gist_id}","starred_url":"https://api.github.com/users/pfalcon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfalcon/subscriptions","organizations_url":"https://api.github.com/users/pfalcon/orgs","repos_url":"https://api.github.com/users/pfalcon/repos","events_url":"https://api.github.com/users/pfalcon/events{/privacy}","received_events_url":"https://api.github.com/users/pfalcon/received_events","type":"User","site_admin":false},"created_at":"2016-05-30T19:20:32Z","updated_at":"2016-05-30T19:20:32Z","body":"> Making it a function puts overhead on the usage as the user must know where it is (which module is sensible for it?). \r\n\r\nIt's obvious - machine.\r\n\r\n> It's easier (more intuitive) from the user point of view to have it as a method.\r\n\r\nJust as treating CS part of SPI bus (what it isn't) or round Pi to 3. We shouldn't look for too-simple solutions, but ones which enable more powerful usage.\r\n"}}
{"actor":{"display_login":"pfalcon"}}