pic 18F4580 has no timer6 try using tmr2 or rework the timer counts for timer3 with a 8:1 prescale
pic 18F4580 has no timer6 try using tmr2 or rework the timer counts for timer3 with a 8:1 prescale
Richard,
need some additional help. The following code compiled, but displayed RH 0.0 and tmr 0 on the LCD. I changed the values for badread and noise as suggested, but still have the same result. As mentioned I'm using a 10 mhz crystal with HS_ppl enabled to run the pic at 40 Mhz. Could you point me in the right direction as to what I'm doing wrong ?
Code:; config settings 18F4580, 10mhz crystal HSPPL ASM __CONFIG _CONFIG1H, _OSC_HSPLL_1H __CONFIG _CONFIG2L, _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM DEFINE OSC 40 ADCON1 = $0F clear INCLUDE "alldigital.pbp" CMCON = 7 TRISA = %11001111 DEFINE LCD_DREG PORTB ' LCD Data port DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4) DEFINE LCD_EREG PORTB ' LCD Enable port DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD) DEFINE LCD_RSREG PORTB ' LCD Register Select port DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD) DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits) DEFINE LCD_LINES 4 ' number of lines on LCD DEFINE LCD_COMMANDUS 2000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us ASM hum = _dht+3 tempa = _dht+1 ENDASM T1CON = %00000001 ; free-running, 1:1 prescaler dht_data var PORTA.1 dht_dir var TRISA.1 dht var byte[5] tempa var word EXT bits var byte crc var byte hum var word EXT main: gosub read_dht LCDOut $FE,$94,"rh ",#hum/10,".",dec1 hum//10 pause 4000 goto main read_dht: for bits=4 to 0 step-1 dht[bits]=0 next tmr2=0 dht_dir=0 dht_data=0 pauseus 1000 'start it up dht_data=1 pauseus 30 dht_dir=1 pauseus 40 'wait till middle of response pulse window if ( dht_data)then goto badread 'no response then give up while (!dht_data) wend t2con=6 while ( dht_data) wend t2con=0 if ((tmr2 <75)||(tmr2>85))then goto badread ' confirm presence ? for bits =39 to 0 step -1 tmr2=0 while (!dht_data) wend t2con=6 while ( dht_data) wend t2con=0 if ((tmr2>20)&&(tmr2<80)) then ' noise ? if (tmr2 >50 ) then dht.0[bits] = 1 endif else goto badread ' noise ? endif next crc=0 for bits=1 to 4 crc=crc+ dht[bits] next if crc != dht[0] then goto badcrc 'crc return badread: LCDOut $FE,$94 +8,"tmr6 ",#tmr2 for bits=4 to 0 step-1 dht[bits]=0 next return badcrc: for bits=4 to 0 step-1 LCDOut $FE,$94 +16,hex dht[bits],"," next return
you did not make the changes I suggested
; config settings 18F4580, 10mhz crystal HSPPL
ASM
__CONFIG _CONFIG1H, _OSC_HSPLL_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
DEFINE OSC 40
ADCON1 = $0F
clear
INCLUDE "alldigital.pbp"
CMCON = 7
TRISA = %11001111
DEFINE LCD_DREG PORTB ' LCD Data port
DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4)
DEFINE LCD_EREG PORTB ' LCD Enable port
DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD)
DEFINE LCD_RSREG PORTB ' LCD Register Select port
DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD)
DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 4 ' number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
ASM
hum = _dht+3
tempa = _dht+1
ENDASM
T1CON = %00000001 ; free-running, 1:1 prescaler
dht_data var PORTA.1
dht_dir var TRISA.1
dht var byte[5]
tempa var word EXT
bits var byte
crc var byte
hum var word EXT
main:
gosub read_dht
LCDOut $FE,$94,"rh ",#hum/10,".",dec1 hum//10
pause 4000
goto main
read_dht:
for bits=4 to 0 step-1
dht[bits]=0
next
tmr2=0
dht_dir=0
dht_data=0
pauseus 1000 'start it up
dht_data=1
pauseus 30
dht_dir=1
pauseus 40 'wait till middle of response pulse window
if ( dht_data)then goto badread 'no response then give up
while (!dht_data)
wend
t2con=6
while ( dht_data)
wend
t2con=0
if ((tmr2 <45)||(tmr2>55))then goto badread ' confirm presence ?
for bits =39 to 0 step -1
tmr2=0
while (!dht_data)
wend
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
next
crc=0
for bits=1 to 4
crc=crc+ dht[bits]
next
if crc != dht[0] then goto badcrc 'crc
return
badread:
LCDOut $FE,$94 +8,"tmr6 ",#tmr2
for bits=4 to 0 step-1
dht[bits]=0
next
return
badcrc:
for bits=4 to 0 step-1
LCDOut $FE,$94 +16,hex dht[bits],","
next
return
if you don't have a oscilloscope or logic analyser add some more diagnostics to the program
Code:; config settings 18F4580, 10mhz crystal HSPPL ASM __CONFIG _CONFIG1H, _OSC_HSPLL_1H __CONFIG _CONFIG2L, _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM DEFINE OSC 40 ADCON1 = $0F clear INCLUDE "alldigital.pbp" CMCON = 7 TRISA = %11001111 DEFINE LCD_DREG PORTB ' LCD Data port DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4) DEFINE LCD_EREG PORTB ' LCD Enable port DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD) DEFINE LCD_RSREG PORTB ' LCD Register Select port DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD) DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits) DEFINE LCD_LINES 4 ' number of lines on LCD DEFINE LCD_COMMANDUS 2000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us ASM hum = _dht+3 tempa = _dht+1 ENDASM T1CON = %00000001 ; free-running, 1:1 prescaler dht_data var PORTA.1 dht_dir var TRISA.1 dht var byte[5] tempa var word EXT bits var byte crc var byte hum var word EXT main: gosub read_dht LCDOut $FE,$94,"rh ",#hum/10,".",dec1 hum//10 pause 4000 goto main read_dht: for bits=4 to 0 step-1 dht[bits]=0 next tmr2=0 dht_dir=0 dht_data=0 pauseus 1000 'start it up dht_data=1 pauseus 30 dht_dir=1 pauseus 40 'wait till middle of response pulse window if ( dht_data)then goto badresponce 'no response then give up while (!dht_data) wend t2con=6 while ( dht_data) wend t2con=0 if ((tmr2 <45)||(tmr2>55))then goto badpresence ' confirm presence ? for bits =39 to 0 step -1 tmr2=0 while (!dht_data) wend 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 next crc=0 for bits=1 to 4 crc=crc+ dht[bits] next if crc != dht[0] then goto badcrc 'crc return badread: LCDOut $FE,$94 +8,"tmr2 ",#tmr2 next return badcrc: for bits=4 to 0 step-1 LCDOut $FE,$94 +16,hex dht[bits],"," pause 5000 next return badresponse: LCDOut $FE,$94 +8,"nr " return badpresence: LCDOut $FE,$94 +8,"pr",#tmr2 return
Sorry Richard, I must of confused you by posting the code with the values in the original code.
I'll take a look at your suggested code tomorrow and let you know - cheers for your help
EDIT - loaded the code as is and the LCD displays rh 0.0 nr
I assume that it's not getting a response from the sensor ? I have checked the connections and they appear correct (+ve to 5v, GND to ground, and signal to PORT A pin 1) this is connected via a header to the EasyPIC5 board with the 10K pull up resistors enabled (also tried without) I have a Hantek PC scope which I can use to test. I'm guessing I should see pin A1 going from high to low for the initial handshake between PIC and sensor ??
Last edited by Scampy; - 25th March 2015 at 01:39. Reason: update
expected dht response to start signal
OK seems to of been a hardware issue. Replaced the sensor and now get a value on the lcd. The program is giving a reading of 870.4 - how would I turn this into a percentage
Just to get a sense of the raw data collected, perhaps you can change your "main" subroutine to the follow and post the results output on the LCD?
Code:main: gosub read_dht 'LCDOut $FE,$94,"rh ",#hum/10,".",dec1 hum//10 lcdout $FE, $94, hex2 dht(0), " ", hex2 dht(1), " ",hex2 dht(2), " ", hex2 dht(3), " ", hex2 dht(4) pause 4000 goto main
Regards,
TABSoft
Bookmarks