Hi Richard,
I was wondering if you could help me understand your use of Timer2 in this project during the read loop for the 40 bits from the DHT11.
In this section of code.....
" t2con=6
while ( dht_data)
wend
t2con=0
if ((tmr2>12)&&(tmr2<50)) then ' noise ?
if (tmr2 >31 ) then
dht.0[bits] = 1
endif
else
goto badread ' noise ?
endif"
I see that Timer2 is turned on with the Prescaler set to 16.
Then after the data line drops to 0, Timer2 is stopped.
Then the TMR2 register is tested for its count value.
If the count is less than 12 or greater than 50, then it's a bad read.
Otherwise if the count is greater than 31 and less than 50 the bit is a 1.
Is this correct?
If the Fosc is 40Mhz and Timer2 counts at Fosc/4 and the Timer2 Prescaler is 16.
Then
Would the test "((tmr2>12)&&(tmr2<50))" equate to
If count is greater than 19.2us and less than 80us?
And then would the test "(tmr2 >31 )" equate to
If count is greater than 49.6us?
Which I think the test logic would translate to...
If the count is less than 19.2us or greater than 80us then it's a bad read.
Otherwise if the count is greater than 49.6us and less than 80us the bit is a 1.
I think this is right, but please let me know if not.
Just trying to understand how it is implemented.
Thanks




Bookmarks