High precision timings
Posted: Sat Mar 29, 2014 7:04 pm
hiya!
I would like to add DHT22 sensor to my project (based on custom stm32f103ret6 mcu).
DHT22 use custom 1-wire communication, to start you have to send 500 us low and 40 us high impulse on pin.
I've read this: http://www.chibios.org/dokuwiki/doku.ph ... :kb:timing
And write following code in thread:
But this not works, communication did not start. I take logic analizer and see, that width of impulse is much more high, than expected.
I understand, that my code did not works, because other thread are running (i've use USB-CDC example as template, because i need USB CDC too) and current thread did not got executed at proper time, when timeout is over.
I've found 2 workaround, both of them have some disadvantages:
1. set this thread prio to high (thread start communication, run ICU driver and sleep for a while). this is works, but sometimes USB communication became unstable.
2. change CH_FREQUENCY to 1000000 in chconf.h. This works ok, but as i understand, too fast task switching is not ok.
I cannot use VT, because after timeout i need to start ICU and i cannot start it from interrupt handler routine.
Is there any other way to get this code works and keep USB stable and task switching regular?
I would like to add DHT22 sensor to my project (based on custom stm32f103ret6 mcu).
DHT22 use custom 1-wire communication, to start you have to send 500 us low and 40 us high impulse on pin.
I've read this: http://www.chibios.org/dokuwiki/doku.ph ... :kb:timing
And write following code in thread:
Code: Select all
palClearPad(IOPORT, IOPIN);
time = chTimeNow() + US2ST(500);
chThdSleepUntil(time);
palSetPad(IOPORT, IOPIN);
time = chTimeNow() + US2ST(40);
chThdSleepUntil(time);
But this not works, communication did not start. I take logic analizer and see, that width of impulse is much more high, than expected.
I understand, that my code did not works, because other thread are running (i've use USB-CDC example as template, because i need USB CDC too) and current thread did not got executed at proper time, when timeout is over.
I've found 2 workaround, both of them have some disadvantages:
1. set this thread prio to high (thread start communication, run ICU driver and sleep for a while). this is works, but sometimes USB communication became unstable.
2. change CH_FREQUENCY to 1000000 in chconf.h. This works ok, but as i understand, too fast task switching is not ok.
I cannot use VT, because after timeout i need to start ICU and i cannot start it from interrupt handler routine.
Is there any other way to get this code works and keep USB stable and task switching regular?