I use a 'soft' interrupt by clearing the PIR1.0 register and preloading TMR1 to a value that gives me 24 mSecs. I start the timer routine and in my software I frequently check if PIR1.0 has been set by the TMR1 overflow. Being a code based 'check it when you can' the timing is a little flakey but it works fine in my application. I wanted to eliminate interrupt based code as far as possible since the overall timing can then get very hard to manage if interrupts get nested.
I do run SWDTEN with a 58 mSec hard reset to keep things in line if the soft check of PIR1.0 should not work as expected.
This is a snip from PIC16F88 code.
HTHCode:MainLoop: 'Housekeeping clearwdt WDTCON = %00001001 ' invoke s/w WDT, 58 mSec timeout, ' WDTCON = %00001010 ' has a recovery time about 110 mSec. OPTION_REG = %10001010 ' No wpu, prescaler assigned to WDT & /4 INTCON = %00000000 ' disable all interrupts ANSEL = %00000000 ' all digital CMCON = %00000111 ' Comparators OFF to allow inputs on pins ADCON0 = %00000000 ADCON1 = %00000000 PIE1 = %00000001 ' enable TMR1 overflow interrupt PIE2 = %00000000 PIR2 = %00000000 TRISB = %11001111 T1CON = %00100000 ' stop TMR1 PIR1.0 = 0 ' clear bit 0 TMR1 interrupt flag TMR1H = $8C TMR1L = $A0 ' loads 36000 - gives 24 mS on CRO T1CON = %00100001 ' start TMR1 FindSync: 'high txd ' The exits from this loop are via TimeOut or 850 loops of steady '1' ' Noise should keep the program stuck in this block until timeout ' but it still finds occasional sync pattterns in pure noise if pir1.0 = 1 then timeout if radioppm = 0 then findsync ' RadioPPM has gone high here - check that it stays high ' A byte variable gives a loop time about 2.7 uSecs. ' A word variable loops in about 9.2 uS so there are less chances ' to detect a low spike during the sync period. for a = 0 to 255 ' measured at 2300 uS if radioppm = 0 then findsync ' noise or channel pulse if pir1.0 = 1 then timeout ' been here too long next a for a = 0 to 255 if radioppm = 0 then findsync ' noise or channel pulse if pir1.0 = 1 then timeout ' been here too long next a for a = 0 to 255 if radioppm = 0 then findsync ' noise or channel pulse if pir1.0 = 1 then timeout ' been here too long next a for a = 0 to 200 '100 if radioppm = 0 then findsync ' noise or channel pulse if pir1.0 = 1 then timeout ' been here too long next a if badch > 2 then timeout goto sendpacket ' 250 contiguous 1's - sync or stuck high TimeOut: ' arrive here if TMR1 overflow is detected ' OR we were sent here by bad receive frame high txd 'low txd if pir1.0 = 0 then timeout ' wait until timer overflows 'Strategy ' The failsafe values are predetermined by the FailCh[n] array. ' When a failsafe state is detected, the system slowly migrates from ' LastCh[n] count to the FailCh[n] count over a number of frames ' using FailLimit as the maximum increment or decrement high p1led failch[0] = 0 ' throttle - cut to zero failch[1] = 125 ' aileron - centralise failch[2] = 125 ' elevator - centralise failch[3] = 165 ' rudder - a small left rudder failch[4] = 125 ' gear - normally 30 or 220. 125 = failsafe failch[5] = 125 ' Aux 1 failch[6] = 125 ' Aux 2 failch[7] = 125 ' Aux 3
BrianT





Bookmarks