I wish the 'edit' period was open for a little longer here (hint!), I've just noticed an error in that last part (cut/pastes are a hack from a much larger program)
One thing to point out, depending on how reactive you want the 'sensor touch' to be trapped, you may need quite a high interrupt rate, which can bring the PIC to it's knees using the interrupt method above - not a problem if your PIC isn't doing much else, but really hampers things if it's a busy little thing!Code:Timer0_Int: @ INT_DISABLE TMR0_INT ' stop timer0 interrupts while we're in here CPS0_PRESENTCOUNT = TMR0 ' take a snapshot of Timer0's present count. CPS0_THRESHOLD = CPS0_LASTCOUNT - ((CPS0_LASTCOUNT/100)*2) ' this sets the 'trigger' up for a 20% diversion (finger press) CPS0_LASTCOUNT = CPS0_PRESENTCOUNT ' store away the present timer0count for the next time we come into the interrupt routine if CPS0_PRESENTCOUNT < CPS0_THRESHOLD then 'if the present incoming timer0 count is 20% below the last count, then a finger is on the sensor,go do 'stuff' 'your stuff goes here' endif TMR0 = 0 ' clear timer0 down @ INT_ENABLE TMR0_INT ' re-enable interrupt @ INT_RETURN
Edit: Damn my speed typing, re this entry...
remove the above entry in my explanation post above - it relates to timer1! (which I was using too, but not needed in my example above, since I was using timer0)Code:T1CON = %11000001 'enable timer 1 (bit 0) & source the clock from the CPS module (bit 6 & 7 =11




Bookmarks