Amoque
- 21st March 2015, 16:41
A lack of program space has forced me to upgrade from the 16F677A to the 18F4420. For the most part this has been fairly easy, but I have had an issue that makes me question the entirety of a very tenuous pyramid of knowledge… code that previously worked well with a DS18B20 1-Wire device now locks up –hanging, I believe at the “Waitloop”. The code is microEngineerings 1-Wire example code; other relevant bits also posted.
Anyone able/ willing to point out what I’ve missed?
This cut/ pasted from the relevant *.LST:
__CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
Here my registers:
'-----REGISTERS SET------------------------------------------------------------
CMCON = %00000111
TRISA = %00011111
TRISB = %00111111
TRISC = %00010000
TRISD = %00000000
TRISE = %00000000
ADCON0.0 = 1
ADCON1 = %00001011
ADCON2 = %10110101
Here Variables:
'-----THERMOMETER
DQ VAR PORTC.6
TEMP VAR WORD
OLD_TEMP VAR WORD
COUNT_REMAIN VAR BYTE
COUNT_PER_C VAR BYTE
MIN_TEMP VAR WORD
MAX_TEMP VAR WORD
And last, the actual 1-Wire routine:
'-----THERMOMETER READ
GET_TEMP:
OWOUT DQ, 1, [$CC, $44]
WAITLOOP:
OWIN DQ, 4, [COUNT_REMAIN]
IF COUNT_REMAIN = 0 THEN WAITLOOP
OWOUT DQ, 1, [$CC, $BE]
OWIN DQ,0, [TEMP.LOWBYTE, TEMP.HIGHBYTE, SKIP 4, COUNT_REMAIN, COUNT_PER_C]
TEMP = (((TEMP>>1) * 100) - 25) + (((COUNT_PER_C - COUNT_REMAIN) * 100) / COUNT_PER_C)
TEMP = (TEMP */ 461) + 3200
RETURN
I RTFM, and looked for some working code and tutorials, but ran into some discussion regarding issues with clock speeds over 4mHz... apparently at some point this issue was resolved by mE. I suspect there must be something in my CONFIG as the code seems pretty straightforward and works well on an '877A
I'd appreciate any thoughts...
Anyone able/ willing to point out what I’ve missed?
This cut/ pasted from the relevant *.LST:
__CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
Here my registers:
'-----REGISTERS SET------------------------------------------------------------
CMCON = %00000111
TRISA = %00011111
TRISB = %00111111
TRISC = %00010000
TRISD = %00000000
TRISE = %00000000
ADCON0.0 = 1
ADCON1 = %00001011
ADCON2 = %10110101
Here Variables:
'-----THERMOMETER
DQ VAR PORTC.6
TEMP VAR WORD
OLD_TEMP VAR WORD
COUNT_REMAIN VAR BYTE
COUNT_PER_C VAR BYTE
MIN_TEMP VAR WORD
MAX_TEMP VAR WORD
And last, the actual 1-Wire routine:
'-----THERMOMETER READ
GET_TEMP:
OWOUT DQ, 1, [$CC, $44]
WAITLOOP:
OWIN DQ, 4, [COUNT_REMAIN]
IF COUNT_REMAIN = 0 THEN WAITLOOP
OWOUT DQ, 1, [$CC, $BE]
OWIN DQ,0, [TEMP.LOWBYTE, TEMP.HIGHBYTE, SKIP 4, COUNT_REMAIN, COUNT_PER_C]
TEMP = (((TEMP>>1) * 100) - 25) + (((COUNT_PER_C - COUNT_REMAIN) * 100) / COUNT_PER_C)
TEMP = (TEMP */ 461) + 3200
RETURN
I RTFM, and looked for some working code and tutorials, but ran into some discussion regarding issues with clock speeds over 4mHz... apparently at some point this issue was resolved by mE. I suspect there must be something in my CONFIG as the code seems pretty straightforward and works well on an '877A
I'd appreciate any thoughts...