Main Site Documentation

Using PinCapture with tristate port


#1

Now that we have PinCapture, I am working on reading a DHT11 Temp and Humidity sensor. But, I need some hints.

The device wants the data line brought low for a time and then it will start sending back 40 bits of data (varying the length of time low for a 0 or 1). Reading the 40 bits back seems like it will be easy with PinCapture. Just set up a 40 element buffer and tell it to go. The timings will tell me if it is a long or short bit. No problem.

What I haven’t figured out is how to send the start bit then turn the line around with the required 40us to start receiving the first bit.

Something like this:

myTristatePort.Active = true;
myTristatePort.Write(true);
myTristatePort.Write(false);
myTristatePort.Active = false;
myPincapture.Read(…);

Is there a better way? Do you think it will turn around within 40us to get the first return data bit? I have doubts. Any suggestions?


#2

How about using two different pins? Have a current limiting resistor between your tristate pin and the pin capture pin. When set as an output you should be able to pull the pin capture line hi/low. Then when you set the tristate pin to an input the DHT11 should be able to take control.


#3

RLP is the way to go


#4

oh great; we always knew RLP was the solution to many of the hard challenges, now we have the tool available to us and we’ll all have to start using it !


#5

I am sure RLP can cook my breakfast, but if we have to always resort to gcc and switching environments that will be a huge curve and time waster for most of us and kind of limits the point of clr. I think the question still remains. Is this possible in managed?
Does this help any?
http://bansky.net/blog/2007/11/using-tristateport-class/

It seems to me, even if this does require a native transition, there should be some kind of abstraction that is callable from c# - even if it is a blocking call waiting on success or failure of a Read pattern. I still feel some kind of “remotable” query expression is required here as the high-road solution.


#6

You do not write your application in RLP, only some little task. RLP should be less than 1$ of your entire project and only use it if you need to.

Let us say GHI didn’t add parallel port interface but you need it, then you only write couple RLP methods to write and read parallel port. The rest of your application is still C# and still managed


#7

Thanks gus. I understood that. But it still like trying to bake cake in two kitchens with different ovens and tools. Still, it is good to have an escape hatch.


#8

for the DHT11, I think you may not be so tight as of 40uS. Maybe try this trick:

  • declare the pin as outputport, at state “up” for a few msec.
  • you need to pull down the line for 18ms, and then pullitup.
  • You may have “plenty of time” : the first bit of data will not occur before 160uS : may be enough to Dispose outputport and initiate pincapture.
  • Immediatly dispose the pin, and declare it as pincapture with pullupresistor mode.
  • You may not catch the first on second state change of 80uS, but we don’t care: it’s just sync’ing.
  • Since you know you will get 40 bits, so 80 state changes, you can later find out what you missed out by counting the number of changes you captured: if you get 80, you’re fine. 81 or 82, strip the 2 first changes… Less, you’re toasted.

Please let me know of your testings, I have a couple of DHT11s I’d like to use, but don’t have access to the beta SDK…

If this is not working, you may also try writing directly to the register instead of declaring the pin as outputport. Some examples exists in this forum: that might spare you a few uS.


#9

Everything is better with FETs. The schematic below should allow you to pull the data pin low by setting an independent digital out as high. Toggle the digital line low after your setup time and do the pincapture in the next instruction.

You could do them in a different order, but it looks like the pincap would prevent (block) the toggling of the digital line.

This does something similar to what Jeff suggests, but the FET method prevents a voltage divider occurring between the pullup on the data line and the current limiting R he mentions. His method will work but you have to be aware of the relative value of the resistors and make sure the voltage levels at each combination of states put you solidly in logic high or low as appropriate.