Well, I think the purpose of averaging with the CSM module is a little different than the Running average routine was written for. But maybe with a couple changes ...
But first, a few other changes are in order.
- Use the USART with HSEROUT for serial comms. It is unaffected by interrupts.
- If you do disable Timer0 to do something else, make sure the Timers get reset, because they will still be counting during that period which could give bad values.
- Stop Timer1 before trying to read the value so the lowbyte can't overflow in-between reading the 2-bytes.
- There is no need to disable Timer0 interrupts in the interrupt handler. Hardware interrupts on 16F1's cannot be interrupted since the GIE bit is cleared by hardware.
Now back to the CSM.
The purpose of averaging the readings is to maintain a baseline of the frequency when it's not being touched. The reading will vary over time due to humidity and temperature.
When you "press" a button, your finger adds capacitance which lowers the frequency. So you can use the FASpread to detect that change, but you don't want to keep averaging or it will change the "baseline" reading.
If you set the FASpread much lower than you have it, I'd guess around 2000 (but try different values). Then change the FastAvg section to ...
Code:
; ...
Pressed = 0
GoTo AVGok
FastAvg:
IF Value < AVE THEN
Pressed = 1
ELSE
AVE = Value
ENDIF
GoTo AVGok
RealClose:
Pressed = 0
; ...
Bookmarks