MCU= PIC16F1829
Development: MPLab 8.92 /MPASM (Assembly)
Two slightly different versions of a program created a day apart behave differently. Call the earlier one "old" and the more recent one "new".
Configuration settings:
This code controls an AMS AS3935 lightning detector that has been mentioned here briefly before. First off, I see no difference between those two sections of code.
Function: On POR, register 0x08 is set to output a tuning frequency on the INT pin (its analog, not digital). User can add or subtract 8 pF capacitors to tune an antenna circuit. Writing 0x85 to register 0x08 is actually 2 commands. 0x80 causes the frequency to be outputted to the pin , adding 0x05 adds 5 capacitors to the circuit. Without the 5 capacitors, the frequency is about 509 kHz. With the capacitors, it is 500 kHz +/- 1kHz.
Problem: When the Old code is installed, it works well. The 5 capacitors are installed, and the frequency is approx. 500 kHz. It can be unplugged, plugged back in, held in reset, released from reset. Whatever I do, it keeps working.
When the New program is installed AFTER the Old program, it also works immediately after programming or after using the reset function of the programmer. Moreover, if I first erase the Old program, the New program still works. However, if power is interrupted to the New program, the reported frequency reverts back what is obtained with no capacitors. All attempts to make it start correctly "cold" fail; however, the subroutines to adjust those capacitors all work as before. If I read register 0x08 after exiting the frequency output part, it shows no capacitors. When working properly, that register shows 5 capacitors.
To repeat, that change with the New program appears to be irreversible without re-programming with the Old program first. That is the part that really troubles me . I have repeated those sequences several times with the same result.
Any ideas?
John
Development: MPLab 8.92 /MPASM (Assembly)
Two slightly different versions of a program created a day apart behave differently. Call the earlier one "old" and the more recent one "new".
Code:
;First section New:
;*******************************************************************************
call ClrRam ;takes care of flag0
POR
movlw 0x85 ;command to display LCO on IRQ/INT pin
movwf temp ;include adding 5 caps x 8 pF each
movlw 0x08 ;register number
call Put232
goto GetLCO ;check ant freq & calibrate antenna, returns |B0
Main
call ClrIF ;call from any bank, returns |B0
call ClrScrn ;returns |B0
StrPrint "Listening"
DelayCy (100*msecs)
movlw 0xBC
call Put232
btfsc flag0,4 ;check flag bit to clear after each event
bra PutNoStat
StrPrint "ClrStat(1)" ;10 char
;<much more code>
Code:
;Same section Old:
;*******************************************************************************
call ClrRam ;takes care of flag0
POR
movlw 0x85 ;command to display LCO on IRQ/INT pin
movwf temp ;include adding 5 caps x 8 pF each
movlw 0x08 ;register number
call PutReg ;returns in |B2
goto GetLCO ;check ant freq & calibrate antenna, returns |B0
Main
call ClrIF ;call from any bank, returns |B0
call ClrScrn ;returns |B0
StrPrint "Listening"
DelayCy (100*msecs)
movlw 0xBC
call Put232
btfsc flag0,4 ;check flag bit to clear after each event
bra PutNoStat
StrPrint "ClrStat(1)" ;10 char
Code:
__CONFIG _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
;__0x09E2
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_19 & _LVP_OFF
;__0x1DFF
Function: On POR, register 0x08 is set to output a tuning frequency on the INT pin (its analog, not digital). User can add or subtract 8 pF capacitors to tune an antenna circuit. Writing 0x85 to register 0x08 is actually 2 commands. 0x80 causes the frequency to be outputted to the pin , adding 0x05 adds 5 capacitors to the circuit. Without the 5 capacitors, the frequency is about 509 kHz. With the capacitors, it is 500 kHz +/- 1kHz.
Problem: When the Old code is installed, it works well. The 5 capacitors are installed, and the frequency is approx. 500 kHz. It can be unplugged, plugged back in, held in reset, released from reset. Whatever I do, it keeps working.
When the New program is installed AFTER the Old program, it also works immediately after programming or after using the reset function of the programmer. Moreover, if I first erase the Old program, the New program still works. However, if power is interrupted to the New program, the reported frequency reverts back what is obtained with no capacitors. All attempts to make it start correctly "cold" fail; however, the subroutines to adjust those capacitors all work as before. If I read register 0x08 after exiting the frequency output part, it shows no capacitors. When working properly, that register shows 5 capacitors.
To repeat, that change with the New program appears to be irreversible without re-programming with the Old program first. That is the part that really troubles me . I have repeated those sequences several times with the same result.
Any ideas?
John