CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with DHT11 humidity and temp measurement
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Mon May 05, 2014 2:42 pm     Reply with quote

Then it (may be) hangs inside RHT_Start() - waiting for a sensor to response. Do you have pull up resistor on data pin? Also consider what ezflyr said. Try to debug the code by yourself. Read the datasheet and find out how the sensor response to a MCU's requests. Also you may detect where the MCU hangs by using leds output messages etc.
_________________
A person who never made a mistake never tried anything new.
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Thu May 22, 2014 2:18 am     Reply with quote

Finally i corrected the code and it is working correctly.

Now i want to use external oscillator 20Mhz.

With the help from Ttelmah, i found EC_IO fuses.

I changed the fuses line to
#fuses EC_IO

I used this line for 4Mhz,
setup_timer_0(T0_INTERNAL | T0_8_BIT | T0_DIV_256);// Timer prescaler

But for 20Mhz,
What it could be.
I tried setup_timer_0(T0_INTERNAL | T0_8_BIT);
I calculated,
20Mhz/4 => 5Mhz
5Mhz/256 => 19531.25

But i want interrupt to generate 15 times per second.
Ttelmah



Joined: 11 Mar 2010
Posts: 20066

View user's profile Send private message

PostPosted: Thu May 22, 2014 3:02 am     Reply with quote

You are going 5 times as fast, so are not going to get 15* per second. Most divisions in the timers are binary, so 4, 8 etc. times.

Nearest you can get is to get rid of the T0_8_BIT which then means T0 will count to 16bit, so 256 times slower, and then use T0_DIV_4 or T0_DIV_8.
These will give 20000000/(4*4*65536) = 19 times per second, or 9.5 times per second (with /8 instead of /4).

If you switched to 16MHz, instead of 20MHz, then using 16bit, with T0_DIV_4, would give exactly the same time as your current interrupt.
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Thu May 22, 2014 3:15 am     Reply with quote

Thanks Ttelmah. I have understood.

But i'm not in a situation where i cannot use 16Mhz. It is intended to use 20Mhz only.

If i use the interrupt to occur 19 times per second, will it create any problem in DHT11 measurement?
Ttelmah



Joined: 11 Mar 2010
Posts: 20066

View user's profile Send private message

PostPosted: Thu May 22, 2014 12:05 pm     Reply with quote

Not sure, would have to read the data sheet.

However you could use the /8 divider to give 9.5 times per second, and then add a constant to the timer, in the timer interrupt to make this give 15* per sec. Add 24576 to the timer when you enter the interrupt, and you'll get the same timing.
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Thu May 22, 2014 9:57 pm     Reply with quote

I modified the code with interrupt to occur 19 times per second with 20Mhz crystal and it is working good with DHT11.

Thank you Ttelmah and everybody for helping.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group