DT averaging of interrupt driven cap sensor


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: DT averaging of interrupt driven cap sensor

    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
    ; ...
    DT

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DT averaging of interrupt driven cap sensor

    If you look at what I think will be you your proper baseline readings (i.e. once you've addressed a couple of those issues mentioned by Darrel)...

    Code:
    14409 
    14439 
    14437 
    14435
    14432
    14423 
    14433
    14440 
    14432 
    14432 
    14426
    14435 
    14434 
    14430 
    14429 
    14431
    they're only varying by about 0.00x% per sample period (interrupt)...and when your finger is pressed on the sensor, you should see the value drop by at least 20% (probably 50% or more if your sensor is decent enough), so there's really no need for averaging.

  3. #3
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: DT averaging of interrupt driven cap sensor

    thank you so much for the insight. that got rid of the erratic readings. I was able to set a threshold, and not update the average during a button press, and also count the amount of time that the button is pressed. I'm pleased.

    but I'm having trouble with the HSEROUT command - I feel so silly, I've never used it before. I saw that the tx pin is the same one as I was using before, so I was encouraged, but all I got in the PICKIT2 UART tool was '????????????????????' and jiberish

    I put these two defines up top, I tried 20h and 24h, 9600 baud and 19200
    DEFINE HSER_TXSTA 24h ' high speed (BRGH = 1)
    DEFINE HSER_BAUD 19200 ' 19200 BAUD rate

    and then I had these in my code
    Hserout ["Hello World", 13, 10]
    HSEROUT [DEC VALUE, ", ", DEC AVE, 13,10]

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DT averaging of interrupt driven cap sensor

    This is what gets me there on an 16f1828 @115,200 baud (16Mhz Osc)...

    Code:
    Osccon = %01111010   'sets the internal oscillator to 16Mhz
    DEFINE  OSC 16
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 34  ' 115200 Baud @ 16MHz, -0.79%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    RCSTA.7 = 1             ' Enable RB7 for TX USART (not sure if this is needed - needs removing one day to see!)
    TrisB.7 = 0                ' set pin 10 RB7 to be an output

    MrE's picmulticalc utility helps a lot wrt setting defines for your required serial speed...

    http://www.picbasic.co.uk/forum/show...5639#post65639

    your command usage looks fine - have you tried scoping the hserout pin?
    Last edited by HankMcSpank; - 15th September 2011 at 13:15.

  5. #5
    Join Date
    Jun 2008
    Location
    Milwaukee, WI
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: DT averaging of interrupt driven cap sensor

    yes! I got it working. Thanks for pointing me to the pic multi calc program, what a life saver. I used it for figuring out my interrupt timing, but I didn't see that it also did EUSART settings. It didn't start working until I set the appropriate bit in the APFCON register.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: DT averaging of interrupt driven cap sensor

    I am thinking of using the Cap sensor idea on a project to be battery powered in the middle of the sea.

    Considering that there are no 50/60Hz power lines, will this work?

    Ioannis

  7. #7
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: DT averaging of interrupt driven cap sensor

    Quote Originally Posted by Ioannis View Post
    Considering that there are no 50/60Hz power lines, will this work?
    I don't know what you mean wrt power lines bit (grounding?), but I see no reason why it wouldn't work - as far as I recall cap touch works with batteries too. (though now having a little bit of doubt in that all my exploits where on breadboard & mains sourced power!)

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts