Kevin1211
Posts: 1
Joined: Mon May 13, 2019 9:33 am

How to get a very accurate delay from 1 milli second in python

Fri May 24, 2019 5:30 pm

Hello people

I need a very precisious delay from 1 millisecond in python. Can I use sleep(0,001) for that or isn't that accurate?
If that isn't accurate, what should I install from library's to get a very accurate delay?
It's for phase cutting on 50Hz with an triac.

Sorry for bad English.

Greetings Kevin

ghp
Posts: 1419
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: How to get a very accurate delay from 1 milli second in python

Sat May 25, 2019 4:27 am

python delay are not very accurate. If you control signals with python, there is a noticeable jitter.
When controlling a triac on 50 Hz ( BE CAREFUL AND OBSERVE ALL TECHNICAL RULES when working with mains) you also need to synchronize the on-pulses with zero crossing of input signal which introduces more error.
There are quite accurate timings available with DMA based pulses (accurate to us), but this does not solve the synchronization problem.

With a careful designed optoisolated zerocross detector, an opto isolated triac driver and then using a microcontroller you get a simple and easy to implement solution.

ankith26
Posts: 103
Joined: Mon Mar 25, 2019 11:08 am
Location: Earth
Contact: Website

Re: How to get a very accurate delay from 1 milli second in python

Sat Jun 01, 2019 4:43 am

Python on raspberry pi is never precise to do perfectly timed stuff in any manner, For that use any microcontroller like arduino
if you have high level stuff, do it on raspberry pi
My website is at https://pratt.ml
Hope it runs (which it wont)

User avatar
joan
Posts: 14386
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to get a very accurate delay from 1 milli second in python

Sat Jun 01, 2019 7:39 am

ankith26 wrote:
Sat Jun 01, 2019 4:43 am
Python on raspberry pi is never precise to do perfectly timed stuff in any manner, For that use any microcontroller like arduino
if you have high level stuff, do it on raspberry pi
That is not true (in the literal sense no machine can do perfectly timed stuff).

The situation is more nuanced as pointed out by ghp. pigpio can accurately time stamp GPIO inputs and can accurately trigger GPIO outputs. What is can't do is guarantee an output response to an input in a particular time frame (because Linux can't guarantee that time frame).

Return to “Python”