| View previous topic :: View next topic |
| Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Mon May 05, 2014 2:42 pm |
|
|
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
|
|
Posted: Thu May 22, 2014 2:18 am |
|
|
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
|
|
Posted: Thu May 22, 2014 3:02 am |
|
|
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
|
|
Posted: Thu May 22, 2014 3:15 am |
|
|
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
|
|
Posted: Thu May 22, 2014 12:05 pm |
|
|
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
|
|
Posted: Thu May 22, 2014 9:57 pm |
|
|
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. |
|
 |
|