call Gainctrl; check if sample due, PIDcycleRef period, Tmp1 is unaffected.
;bsf Beeptime,6 ; task a 50+ms beep
[B][U]movf PIDcycle,f[/U][/B]
btfss STATUS,Z ; test results of Gainctrl, skip if zero,else
return ; if non zero.(sample period timer not done)
Code:
Gainctrl ;
movf PIDcycleRef,w ; set by PID process control
subwf PIDcycle,w; this count is updated by ISR.
btfss STATUS,C ; can compensate for code over 1 ms cycle
return
clrf PIDcycle; reset counter if count is met.
return ;
The first bit of code executes a test of the Z flag. Works on the simulator just fine.
In the real 16f886 hardware, it fails....unless i include the movf PIDcycle,f.
As far as I can tell the Z flag test is supposed to work as there is just the 'return' before the test, yet it fails. I used the beeptask to trace it as ICD can't be used...the pins are occupied.
29.3.1 STATUS Register as Destination
If an instruction writes to the STATUS register, the Z, C, DC and OV bits may be set or cleared
as a result of the instruction and overwrite the original data bits written. For example, executing
CLRF STATUS will clear register STATUS, and then set the Z bit leaving 0000 0100b in the register
Without the read from PIDcycle the zero flag is set on the result of PIDcycle-PIDcycleRef (not the other way around as you might expect). Without seeing a working example it's hard to see what's happening.
Well here's the intention of the code flow, perhaps I'm missing something obvious, hard to edit your own stuff sometimes.
This is the original code that works in ISIS.
Code:
call Gainctrl; check if sample due, PIDcycleRef period, Tmp1 is unaffected.
btfss STATUS,Z ; test results of Gainctrl, skip if zero,else
return ; if non zero.(sample period timer not done)
Code:
movf PIDcycleRef,w ; set by PID process control
subwf PIDcycle,w; this count is updated by ISR.
btfss STATUS,C ; can compensate for code over 1 ms cycle
return
clrf PIDcycle; reset counter if count is met.
return ;
The Gainctrl subroutine is called, then PIDcycle subtracts PIDcycleRef, if carry set then the PIDcycle >= PIDcycleRef, Then 'clrf PIDcycle' happens and a return, else just a return.
'clrf PIDcycle' ought to set the Z flag, upon return 'btfss STATUS,Z' tests this flag.
The problem is without the additional 'movf PIDcycle,f' inserted before the Z flag test the actual 16f886 chip doesn't detect the Z flag as set, based on the clrf PIDcycle.